X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela_mobs.scm;h=927d8b138af7125823b8b549e1dcf20605211e83;hb=d2cbfa2d53c011c7c1939e14201fb41a322a9031;hp=c0507f5af6eb529a4a61a44f6fe1ac060cc8cb5a;hpb=25092276a1f3e86b9681fe155b7050da730a3514;p=gacela.git diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index c0507f5..927d8b1 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -54,31 +54,31 @@ ;;; Actions and looks for mobs -(defmacro make-behaviour (name attr &rest code) - `(defun ,(get-behaviour-fun-name name) (object-attr) - (let ,(mapcar #'attribute-definition attr) +(define (get-attr list name default) + (let ((value (assoc-ref list name))) + (cond (value (car value)) + (else default)))) + +(define (attr-def attr) + (let ((name (car attr)) + (value (cadr attr))) + `(,name (get-attr attributes ',name ',value)))) + +(define (attr-save attr) + (let ((name (car attr))) + `(assoc-set! attributes ',name (list ,name)))) + +(define-macro (define-action action-head . code) + (let ((name (car action-head)) (attr (cdr action-head))) + `(define ,name + (lambda-action ,attr ,@code)))) + +(define-macro (lambda-action attr . code) + `(lambda (attributes) + (let ,(map attr-def attr) ,@code - ,(cons 'progn (mapcar #'attribute-save (reverse attr))) - object-attr))) - -(defun get-behaviour-fun-name (name) - (intern (concatenate 'string "BEHAVIOUR-" (string-upcase (string name))) 'gacela)) - -(defun attribute-name (attribute) - (intern (string attribute) 'keyword)) - -(define (attribute-definition attribute) - (let* ((name (cond ((list? attribute) (car attribute)) - (else attribute))) - (pname (attribute-name name)) - (value (cond ((listp attribute) (cadr attribute))))) - `(,name (getf object-attr ,pname ,value)))) - -(defun attribute-save (attribute) - (let* ((name (cond ((listp attribute) (car attribute)) - (t attribute))) - (pname (attribute-name name))) - `(setf (getf object-attr ,pname) ,name))) + ,(cons 'begin (map attr-save attr)) + attributes))) (define-macro (lambda-look . look) (define (process-look look)