5 NetLogo Virtual Machine: the simulation engine.
9 * **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.
10 * **function [ask](#function-ask)** - _ask_ is equivalent to ask in NetLogo.
11 * **function [clear-all](#function-clear-all)** - Clears ticks, turtles, patches, globals (unimplemented).
12 * **function [count](#function-count)** - _count_ is equivalent to count in _n_etLogo. Returns _n_, the number of agents in _agentset_.
13 * **function [create-turtles](#function-create-turtles)** - Creates _n_ new turtles at the origin.
14 * **function [create-world](#function-create-world)** - Initializes the world in the NVM.
15 * **function [current-state](#function-current-state)** - Dumps out the state of the world.
16 * **function [die](#function-die)** - The turtle or link dies
17 * **function [display](#function-display)** - As of yet, this does nothing. A placeholder method for forced dipslay updates from the engine.
18 * **function [export-world](#function-export-world)** - Dumps out a csv matching NetLogo's export world.
19 * **function [forward](#function-forward)** - Moves the current turtle forward _n_ steps, one step at a time.
20 * **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.
21 * **function [lookup-color](#function-lookup-color)** - Returns the number used to represent colors in NetLogo.
22 * **function [of](#function-of)** - _of_ is equivalent to of in NetLogo.
23 * **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.
24 * **function [patches](#function-patches)** - Reports the agentset consisting of all the patches.
25 * **function [random](#function-random)** - Returns a random number strictly closer to zero than _n_.
26 * **function [random-float](#function-random-float)** - Returns a random number strictly closer to zero than _n_.
27 * **function [random-xcor](#function-random-xcor)** - Returns a random floating point number in the allowable range of turtle coordinates along the x axis.
28 * **function [random-ycor](#function-random-ycor)** - Returns a random floating point number in the allowable range of turtle coordinates along the y axis.
29 * **function [reset-ticks](#function-reset-ticks)** - Resets the tick counter to zero, sets up all plots, then updates all plots.
30 * **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.
31 * **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.
32 * **function [show](#function-show)** - A command that prints the given NetLogo value to the command center.
33 * **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.
34 * **function [tick](#function-tick)** - Advances the tick counter by one and updates all plots.
35 * **function [ticks](#function-ticks)** - Reports the current value of the tick counter. The result is always a number and never negative.
36 * **function [turn-left](#function-turn-left)** - The turtle turns left by number degrees. (If number is negative, it turns right.)
37 * **function [turn-right](#function-turn-right)** - The turtle turns right by number degrees. (If number is negative, it turns left.)
38 * **function [turtles](#function-turtles)** - Reports the agentset consisting of all the turtles.
39 * **function [turtles-here](#function-turtles-here)** - Returns the agentset consisting of all the turtles sharing the patch with the agent in by *self*
40 * **function [with](#function-with)** - _with_ is equivalent to with in NetLogo.
41 * **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.
43 ## Function **AGENT-VALUE**
47 **agent-value** _var_ _&optional_ _agent_ => _result_
49 #### Arguments and Values:
51 _var_---A variable name
52 _agent_---an agent, defaulting to *self*
53 _result_---the value of _var_
57 _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.
59 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html for builtins
65 **ask** _agent-or-agentset_ _fn_ => _result_
67 ```agent-or-agentset::= agent | agentset```
68 ```result::= :undefined```
70 #### Arguments and Values:
72 _fn_---a function, run on each agent
73 _agent_---a NetLogo agent
74 _agentset_---a NetLogo agentset
78 _ask_ is equivalent to ask in NetLogo.
80 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.
82 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ask
84 ## Function **CLEAR-ALL**
88 **clear-all** => _result_
90 ```result::= :undefined```
94 Clears ticks, turtles, patches, globals (unimplemented).
96 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-all
102 **count** _agentset_ => _n_
104 #### Arguments and Values:
106 _agentset_---a _n_etLogo agentset
111 _count_ is equivalent to count in _n_etLogo. Returns _n_, the number of agents in _agentset_.
113 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count
115 ## Function **CREATE-TURTLES**
119 **create-turtles** _n_ _&optional_ _breed_ _fn_ => _result_
121 ```result::= :undefined```
123 #### Arguments and Values:
125 _n_---an integer, the numbers of turtles to create
127 _fn_---A function, applied to each turtle after creation
131 Creates _n_ new turtles at the origin.
133 _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.
135 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#create-turtles
137 ## Function **CREATE-WORLD**
141 **create-world** _&key_ _dims_ _globals_ _turtles-own-vars_ _patches-own-vars_ _breeds_ => _result_
143 ```dims::= (:xmin xmin :xmax xmax :ymin ymin :ymax ymax)```
144 ```globals::= global*```
145 ```turtles-own-vars::= turtles-own-var*```
146 ```patches-own-vars::= patches-own-var*```
147 ```breeds::= breed*```
148 ```result::= :undefined```
149 ```global::= (global-name global-access-func)```
151 #### Arguments and Values:
153 _xmin_---An integer representing the minimum patch coord in X
154 _xmax_---An integer representing the maximum patch coord in X
155 _ymin_---An integer representing the minimum patch coord in Y
156 _ymax_---An integer representing the maximum patch coord in Y
157 _turtles-own-var_---Symbol for the turtles own variable in the keyword package
158 _patches-own-var_---Symbol for the patches own variable in the keyword package
159 _breed_---A list of symbols representing the possible preeds
160 _global-name_---Symbol for the global in the keyword package
161 _global-access-func_---Function to get the value of the global
165 Initializes the world in the NVM.
167 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.
169 ## Function **CURRENT-STATE**
173 **current-state** => _world-state_
175 #### Arguments and Values:
177 _world-state_---A list, the current state of the whole world
181 Dumps out the state of the world.
183 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.
185 Currently this only dumps out turtle and patch information.
187 This is called _current-state_ because export-world is an actual primitive used by NetLogo.
195 ```result::= :undefined```
199 The turtle or link dies
201 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.
203 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#die
205 ## Function **DISPLAY**
209 **display** => _result_
211 ```result::= :undefined```
215 As of yet, this does nothing. A placeholder method for forced dipslay updates from the engine.
217 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#display
219 ## Function **EXPORT-WORLD**
223 **export-world** => _world-csv_
225 #### Arguments and Values:
227 _world-csv_---A string, the csv of the world
231 Dumps out a csv matching NetLogo's export world.
233 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.
235 ## Function **FORWARD**
239 **forward** _n_ => _result_
241 ```result::= :undefined```
243 #### Arguments and Values:
245 _n_---a double, the amount the turtle moves forward
249 Moves the current turtle forward _n_ steps, one step at a time.
251 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.
253 If the current agent is not a turtle, it raises an error.
255 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#forward
257 ## Function **HATCH**
261 **hatch** _n_ _&optional_ _fn_ => _result_
263 ```result::= :undefined```
265 #### Arguments and Values:
267 _n_---an integer, the numbers of turtles to hatch
268 _fn_---A function, applied to each turtle after creation
272 The turtle in *self* creates _n_ new turtles. Each new turtle inherits of all its variables, including its location, from self.
274 If F_n_ is supplied, the new turtles immediately run it.
276 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#hatch
278 ## Function **LOOKUP-COLOR**
282 **lookup-color** _color_ => _color-number_
284 #### Arguments and Values:
286 _color_---a symbol representing a color
287 _color-number_---the NetLogo color integer
291 Returns the number used to represent colors in NetLogo.
293 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#Constants
299 **of** _fn_ _agent-or-agentset_ => _result_
301 ```agent-or-agentset::= agent | agentset```
302 ```result::= result-list | result-value```
304 #### Arguments and Values:
306 _fn_---a function, run on each agent
307 _agent_---a NetLogo agent
308 _agentset_---a NetLogo agentset
309 _result-list_---a list
310 _result-value_---a single value
314 _of_ is equivalent to of in NetLogo.
316 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.
318 _result_-LIST is returned when the input is an _agent_SET, but _result_-VALUE is returned when only passed an _agent_.
320 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#of
322 ## Function **ONE-OF**
326 **one-of** _list-or-agentset_ => _result_
328 ```list-or-agentset::= list | agentset```
329 ```result::= random-value | random-agent | :nobody```
331 #### Arguments and Values:
334 _agentset_---An agent set
335 _random-value_---a value in _list_
336 _random-agent_---an agent if _agentset_ is non empty
340 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.
342 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#one-of
344 ## Function **PATCHES**
348 **patches** => _all-patches_
350 #### Arguments and Values:
352 _all-patches_---a NetLogo agentset, all patches
356 Reports the agentset consisting of all the patches.
358 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.
360 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches
362 ## Function **RANDOM**
366 **random** _n_ => _random-number_
368 #### Arguments and Values:
370 _n_---an integer, the upper bound of the random
371 _random-number_---an integer, the random result
375 Returns a random number strictly closer to zero than _n_.
377 If number is positive, returns a random integer greater than or equal to 0, but strictly less than number.
379 If number is negative, returns a random integer less than or equal to 0, but strictly greater than number.
381 If number is zero, the result is always 0.
383 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random
385 ## Function **RANDOM-FLOAT**
389 **random-float** _n_ => _random-number_
391 #### Arguments and Values:
393 _n_---a double, the upper bound of the random float
394 _random-number_---a double, the random result
398 Returns a random number strictly closer to zero than _n_.
400 If number is positive, returns a random floating point number greater than or equal to 0 but strictly less than number.
402 If number is negative, returns a random floating point number less than or equal to 0, but strictly greater than number.
404 If number is zero, the result is always 0.
406 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-float
408 ## Function **RANDOM-XCOR**
412 **random-xcor** => _random-number_
414 #### Arguments and Values:
416 _random-number_---a float, the random result
420 Returns a random floating point number in the allowable range of turtle coordinates along the x axis.
422 These range from min-pxcor - 0.5 (inclusive) to max-pxcor + 0.5 (exclusive)
424 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-cor
426 ## Function **RANDOM-YCOR**
430 **random-ycor** => _random-number_
432 #### Arguments and Values:
434 _random-number_---a float, the random result
438 Returns a random floating point number in the allowable range of turtle coordinates along the y axis.
440 These range from min-pycor - 0.5 (inclusive) to max-pycor + 0.5 (exclusive)
442 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#random-cor
444 ## Function **RESET-TICKS**
448 **reset-ticks** => _result_
450 ```result::= :undefined```
454 Resets the tick counter to zero, sets up all plots, then updates all plots.
456 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#reset-ticks
458 ## Function **SET-DEFAULT-SHAPE**
462 **set-default-shape** _breed_ _shape_ => _result_
464 ```result::= :undefined```
466 #### Arguments and Values:
468 _breed_---a valid breed
473 Specifies a default initial shape for a _breed_. When a turtle, or it changes breeds, its shape is set to the given shape.
475 _set-default-shape_ doesn't affect existing agents, only agents you create afterwards.
477 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#set-default-shape
479 ## Function **SETXY**
483 **setxy** _x_ _y_ => _result_
485 ```result::= :undefined```
487 #### Arguments and Values:
494 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.
496 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#setxy
502 **show** _value_ => _result_
504 ```result::= :undefined```
506 #### Arguments and Values:
508 _value_---a NetLogo value
512 A command that prints the given NetLogo value to the command center.
514 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#show
522 ```result::= :undefined```
526 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.
528 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#stop
536 ```result::= :undefined```
540 Advances the tick counter by one and updates all plots.
542 If the tick counter has not been started yet with reset-ticks, an error results.
544 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#tick
546 ## Function **TICKS**
550 **ticks** => _current-ticks_
552 #### Arguments and Values:
554 _current-ticks_---A positiv double, representing the current number of ticks
558 Reports the current value of the tick counter. The result is always a number and never negative.
560 If the tick counter has not been started yet with reset-ticks, an error results.
562 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#ticks
564 ## Function **TURN-LEFT**
568 **turn-left** _n_ => _result_
570 ```result::= :undefined```
572 #### Arguments and Values:
574 _n_---a double, the amount the turtle turns
578 The turtle turns left by number degrees. (If number is negative, it turns right.)
580 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#right
582 ## Function **TURN-RIGHT**
586 **turn-right** _n_ => _result_
588 ```result::= :undefined```
590 #### Arguments and Values:
592 _n_---a double, the amount the turtle turns
596 The turtle turns right by number degrees. (If number is negative, it turns left.)
598 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#right
600 ## Function **TURTLES**
604 **turtles** => _all-turtles_
606 #### Arguments and Values:
608 _all-turtles_---a NetLogo agentset, all turtles
612 Reports the agentset consisting of all the turtles.
614 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.
616 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles
618 ## Function **TURTLES-HERE**
622 **turtles-here** => _turtles_
624 #### Arguments and Values:
626 _turtles_---an agentset
630 Returns the agentset consisting of all the turtles sharing the patch with the agent in by *self*
632 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles-here
638 **with** _agentset_ _fn_ => _result-agentset_
640 #### Arguments and Values:
642 _agentset_---a NetLogo agentset
643 _fn_---a boolean function, run on each agent to determine if included
644 _result-agentset_---an agentset of valid agents
648 _with_ is equivalent to with in NetLogo.
650 Returns a new agentset containing only those agents that reported true when _fn_ is called.
652 See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#with
654 ## Function **WITH-STOP-HANDLER**
658 **with-stop-handler** _&rest_ _forms_ => _handled-form_
660 #### Arguments and Values:
662 _forms_---body to be handled
663 _handled-form_---body with handling
667 _with-stop-handler_ is a convenience macro to handle when programs issue a stop condition. When one does, a simple :stop is returned.