03 Mar 2008, 01:56

Mike Lutz (1 post)

code:getpath() returns a list of the current directories searched for modules. This list can be modified by code:add_patha() and code:add_pathz() and a bunch of their cousins. This looks like a violation of the one assignment rule - otherwise, how can code:get_path() return different values at different times?

The source code shows add_patha as:

add_patha(Dir) when is_list(Dir) -> call({add_path,first,Dir}).

and I can’t find any documentation on “call”, so my suspicion is that it’s some internal mumbo-jumbo in the interpreter, but I’d love to have this explained. A form of continuation??


22 Mar 2008, 22:52

Alain O'Dea (41 posts)

The path list can be modified because it is maintained by a separate process. The state around the receive statement in that process can be changed by recursion.

code:call/1 invokes code_server:call/1 which sends a message to the code server process. Upon receiving a path addition message the code_server process calls the function that receives code_server commands again recursively with a modified version of the list. Single assignment is preserved in this manner.

  You must be logged in to comment