Home > Archive > Scheme > October 2004 > let-syntax splicing into top-level?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
let-syntax splicing into top-level?
|
|
| David Van Horn 2004-10-15, 3:59 pm |
| I really wish I could write a let-syntax that expands into top level forms.
Is there no hope for me?
Eg:
(let-syntax ()
(define x 1))
David
| |
| oleg@pobox.com 2004-10-15, 3:59 pm |
| David Van Horn <dvanhorn@cs.uvm.edu> wrote in message news:<ckols2$1n8rl$1@swen.emba.uvm.edu>...
> I really wish I could write a let-syntax that expands into top level forms.
> Is there no hope for me?
>
> Eg:
>
> (let-syntax ()
> (define x 1))
1. Use (Petite) Chez Scheme that implements the proposal discussed at
the Scheme 1998 workshop.
2. Check to see if this can be re-written into
(define x (let-syntax ....))
Perhaps the following thread will prove useful:
http://google.com/groups?threadm=7e...ting.google.com
| |
| David Van Horn 2004-10-15, 8:56 pm |
| oleg@pobox.com wrote:
> David Van Horn <dvanhorn@cs.uvm.edu> wrote in message news:<ckols2$1n8rl$1@swen.emba.uvm.edu>...
>
>
> 1. Use (Petite) Chez Scheme that implements the proposal discussed at
> the Scheme 1998 workshop.
http://www.schemers.org/Events/Work...Sep1998/minutes
Right, but I'm trying to implement a R5RS macro.
Perhaps this should be a SRFI. There was at least the mention of adding this
to SRFI 53, but the idea seems to have been abandoned (rightfully so, this
really has nothing to do with ellipses in macro generated macros).
I believe Al Petrofsky's alexpander supports this extension as well, but I'm
not positive.
> 2. Check to see if this can be re-written into
> (define x (let-syntax ....))
Nope. Actually what I have in mind is an expansion into several define-syntax
forms that share a transformer introduced with let-syntax. Here is the idea
(ellipses here means elided code, not the ellipsis pattern):
(define-syntax i
(syntax-rules ()
((i e ...)
(let-syntax ((f (syntax-rules () ((f ...) (... e ...)))))
(begin
(define-syntax g ... (f ...) ...)
(define-syntax h ... (f ...) ...))))))
Let-syntax is needed so that the shared transformer f does not pollute the
namespace, but also because I can reference pattern variables bound by (i e
....) in the templates of f. If I move f to the top-level I have to add an e
parameter to the macro that passes this information, which quickly destroys
the readability of a (previously concise) macro.
Syntax-rules hits a rather sweet spot in the world of describing syntactic
abstractions, but leaves a lot to be desired which could be addressed with
just a few simple extensions. I hope the R6RS authors are paying attention to
the SRFI 46 and 53 discussions. The later SRFI was withdrawn, in part,
because syntax-rules couldn't cut it due to let-syntax implicitly expanding
into a let.
http://srfi.schemers.org/srfi-53/ma...e/msg00040.html
> Perhaps the following thread will prove useful:
>
> http://google.com/groups?threadm=7e...ting.google.com
Ah, thanks. I hadn't seen this thread.
David
| |
| oleg@pobox.com 2004-10-16, 3:56 am |
| David Van Horn <dvanhorn@cs.uvm.edu> wrote in message news:<ckpcoq$1na4j$1@swen.emba.uvm.edu>...
> Actually what I have in mind is an expansion into several define-syntax
> forms that share a transformer introduced with let-syntax. Here is the idea
> (ellipses here means elided code, not the ellipsis pattern):
>
> (define-syntax i
> (syntax-rules ()
> ((i e ...)
> (let-syntax ((f (syntax-rules () ((f ...) (... e ...)))))
> (begin
> (define-syntax g ... (f ...) ...)
> (define-syntax h ... (f ...) ...))))))
>
> Let-syntax is needed so that the shared transformer f does not pollute the
> namespace, but also because I can reference pattern variables bound by (i e
> ...) in the templates of f. If I move f to the top-level I have to add an e
> parameter to the macro that passes this information, which quickly destroys
> the readability of a (previously concise) macro.
One method (no pollution of the global namespace):
(define-syntax i
(syntax-rules ()
((i "it's me!" (e ...) f-arg1 ...)
; was: (let-syntax ((f (syntax-rules () ((f ...) (... e ...))))
(for-each display '(e ... f-arg1 ...)))
((i g h e ...)
(begin
(define-syntax g (syntax-rules () ((g)
(i "it's me!" (e ...) "in-g"))))
(define-syntax h (syntax-rules () ((h)
(i "it's me!" (e ...) "in-h" "in-h"))))))))
> (i g1 h1 "here" "there")
(i g1 h1 "here" "there")
#{Unspecific}
> (g1)
(g1)
heretherein-g#{Unspecific}
> (h1)
(h1)
heretherein-hin-h#{Unspecific}
Perhaps a better method:
(define-syntax define-syntaxes
(syntax-rules ()
((define-syntaxes (name) common (body))
(define-syntax name
(syntax-rules ()
((name . args)
(let-syntax common (let-syntax ((new body)) (new . args)))))))
((define-syntaxes (name . other-names) common (body . other-bodies))
(begin
(define-syntax name
(syntax-rules ()
((name . args)
(let-syntax common (let-syntax ((new body)) (new . args))))))
(define-syntaxes other-names common other-bodies)))))
(define-syntax i
(syntax-rules ()
((i g h e ...)
(define-syntaxes (g h)
((f
(syntax-rules ()
((f . f-args)
(for-each display '(e ... . f-args))))))
(
(syntax-rules () ((g) (f "in-g")))
(syntax-rules () ((h) (f "in-h" "in-h")))
)))))
> (i g1 h1 "here" "there")
(i g1 h1 "here" "there")
#{Unspecific}
> (g1)
(g1)
heretherein-g#{Unspecific}
> (h1)
(h1)
heretherein-hin-h#{Unspecific}
|
|
|
|
|