|
From: | Jörg F . Wittenberger |
Subject: | Re: [Chicken-users] need help with hygienic macros |
Date: | 12 May 2013 17:02:46 +0200 |
Thanks Peter, but... it doesn't do the trick for me either. I'm aware of the ellipsis problem. The partial success, I mentioned, I had when I tried to get rid of those inner ellipsis before. (Didn't know about the SRFI-46 possibility to pass an ellipsis identifier however.) Instead I tried to rewrite the sub-macro using dotted lists. This did work for a single-element body-form, or rather for the first form in the body. Nevertheless when I follow your advice and pass _ for the unused outer ellipsis, I still end up with the same problem: "foo" is unbound in my body... Here I followed your advice by changing the inner ellipsis id - however that's now commented out. If you move the #; comment to the alternate case you'll see how it still doesn't bind "foo" inside "body ...". It this possible with hygienic macros at all? (define-syntax deftig (syntax-rules () ((_ "pinapple" ((p v) ...) body ...) (let-syntax ((helper (syntax-rules ()((_ p ...) (begin body ...))))) (helper v ...)))
#; ((_ name body ...) (define name (lambda (x y) (let-syntax ((pinapple (syntax-rules <...> () ((_ ((p v) <...>) bdy <...>) (let-syntax ((helper (syntax-rules ()((_ p <...>) (begin bdy <...>))))) (helper v <...>))))))
(pinapple ((foo (x y)) (foog (x y)) (gosh y)) body ...))))) ((_ name body ...) (define name (lambda (x y) (deftig "pinapple" ((foo (x y)) (gosh y)) body ...)))) )) (define (foog x) (* 2 x)) (deftig bar (foo) (foog 2) (foog 2.5) (let ((n gosh)) (foog n)) 'phar) Thanks again! /Jörg On May 12 2013, Peter Bex wrote:
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
[Prev in Thread] | Current Thread | [Next in Thread] |