;;; 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