chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] need help with hygienic macros


From: Peter Bex
Subject: Re: [Chicken-users] need help with hygienic macros
Date: Sun, 12 May 2013 15:00:25 +0200
User-agent: Mutt/1.4.2.3i

On Sun, May 12, 2013 at 02:41:05PM +0200, Jörg F. Wittenberger wrote:
> Here my current state of affairs:
> 
> ;; The definer:
> 
> (define-syntax deftig
>  (syntax-rules ()
>    ((_ name . body)  ;; Within this "body" I want some rewrites.
>     (define name
>       (lambda (x y)
>        (let-syntax
>            ((pinapple
>              (syntax-rules ()
>                ((_ ((p v) ...) . body)
>                 (let-syntax ((helper (syntax-rules ()
>                                        ((_ p ...) (begin . body))))) 
>                   (helper v ...))))))
> 
>           ;; trying to bind "foo" and "gosh" within "body" here
> 
>          (pinapple ((foo (x y)) (gosh y)) . body)))))

This doesn't work because the outer syntax-rules tries to interpret the
ellipsis.  The ... always refers to the pattern belonging to the
outermost expansion in which ... occurs.  The problem then is that
the expansion refers to ... but the pattern has no matching ... to base
the expansion on.

If you want to use ... in nested syntax-rules, you'll have to pass your
own alternative name, as per SRFI-46's "ellipsis identifier":

(define-syntax test
  (syntax-rules ()
    ((_ foo bar ...)
     (let-syntax ((inner (syntax-rules <...> ()
                           ((_ bla more-bla <...>)
                            (print bla more-bla <...> bar ...)))))
       (inner 1 2 3)))))

;; prints 123456:
(test 4 5 6)

The ellipsis functionality in the inner macro is bound to the
identifier <...>.  This allows arbitrary nesting, as long as
each level using ellipsis has its own ellipsis identifier.

Since you're not using the outer syntax-rules's ellipsis, you can just
change the first lines to:

---
(define-syntax deftig
  (syntax-rules _ ()
---

This will ignore the outer ellipsis.

Cheers,
Peter
-- 
http://www.more-magic.net



reply via email to

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