X-Git-Url: https://code.consxy.com/gitweb/gitweb.cgi?a=blobdiff_plain;f=src%2Fmain%2Fnvm%2Fbase.lisp;h=af87bc27e167f68c320a51009d59087bb22b60d6;hb=762ab38;hp=ddd429ee265cf9ca01825340f13b340db20960d2;hpb=8b23537f6b141ee51a23ce4eb66e93105bf040a9;p=clnl diff --git a/src/main/nvm/base.lisp b/src/main/nvm/base.lisp index ddd429e..af87bc2 100644 --- a/src/main/nvm/base.lisp +++ b/src/main/nvm/base.lisp @@ -7,7 +7,62 @@ (defvar *myself* nil) (defvar *self* nil) (defvar *dimensions* nil) +(defvar *globals* nil) (defvar *topology* :torus) +(defvar *ticks* nil) +(defvar *breeds* nil) -(defstruct turtle who color heading xcor ycor) +(define-condition stop nil nil) + +(defmacro with-stop-handler (&rest forms) + "MACRO WITH-STOP-HANDLER &rest FORMS => HANDLED-FORM + +ARGUMENTS AND VALUES: + + FORMS: body to be handled + HANDLED-FORM: body with handling + +DESCRIPTION: + + WITH-STOP-HANDLER is a convenience macro to handle when + programs issue a stop condition. When one does, a simple + :stop is returned." + `(handler-case (progn ,@forms) (stop (s) (declare (ignore s)) :stop))) + +(defstruct turtle who color heading xcor ycor (label "") (label-color 9.9d0) (size 1d0) shape) (defstruct patch color xcor ycor) + +(defun agentset-list (agentset) + (cond + ((eql agentset :turtles) *turtles*) + ((eql agentset :patches) *patches*) + ((and (listp agentset) (eql :agentset (car agentset))) (cddr agentset)) + (t (error "Doesn't seem to be an agentset: ~A" agentset)))) + +(defun agentset-breed (agentset) + (cond + ((eql agentset :turtles) :turtles) + ((eql agentset :patches) :patches) + ((and (listp agentset) (eql :agentset (car agentset))) (second agentset)) + (t (error "Doesn't seem to be an agentset: ~A" agentset)))) + +(defun list->agentset (list breed) + (append (list :agentset breed) list)) + +(defun agentset-p (o) + (or + (eql o :turtles) + (eql o :patches) + (and (listp o) (eql :agentset (car o))))) + +(defun agent-p (o) + (or (turtle-p o) (patch-p o))) + +(defun breed-p (breed) + (find breed *breeds* :key #'car)) + +(defun breed-default-shape (breed) + (second (find breed *breeds* :key #'car))) + +(defsetf breed-default-shape (breed) (shape) + `(setf (second (find ,breed *breeds* :key #'car)) ,shape))