1 (in-package #:clnl-nvm)
3 (defvar *current-id* 0)
6 (defvar *turtles-own-vars* nil)
7 (defvar *patches-own-vars* nil)
11 (defvar *dimensions* nil)
12 (defvar *globals* nil)
13 (defvar *topology* :torus)
17 (define-condition stop nil nil)
18 (define-condition death nil nil)
20 (defmacro with-stop-handler (&rest forms)
21 "MACRO WITH-STOP-HANDLER &rest FORMS => HANDLED-FORM
25 FORMS: body to be handled
26 HANDLED-FORM: body with handling
30 WITH-STOP-HANDLER is a convenience macro to handle when
31 programs issue a stop condition. When one does, a simple
33 `(handler-case (progn ,@forms) (stop (s) (declare (ignore s)) :stop)))
35 (defmacro with-stop-and-death-handler (&rest forms)
38 (stop (s) (declare (ignore s)) :stop)
39 (death (d) (declare (ignore d)) :death)))
41 (defstruct turtle who breed color heading xcor ycor (label "") label-color size shape own-vars)
42 (defstruct patch color xcor ycor own-vars turtles)
44 (defun agentset-list (agentset)
46 ((eql agentset :turtles) *turtles*)
47 ((eql agentset :patches) *patches*)
48 ((and (listp agentset) (eql :agentset (car agentset))) (cddr agentset))
49 ((find agentset *breeds* :key #'car)
50 (remove agentset *turtles* :key #'turtle-breed :test-not #'eql))
51 (t (error "Doesn't seem to be an agentset: ~A" agentset))))
53 (defun agentset-breed (agentset)
55 ((eql agentset :turtles) :turtles)
56 ((eql agentset :patches) :patches)
57 ((find agentset *breeds* :key #'car) agentset)
58 ((and (listp agentset) (eql :agentset (car agentset))) (second agentset))
59 (t (error "Doesn't seem to be an agentset: ~A" agentset))))
61 (defun list->agentset (list breed)
62 (append (list :agentset breed) list))
68 (find o *breeds* :key #'car)
69 (and (listp o) (eql :agentset (car o)))))
72 (or (turtle-p o) (patch-p o)))
74 (defun breed-p (breed)
75 (find breed *breeds* :key #'car))
77 (defun breed-default-shape (breed)
78 (second (find breed *breeds* :key #'car)))
80 (defsetf breed-default-shape (breed) (shape)
81 `(setf (second (find ,breed *breeds* :key #'car)) ,shape))