See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#count"
(coerce (length (agentset-list agentset)) 'double-float))
+(defun clear-all ()
+ "CLEAR-ALL => RESULT
+
+ARGUMENTS AND VALUES:
+
+ RESULT: undefined
+
+DESCRIPTION:
+
+ Clears ticks, turtles, patches, globals (unimplemented).
+
+ See http://ccl.northwestern.edu/netlogo/docs/dictionary.html#clear-all"
+ (clear-turtles)
+ (clear-patches)
+ (clear-ticks))
+
(defun of (fn agent-or-agentset)
"OF FN AGENT-OR-AGENTSET => RESULT
(when (not *ticks*) (error "reset-ticks must be called"))
*ticks*)
+(defun clear-patches ()
+ (setf
+ *patches*
+ (loop
+ :for y :from (max-pycor) :downto (min-pycor)
+ :append (loop
+ :for x :from (min-pxcor) :to (max-pxcor)
+ :collect (make-patch
+ :xcor (coerce x 'double-float)
+ :ycor (coerce y 'double-float)
+ :color 0d0)))))
+
+(defun clear-turtles ()
+ (setf *turtles* nil)
+ (setf *current-id* 0))
+
+(defun clear-ticks ()
+ (setf *ticks* nil))
+
(defun create-world (&key dims)
"CREATE-WORLD &key DIMS => RESULT
called when an engine is already running, it may do somethign weird."
(setf *dimensions* dims)
(setf *breeds* (list (list :turtles "default")))
- (setf
- *patches*
- (loop
- :for y :from (max-pycor) :downto (min-pycor)
- :append (loop
- :for x :from (min-pxcor) :to (max-pxcor)
- :collect (make-patch
- :xcor (coerce x 'double-float)
- :ycor (coerce y 'double-float)
- :color 0d0))))
- (setf *turtles* nil)
- (setf *current-id* 0))
+ (clear-ticks)
+ (clear-patches)
+ (clear-turtles))
; These match netlogo's dump
(defgeneric dump-object (o))
(defun find-prim (symb)
(when symb
- (or
- (find symb *prims* :key #'prim-name)
- (find-prim (getf (find symb *prim-aliases* :key #'prim-name) :real-symb)))))
+ (find-if
+ (lambda (prim-name) (or (eql symb prim-name) (and (listp prim-name) (find symb prim-name))))
+ *prims* :key #'prim-name)))
; Let this grow, slowly but surely, eventually taking on calling context, etc.
; For now, it's just a
(defprim :any? :reporter (lambda (agentset) `(> (clnl-nvm:count ,agentset) 0)))
(defsimpleprim :ask :command clnl-nvm:ask)
(defagentvalueprim :color)
+(defsimpleprim '(:clear-all :ca) :command clnl-nvm:clear-all)
(defsimpleprim :count :reporter clnl-nvm:count)
(defsimpleprim :crt :command clnl-nvm:create-turtles)
(defsimpleprim :die :command clnl-nvm:die)
(defsimpleprim :fd :command clnl-nvm:forward)
(defsimpleprim :hatch :command clnl-nvm:hatch)
(defprim :if :command (lambda (pred a) `(when ,pred ,@(make-command-block-inline a))))
-(defprim :ifelse :command (lambda (pred a b)
- `(if ,pred
- ,@(make-command-block-inline a)
- ,@(make-command-block-inline b))))
+(defprim '(:ifelse :if-else)
+ :command (lambda (pred a b)
+ `(if ,pred
+ ,@(make-command-block-inline a)
+ ,@(make-command-block-inline b))))
-(defprim-alias :if-else :ifelse)
(defagentvalueprim :label)
(defagentvalueprim :label-color)
(defsimpleprim :lt :command clnl-nvm:turn-left)