Update documentation after 0.1.1 release
[clnl] / docs / DocsNvm.md
diff --git a/docs/DocsNvm.md b/docs/DocsNvm.md
new file mode 100644 (file)
index 0000000..9b78bb2
--- /dev/null
@@ -0,0 +1,667 @@
+# Package CLNL-NVM
+
+CLNL NVM
+
+NetLogo Virtual Machine: the simulation engine.
+
+## Contents
+
+* **function [agent-value](#function-agent-value)** - _agent-value_ is the general agent variable access function.  For many NetLogo reporters, the compilation results is _agent-value_.  The list of valid values are any builtin variable in the NetLogo dictionary, as well as any *-own variable.
+* **function [ask](#function-ask)** - _ask_ is equivalent to ask in NetLogo.
+* **function [clear-all](#function-clear-all)** - Clears ticks, turtles, patches, globals (unimplemented).
+* **function [count](#function-count)** - _count_ is equivalent to count in _n_etLogo.  Returns _n_, the number of agents in _agentset_.
+* **function [create-turtles](#function-create-turtles)** - Creates _n_ new turtles at the origin.
+* **function [create-world](#function-create-world)** - Initializes the world in the NVM.
+* **function [current-state](#function-current-state)** - Dumps out the state of the world.
+* **function [die](#function-die)** - The turtle or link dies
+* **function [display](#function-display)** - As of yet, this does nothing.  A placeholder method for forced dipslay updates from the engine.
+* **function [export-world](#function-export-world)** - Dumps out a csv matching NetLogo's export world.
+* **function [forward](#function-forward)** - Moves the current turtle forward _n_ steps, one step at a time.
+* **function [hatch](#function-hatch)** - The turtle in *self* creates _n_ new turtles. Each new turtle inherits of all its variables, including its location, from self.
+* **function [lookup-color](#function-lookup-color)** - Returns the number used to represent colors in NetLogo.
+* **function [of](#function-of)** - _of_ is equivalent to of in NetLogo.
+* **function [one-of](#function-one-of)** - From an _agentset_, returns a _random-agent_. If the agentset is empty, returns :nobody. From a list, returns a _random-value_.  If the list is empty, an error occurs.
+* **function [patches](#function-patches)** - Reports the agentset consisting of all the patches.
+* **function [random](#function-random)** - Returns a random number strictly closer to zero than _n_.
+* **function [random-float](#function-random-float)** - Returns a random number strictly closer to zero than _n_.
+* **function [random-xcor](#function-random-xcor)** - Returns a random floating point number in the allowable range of turtle coordinates along the x axis.
+* **function [random-ycor](#function-random-ycor)** - Returns a random floating point number in the allowable range of turtle coordinates along the y axis.
+* **function [reset-ticks](#function-reset-ticks)** - Resets the tick counter to zero, sets up all plots, then updates all plots.
+* **function [set-default-shape](#function-set-default-shape)** - Specifies a default initial shape for a _breed_. When a turtle, or it changes breeds, its shape is set to the given shape.
+* **function [setxy](#function-setxy)** - Sets the x-coordinate and y-coordinate for the turle.  Equivalent to set xcor x set ycor y, except it happens in one step inside of two.
+* **function [show](#function-show)** - A command that prints the given NetLogo value to the command center.
+* **function [stop](#function-stop)** - Returns from the current stop block, which will halt the currently running thing, be that the program, current ask block, or procedure.  Stop has odd semantics that are best gleaned from the actual NetLogo manual.
+* **function [tick](#function-tick)** - Advances the tick counter by one and updates all plots.
+* **function [ticks](#function-ticks)** - Reports the current value of the tick counter. The result is always a number and never negative.
+* **function [turn-left](#function-turn-left)** - The turtle turns left by number degrees. (If number is negative, it turns right.)
+* **function [turn-right](#function-turn-right)** - The turtle turns right by number degrees. (If number is negative, it turns left.)
+* **function [turtles](#function-turtles)** - Reports the agentset consisting of all the turtles.
+* **function [turtles-here](#function-turtles-here)** - Returns the agentset consisting of all the turtles sharing the patch with the agent in by *self*
+* **function [with](#function-with)** - _with_ is equivalent to with in NetLogo.
+* **function [with-stop-handler](#function-with-stop-handler)** - _with-stop-handler_ is a convenience macro to handle when programs issue a stop condition.  When one does, a simple :stop is returned.
+
+## Function **AGENT-VALUE**
+
+#### Syntax:
+
+**agent-value** _var_ _&optional_ _agent_ => _result_
+
+#### Arguments and Values:
+
+_var_---A variable name  
+_agent_---an agent, defaulting to *self*  
+_result_---the value of _var_  
+
+#### Description:
+
+_agent-value_ is the general agent variable access function.  For many NetLogo reporters, the compilation results is _agent-value_.  The list of valid values are any builtin variable in the NetLogo dictionary, as well as any *-own variable.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html for builtins
+
+## Function **ASK**
+
+#### Syntax:
+
+**ask** _agent-or-agentset_ _fn_ => _result_
+
+```agent-or-agentset::= agent | agentset```  
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_fn_---a function, run on each agent  
+_agent_---a NetLogo agent  
+_agentset_---a NetLogo agentset  
+
+#### Description:
+
+_ask_ is equivalent to ask in NetLogo.
+
+The specified _agent_SET or _agent_ runs the given _fn_.  In the case of an _agent_SET, the order in which the agents are run is random each time, and only agents that are in the set at the beginning of the call.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ask
+
+## Function **CLEAR-ALL**
+
+#### Syntax:
+
+**clear-all** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+Clears ticks, turtles, patches, globals (unimplemented).
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-all
+
+## Function **COUNT**
+
+#### Syntax:
+
+**count** _agentset_ => _n_
+
+#### Arguments and Values:
+
+_agentset_---a _n_etLogo agentset  
+_n_---a number  
+
+#### Description:
+
+_count_ is equivalent to count in _n_etLogo.  Returns _n_, the number of agents in _agentset_.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count
+
+## Function **CREATE-TURTLES**
+
+#### Syntax:
+
+**create-turtles** _n_ _&optional_ _breed_ _fn_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_n_---an integer, the numbers of turtles to create  
+_breed_---a breed  
+_fn_---A function, applied to each turtle after creation  
+
+#### Description:
+
+Creates _n_ new turtles at the origin.
+
+_n_ew turtles have random integer headings and the color is randomly selected from the 14 primary colors.  If F_n_ is supplied, the new turtles immediately run it.  If a _breed_ is supplied, that is the breed the new turtles are set to.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles
+
+## Function **CREATE-WORLD**
+
+#### Syntax:
+
+**create-world** _&key_ _dims_ _globals_ _turtles-own-vars_ _patches-own-vars_ _breeds_ => _result_
+
+```dims::= (:xmin xmin :xmax xmax :ymin ymin :ymax ymax)```  
+```globals::= global*```  
+```turtles-own-vars::= turtles-own-var*```  
+```patches-own-vars::= patches-own-var*```  
+```breeds::= breed*```  
+```result::= :undefined```  
+```global::= (global-name global-access-func)```  
+
+#### Arguments and Values:
+
+_xmin_---An integer representing the minimum patch coord in X  
+_xmax_---An integer representing the maximum patch coord in X  
+_ymin_---An integer representing the minimum patch coord in Y  
+_ymax_---An integer representing the maximum patch coord in Y  
+_turtles-own-var_---Symbol for the turtles own variable in the keyword package  
+_patches-own-var_---Symbol for the patches own variable in the keyword package  
+_breed_---A list of symbols representing the possible preeds  
+_global-name_---Symbol for the global in the keyword package  
+_global-access-func_---Function to get the value of the global  
+
+#### Description:
+
+Initializes the world in the NVM.
+
+This should be called before using the engine in any real capacity.  If called when an engine is already running, it may do somethign weird.
+
+## Function **CURRENT-STATE**
+
+#### Syntax:
+
+**current-state** => _world-state_
+
+#### Arguments and Values:
+
+_world-state_---A list, the current state of the whole world  
+
+#### Description:
+
+Dumps out the state of the world.
+
+This is useful for visualizations and also storing in a common lisp data structure for easy usage in a common lisp instance.  It's preferable to use this when working with the nvm than the output done by export-world.
+
+Currently this only dumps out turtle and patch information.
+
+This is called _current-state_ because export-world is an actual primitive used by NetLogo.
+
+## Function **DIE**
+
+#### Syntax:
+
+**die** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+The turtle or link dies
+
+A dead agent ceases to exist. The effects of this include: - The agent will not execute any further code. - The agent will disappear from any agentsets it was in, reducing the size of those agentsets by one. - Any variable that was storing the agent will now instead have nobody in it. - If the dead agent was a turtle, every link connected to it also dies. - If the observer was watching or following the agent, the observer's perspective resets.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#die
+
+## Function **DISPLAY**
+
+#### Syntax:
+
+**display** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+As of yet, this does nothing.  A placeholder method for forced dipslay updates from the engine.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#display
+
+## Function **EXPORT-WORLD**
+
+#### Syntax:
+
+**export-world** => _world-csv_
+
+#### Arguments and Values:
+
+_world-csv_---A string, the csv of the world  
+
+#### Description:
+
+Dumps out a csv matching NetLogo's export world.
+
+This is useful for serializing the current state of the engine in order to compare against NetLogo or to reimport later.  Contains everything needed to boot up a NetLogo instance in the exact same state.
+
+## Function **FORWARD**
+
+#### Syntax:
+
+**forward** _n_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_n_---a double, the amount the turtle moves forward  
+
+#### Description:
+
+Moves the current turtle forward _n_ steps, one step at a time.
+
+This moves forward one at a time in order to make the view updates look good in the case of a purposefully slow running instance.  If the number is negative, the turtle moves backward.
+
+If the current agent is not a turtle, it raises an error.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#forward
+
+## Function **HATCH**
+
+#### Syntax:
+
+**hatch** _n_ _&optional_ _fn_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_n_---an integer, the numbers of turtles to hatch  
+_fn_---A function, applied to each turtle after creation  
+
+#### Description:
+
+The turtle in *self* creates _n_ new turtles. Each new turtle inherits of all its variables, including its location, from self.
+
+If F_n_ is supplied, the new turtles immediately run it.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#hatch
+
+## Function **LOOKUP-COLOR**
+
+#### Syntax:
+
+**lookup-color** _color_ => _color-number_
+
+#### Arguments and Values:
+
+_color_---a symbol representing a color  
+_color-number_---the NetLogo color integer  
+
+#### Description:
+
+Returns the number used to represent colors in NetLogo.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#Constants
+
+## Function **OF**
+
+#### Syntax:
+
+**of** _fn_ _agent-or-agentset_ => _result_
+
+```agent-or-agentset::= agent | agentset```  
+```result::= result-list | result-value```  
+
+#### Arguments and Values:
+
+_fn_---a function, run on each agent  
+_agent_---a NetLogo agent  
+_agentset_---a NetLogo agentset  
+_result-list_---a list  
+_result-value_---a single value  
+
+#### Description:
+
+_of_ is equivalent to of in NetLogo.
+
+The specified _agent_SET or _agent_ runs the given _fn_.  In the case of an _agent_SET, the order in which the agents are run is random each time, and only agents that are in the set at the beginning of the call.
+
+_result_-LIST is returned when the input is an _agent_SET, but _result_-VALUE is returned when only passed an _agent_.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of
+
+## Function **ONE-OF**
+
+#### Syntax:
+
+**one-of** _list-or-agentset_ => _result_
+
+```list-or-agentset::= list | agentset```  
+```result::= random-value | random-agent | :nobody```  
+
+#### Arguments and Values:
+
+_list_---A list  
+_agentset_---An agent set  
+_random-value_---a value in _list_  
+_random-agent_---an agent if _agentset_ is non empty  
+
+#### Description:
+
+From an _agentset_, returns a _random-agent_. If the agentset is empty, returns :nobody. From a list, returns a _random-value_.  If the list is empty, an error occurs.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#one-of
+
+## Function **PATCHES**
+
+#### Syntax:
+
+**patches** => _all-patches_
+
+#### Arguments and Values:
+
+_all-patches_---a NetLogo agentset, all patches  
+
+#### Description:
+
+Reports the agentset consisting of all the patches.
+
+This agentset is special in that it represents the living patches each time it's used, so changes depending on the state of the engine.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches
+
+## Function **RANDOM**
+
+#### Syntax:
+
+**random** _n_ => _random-number_
+
+#### Arguments and Values:
+
+_n_---an integer, the upper bound of the random  
+_random-number_---an integer, the random result  
+
+#### Description:
+
+Returns a random number strictly closer to zero than _n_.
+
+If number is positive, returns a random integer greater than or equal to 0, but strictly less than number.
+
+If number is negative, returns a random integer less than or equal to 0, but strictly greater than number.
+
+If number is zero, the result is always 0.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random
+
+## Function **RANDOM-FLOAT**
+
+#### Syntax:
+
+**random-float** _n_ => _random-number_
+
+#### Arguments and Values:
+
+_n_---a double, the upper bound of the random float  
+_random-number_---a double, the random result  
+
+#### Description:
+
+Returns a random number strictly closer to zero than _n_.
+
+If number is positive, returns a random floating point number greater than or equal to 0 but strictly less than number.
+
+If number is negative, returns a random floating point number less than or equal to 0, but strictly greater than number.
+
+If number is zero, the result is always 0.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-float
+
+## Function **RANDOM-XCOR**
+
+#### Syntax:
+
+**random-xcor** => _random-number_
+
+#### Arguments and Values:
+
+_random-number_---a float, the random result  
+
+#### Description:
+
+Returns a random floating point number in the allowable range of turtle coordinates along the x axis.
+
+These range from min-pxcor - 0.5 (inclusive) to max-pxcor + 0.5 (exclusive)
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-cor
+
+## Function **RANDOM-YCOR**
+
+#### Syntax:
+
+**random-ycor** => _random-number_
+
+#### Arguments and Values:
+
+_random-number_---a float, the random result  
+
+#### Description:
+
+Returns a random floating point number in the allowable range of turtle coordinates along the y axis.
+
+These range from min-pycor - 0.5 (inclusive) to max-pycor + 0.5 (exclusive)
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-cor
+
+## Function **RESET-TICKS**
+
+#### Syntax:
+
+**reset-ticks** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+Resets the tick counter to zero, sets up all plots, then updates all plots.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#reset-ticks
+
+## Function **SET-DEFAULT-SHAPE**
+
+#### Syntax:
+
+**set-default-shape** _breed_ _shape_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_breed_---a valid breed  
+_shape_---a string  
+
+#### Description:
+
+Specifies a default initial shape for a _breed_. When a turtle, or it changes breeds, its shape is set to the given shape.
+
+_set-default-shape_ doesn't affect existing agents, only agents you create afterwards.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#set-default-shape
+
+## Function **SETXY**
+
+#### Syntax:
+
+**setxy** _x_ _y_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_x_---a double  
+_y_---a double  
+
+#### Description:
+
+Sets the x-coordinate and y-coordinate for the turle.  Equivalent to set xcor x set ycor y, except it happens in one step inside of two.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#setxy
+
+## Function **SHOW**
+
+#### Syntax:
+
+**show** _value_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_value_---a NetLogo value  
+
+#### Description:
+
+A command that prints the given NetLogo value to the command center.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#show
+
+## Function **STOP**
+
+#### Syntax:
+
+**stop** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+Returns from the current stop block, which will halt the currently running thing, be that the program, current ask block, or procedure.  Stop has odd semantics that are best gleaned from the actual NetLogo manual.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#stop
+
+## Function **TICK**
+
+#### Syntax:
+
+**tick** => _result_
+
+```result::= :undefined```  
+
+#### Description:
+
+Advances the tick counter by one and updates all plots.
+
+If the tick counter has not been started yet with reset-ticks, an error results.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#tick
+
+## Function **TICKS**
+
+#### Syntax:
+
+**ticks** => _current-ticks_
+
+#### Arguments and Values:
+
+_current-ticks_---A positiv double, representing the current number of ticks  
+
+#### Description:
+
+Reports the current value of the tick counter. The result is always a number and never negative.
+
+If the tick counter has not been started yet with reset-ticks, an error results.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ticks
+
+## Function **TURN-LEFT**
+
+#### Syntax:
+
+**turn-left** _n_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_n_---a double, the amount the turtle turns  
+
+#### Description:
+
+The turtle turns left by number degrees. (If number is negative, it turns right.)
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#right
+
+## Function **TURN-RIGHT**
+
+#### Syntax:
+
+**turn-right** _n_ => _result_
+
+```result::= :undefined```  
+
+#### Arguments and Values:
+
+_n_---a double, the amount the turtle turns  
+
+#### Description:
+
+The turtle turns right by number degrees. (If number is negative, it turns left.)
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#right
+
+## Function **TURTLES**
+
+#### Syntax:
+
+**turtles** => _all-turtles_
+
+#### Arguments and Values:
+
+_all-turtles_---a NetLogo agentset, all turtles  
+
+#### Description:
+
+Reports the agentset consisting of all the turtles.
+
+This agentset is special in that it represents the living turtles each time it's used, so changes depending on the state of the engine.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles
+
+## Function **TURTLES-HERE**
+
+#### Syntax:
+
+**turtles-here** => _turtles_
+
+#### Arguments and Values:
+
+_turtles_---an agentset  
+
+#### Description:
+
+Returns the agentset consisting of all the turtles sharing the patch with the agent in by *self*
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles-here
+
+## Function **WITH**
+
+#### Syntax:
+
+**with** _agentset_ _fn_ => _result-agentset_
+
+#### Arguments and Values:
+
+_agentset_---a NetLogo agentset  
+_fn_---a boolean function, run on each agent to determine if included  
+_result-agentset_---an agentset of valid agents  
+
+#### Description:
+
+_with_ is equivalent to with in NetLogo.
+
+Returns a new agentset containing only those agents that reported true when _fn_ is called.
+
+See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#with
+
+## Function **WITH-STOP-HANDLER**
+
+#### Syntax:
+
+**with-stop-handler** _&rest_ _forms_ => _handled-form_
+
+#### Arguments and Values:
+
+_forms_---body to be handled  
+_handled-form_---body with handling  
+
+#### Description:
+
+_with-stop-handler_ is a convenience macro to handle when programs issue a stop condition.  When one does, a simple :stop is returned.