Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

let-syntax splicing into top-level?
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

Report this thread to moderator Post Follow-up to this message
Old Post
David Van Horn
10-15-04 08:59 PM


Re: let-syntax splicing into top-level?
David Van Horn <dvanhorn@cs.uvm.edu> wrote in message news:<ckols2$1n8rl$1@swen.emba.uvm.ed
u>...
> 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...gle.com


Report this thread to moderator Post Follow-up to this message
Old Post
oleg@pobox.com
10-15-04 08:59 PM


Re: let-syntax splicing into top-level?
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-synt
ax
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

Report this thread to moderator Post Follow-up to this message
Old Post
David Van Horn
10-16-04 01:56 AM


Re: let-syntax splicing into top-level?
David Van Horn <dvanhorn@cs.uvm.edu> wrote in message news:<ckpcoq$1na4j$1@swen.emba.uvm.ed
u>...
> 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 ide
a
> (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 destroy
s
> 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}

Report this thread to moderator Post Follow-up to this message
Old Post
oleg@pobox.com
10-16-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Scheme archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:55 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.