On Mon, 25 Aug 2008 14:55:16 +0200 Peter Bex <[EMAIL PROTECTED]> wrote:
> On Mon, Aug 25, 2008 at 09:47:18AM -0300, Mario Domenech Goulart wrote: > > > > Is it possible with chicken 4 to generate toplevel (or module-level) > > definitions from a macro (explicit renaming)? > > > > I mean, I'd like something like: > > > > (module gen-things * > > > > (define-syntax gen-thing > > (lambda (thing) > > `(define ,thing (lambda () (display "hello"))))) > > > > (gen-thing one-thing) > > ) > > > > So I could use `one-thing' from module `gen-things'. > > I think all you need to do is change the macro a bit (untested): > > (define-syntax gen-thing > (lambda (exp r cmp) > (let ((thing (cadr exp))) > `(,(r 'define) ,thing (,(r 'lambda) () (,(r 'display) "hello")))))) Thanks, Peter. It works. I just had to add `(import scheme)' to get the R5RS stuff. So, the complete example is: (module gen-things (one-thing) (import scheme) (define-syntax gen-thing (lambda (exp r cmp) (let ((thing (cadr exp))) `(,(r 'define) ,thing (,(r 'lambda) () (,(r 'display) "hello")))))) (gen-thing one-thing) ) Usage: $ csi -n CHICKEN (c)2008 The Chicken Team (c)2000-2007 Felix L. Winkelmann Version 4.0.0x - linux-unix-gnu-x86 [ manyargs dload ptables applyhook ] SVN rev. 11756 compiled 2008-08-25 on ze-dureza (Linux) #;1> ,l gen-things.scm ; loading gen-things.scm ... ; loading /usr/local/chicken-hygienic/lib/chicken/4/scheme.import.so ... #;1> (import gen-things) #;2> (one-thing) hello Or (compiled): $ csc -s gen-things.scm $ csi -n CHICKEN (c)2008 The Chicken Team (c)2000-2007 Felix L. Winkelmann Version 4.0.0x - linux-unix-gnu-x86 [ manyargs dload ptables applyhook ] SVN rev. 11756 compiled 2008-08-25 on ze-dureza (Linux) #;1> ,l gen-things.so ; loading gen-things.so ... ; loading /usr/local/chicken-hygienic/lib/chicken/4/scheme.import.so ... #;1> (import gen-things) #;2> (one-thing) hello Best wishes. Mario _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users