chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: Explicit Renaming Macros Help/Tutorial?


From: Jack Trades
Subject: Re: [Chicken-users] Re: Explicit Renaming Macros Help/Tutorial?
Date: Mon, 8 Jun 2009 16:13:20 -0400

On Mon, Jun 8, 2009 at 6:34 AM, felix <address@hidden> wrote:
Jack Trades <jacktradespublic <at> gmail.com> writes:

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

Hi!

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


Thanks, that's exactly what I was looking for.  Now that I know how it applies to my problem I shouldn't have too much trouble figuring the rest out.  I really appreciate your help.

Jack Trades

reply via email to

[Prev in Thread] Current Thread [Next in Thread]