1 (in-package #:clnl-nvm)
3 (defvar *current-id* 0)
6 (defvar *turtles-own-vars* nil)
10 (defvar *dimensions* nil)
11 (defvar *globals* nil)
12 (defvar *topology* :torus)
16 (define-condition stop nil nil)
18 (defmacro with-stop-handler (&rest forms)
19 "MACRO WITH-STOP-HANDLER &rest FORMS => HANDLED-FORM
23 FORMS: body to be handled
24 HANDLED-FORM: body with handling
28 WITH-STOP-HANDLER is a convenience macro to handle when
29 programs issue a stop condition. When one does, a simple
31 `(handler-case (progn ,@forms) (stop (s) (declare (ignore s)) :stop)))
33 (defstruct turtle who color heading xcor ycor (label "") (label-color 9.9d0) (size 1d0) shape own-vars)
34 (defstruct patch color xcor ycor)
36 (defun agentset-list (agentset)
38 ((eql agentset :turtles) *turtles*)
39 ((eql agentset :patches) *patches*)
40 ((and (listp agentset) (eql :agentset (car agentset))) (cddr agentset))
41 (t (error "Doesn't seem to be an agentset: ~A" agentset))))
43 (defun agentset-breed (agentset)
45 ((eql agentset :turtles) :turtles)
46 ((eql agentset :patches) :patches)
47 ((and (listp agentset) (eql :agentset (car agentset))) (second agentset))
48 (t (error "Doesn't seem to be an agentset: ~A" agentset))))
50 (defun list->agentset (list breed)
51 (append (list :agentset breed) list))
57 (and (listp o) (eql :agentset (car o)))))
60 (or (turtle-p o) (patch-p o)))
62 (defun breed-p (breed)
63 (find breed *breeds* :key #'car))
65 (defun breed-default-shape (breed)
66 (second (find breed *breeds* :key #'car)))
68 (defsetf breed-default-shape (breed) (shape)
69 `(setf (second (find ,breed *breeds* :key #'car)) ,shape))