From: jsancho Date: Sun, 22 Jan 2012 09:25:45 +0000 (+0000) Subject: External main function for each mob (wich permits redefinition of mobs in run time) X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=0d2ae3310d3ec22e70023f4f1739c83e2f2cbadf;p=gacela.git External main function for each mob (wich permits redefinition of mobs in run time) --- diff --git a/src/gacela.scm b/src/gacela.scm index f3794c9..10e7d8b 100644 --- a/src/gacela.scm +++ b/src/gacela.scm @@ -279,11 +279,21 @@ (,fun-name 123))))))) (define-macro (define-mob-function head . body) - (let ((fun-name (car head)) (attr (cdr head))) - `(define (,fun-name data) - (catch #t - (lambda* () ,@body) - (lambda (key . args) #f)))) + (let ((fun-name (car head)) (attr (map (lambda (a) (if (list? a) a (list a #f))) (cdr head))) + (data-symbol (gensym)) + (body-fun + `(catch #t + (lambda* () ,@body) + (lambda (key . args) #f)))) + `(define (,fun-name ,data-symbol) + (let ,attr + ,@(map + (lambda (a) + `(let ((val (assoc-ref ,data-symbol ',(car a)))) + (cond (val (set! ,(car a) val))))) + attr) + ,body-fun + (list ,@(map (lambda (a) `(cons ',(car a) ,(car a))) attr)))))) (define-macro (define-mob mob-head . body) (let* ((name (car mob-head)) (attr (cdr mob-head))