[plt-scheme] gensym in r6rs?

From: David Van Horn (dvanhorn at ccs.neu.edu)
Date: Fri Mar 27 11:09:52 EDT 2009

jmhufflen at lifc.univ-fcomte.fr wrote:
>> Hello,
>>
>> gensym seems to be thrown out of r6rs. Is there a standardized
>> equivalent?
> 
> (syntax->datum (generate-temporaries X))
> 
> where X is a linear list. This expression builds a list of symbols being
> same lenth than X.  That's somewhat heavy, I agree, but I think, there is
> no other way!

I'm not sure that should work.  You will get a list of unique 
*identifiers*, but I don't believe R6RS says syntax->datum will preserve 
the uniqueness to symbols, ie. that the resulting symbol will not be eq? 
to any other symbol.

Indeed, experimenting with PLT Scheme confirms this is not true, at 
least in PLT.

#!r6rs
(library (foo)
   (export)
   (import (rnrs))
   (define x (car (generate-temporaries '(x)))))

At the interactions window, inspect the syntax object x, where you can 
see the identifier's spelling.  If this is your first run of the program 
it will be "x1".  So try:

(eq? (syntax->datum x) (string->symbol "x1"))  ; => #t

Compare that with:

#lang scheme
(define x (gensym))

At the interactions window, inspect the symbol x, where you can see the 
symbol's spelling.  It will be something like "g1505".  So try:

(eq? x (string->symbol "g1505")) ; => #f

David


Posted on the users mailing list.