]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela_mobs.scm
(no commit message)
[gacela.git] / src / gacela_mobs.scm
index c0037f1053a5ab5416848c671623d07f2fdcd31c..12a0ef1d8aa90163e40a2469adfda912ac2b4184 100755 (executable)
 
 ;;; Actions for mobs
 
+(define-macro (define-action action-def . code)
+  (let ((name (car action-def)) (attr (cdr action-def)))
+    `(define (,name mob-attr)
+       (let ,(map attribute-definition attr)
+        ,@code
+        ,(cons 'list (map attribute-result attr))))))
+
+(define (attribute-definition attribute)
+  (let ((name (if (list? attribute) (car attribute) attribute))
+       (value (if (list? attribute) (cadr attribute) #f)))
+    `(,name (let ((v (assoc-ref mob-attr ',name))) (if v (cdr v) ,value)))))
+
+(define (attribute-result attribute)
+  (let ((name (if (list? attribute) (car attribute) attribute)))
+    `(list ',name ,name)))
 
 
 ;;; Mob Factory