Make agentsets annotated lists, Implement count
[clnl] / src / main / nvm / nvm.lisp
index f8fdd84bde3a72ecdc4c8e87f6db905e5c42ca44..da42870c86d3cbc4129a4220a039c316bd60f75b 100644 (file)
@@ -100,7 +100,7 @@ DESCRIPTION:
   each time it's used, so changes depending on the state of the engine.
 
   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patches"
*patches*)
:patches)
 
 (defun turtles ()
  "TURTLES => ALL-TURTLES
@@ -117,7 +117,7 @@ DESCRIPTION:
   each time it's used, so changes depending on the state of the engine.
 
   See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#turtles"
*turtles*)
:turtles)
 
 (defun ask (agent-set fn)
  "ASK AGENT-SET FN => RESULT
@@ -144,6 +144,22 @@ DESCRIPTION:
    :while agent
    :do (let ((*myself* *self*) (*self* agent)) (funcall fn)))))
 
+(defun count (agent-set)
+ "COUNT AGENT-SET => N
+
+ARGUMENTS AND VALUES:
+
+  AGENT-SET: a NetLogo agentset
+  N: a number
+
+DESCRIPTION:
+
+  COUNT is equivalent to count in NetLogo.  Returns N, the number of
+  agents in AGENT-SET.
+
+  See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count"
+ (coerce (length (agent-set-list agent-set)) 'double-float))
+
 (defun of (fn agent-set)
  "OF FN AGENT-SET => RESULT