[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A bug?
Miki Tebeka wrote:
>
> Hello All,
>
> It this a bug:
>
> > (gensym)
> g47
> > (define g48 'foo)
> > (gensym)
> g48
>
> (This is mzscheme version 101)
>
> Or gensym does something else than I think?
Gensym generates *uninterned* symbols. That means that the "g47" that
was generated the first time is distinct from any other symbol called
"g47." Ditto for g48.
So, look at the following:
> (define a (gensym))
> a
g4
> (define b 'g4)
> a
g4
> b
g4
> (eq? a b)
#f
> (equal? a b)
#f
A main use of gensym is to generate symbols that can never be generated
again.
This is particularly useful for building names/identifiers in macros;
the goal is to have a name that you know cannot conflict with anything
that an application might generate.
I used it in a set of R5RS functions for manipulating
"structures/records;" I wound up using gensym to generate a "signature"
to indicate that a particular structure instance was indeed generated by
the structure system.
--
Would-be National Mottos:
Switzerland: "You wouldn't hit a country that's neutral, would you?"
chris.browne@sabre.com
begin:vcard
n:Browne;Christopher
tel;work:817-963-5621
x-mozilla-html:FALSE
url:http://www.hex.net/~cbbrowne/
org:Sabre Inc;SHARP Project
version:2.1
email;internet:chris.browne@sabre.com
title:Consultant II
adr;quoted-printable:;;4333 Amon Carter Blvd=0D=0AMD 3N2D41;DFW Airport;TX;75261-9616;USA
x-mozilla-cpt:;0
fn:Christopher Browne
end:vcard
- References:
- A bug?
- From: Miki Tebeka <mtebeka@intel.com>