From 9e55bd787fa48db3ce0b8bde5ce40539b301d30a Mon Sep 17 00:00:00 2001 From: jsancho Date: Fri, 3 Jun 2011 00:08:09 +0000 Subject: [PATCH] --- src/gacela_mobs.scm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/gacela_mobs.scm b/src/gacela_mobs.scm index c442bf5..12a0ef1 100755 --- a/src/gacela_mobs.scm +++ b/src/gacela_mobs.scm @@ -20,16 +20,20 @@ ;;; Actions for mobs (define-macro (define-action action-def . code) - `(define (,name mob-attr) - ,@code)) - -(define-macro (define-action2 name attr . code) - `(define (,name mob-attr) - (let ,attr - ,@code - ,(cons 'begin (map #'attribute-save (reverse attr))) - mob-attr))) - + (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 -- 2.39.2