chicken-users
[Top][All Lists]
Advanced

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

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


From: felix
Subject: [Chicken-users] Re: Explicit Renaming Macros Help/Tutorial?
Date: Mon, 8 Jun 2009 10:34:29 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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






reply via email to

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