|
From: | Jack Trades |
Subject: | Re: [Chicken-users] Re: Explicit Renaming Macros Help/Tutorial? |
Date: | Mon, 8 Jun 2009 16:13:20 -0400 |
Jack Trades <jacktradespublic <at> gmail.com> writes:Hi!
>
> I'm revisiting a problem I had a few months ago when developing a DSL and it
was suggested that explicit renaming macros would be the easiest solution.
However after reading everything macro-related I could find on the web I'm still
nowhere.
This should get you going:
(define-syntax (def x r c)
(let ((%define (r 'define))
(head (cadr x))
(body (cddr x)))
`(,%define
,(cons
(car head)
(let loop ((args (cdr head)) (req '()) (opt '()))
(cond ((null? args)
(append (reverse req) (reverse opt)))
((list? (car args))
(loop (cdr args)
req
(cons (car args)
(if (null? opt)
'(#!optional)
opt))))
((pair? opt)
(if (null? (cdr args))
(append (loop '() req opt) `(#!rest ,(car args)))
(syntax-error 'def "invalid lambda-list" head)))
(else (loop (cdr args) (cons (car args) req) opt)))))
,@body)))
(this is probably totally wrong, but you get the idea)
Also have a look here:
http://chicken.wiki.br/man/4/Modules%20and%20macros#explicit-renaming-macros
cheers,
felix
_______________________________________________
Chicken-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/chicken-users
[Prev in Thread] | Current Thread | [Next in Thread] |