[plt-scheme] Defining syntax parameters that act like ordinary symbols outside of syntax-parameterize

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Sun Feb 21 18:49:10 EST 2010

Another answer here: if you want something like separate binding
spaces (ala ML, say), then you can prefix all of your special
identifiers with some keyword, ie instead of writing just 'x', you'd
write '(my-vars x)' and then you'd only have to take over the name
'my-vars' and not all the possible 'x's your programmers use.

Robby

On Sun, Feb 21, 2010 at 5:35 PM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
>
> On Feb 21, 2010, at 3:59 PM, Remco Bras wrote:
>
>> Hi,
>>
>> I'm using quite a few macros that use syntax parameters, so I'd like them to act like ordinary symbols (when not in syntax-parameterize) to not clutter up the namespace too much.
>> I wrote an attempt (see below) to alpha-rename the parameters to gensyms outside of syntax-parameterize.
>> Could someone tell me if this will work properly?
>> So far, I haven't found a way to break it.
>>
>> (define-syntax-parameter foo
>>                        (let ((sym (gensym)))
>>                          (make-rename-transformer (datum->syntax #f sym))))
>
>
> You're misusing the rename transformer. It really just renames foo to the random identifier that you created and that identifier isn't bound in phase 0. So here is something close to what you want:
>
>  (define foo-symbol 'foo)
>  (define-syntax-parameter foo (make-rename-transformer #'foo-symbol))
>
> Now having said that, I urge you to read Ryan's explanation carefully. I have never had any use for a global syntax parameter that isn't an error-signaling function. Indeed, I'd consider anything else a design flaw.
>
> Example: suppose you wish to rebind the keyword _resume_ so that you can write 'beautiful' coroutines like this:
>
>  (define const-routine (coroutine (while true (resume 1))))
>
> A properly designed syntax would inform a programmer who uses _resume_ outside of the coroutine sub-expression that only coroutines can employ resume expressions.
>
> -- Matthias
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.