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

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Feb 21 18:35:30 EST 2010

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

Posted on the users mailing list.