Re: gensym not creating unique symbols

From: Brian Denheyer <>
Date: Thu, 24 Jun 1999 08:06:48 -0700 (PDT)

>>>>> "Lars" == Lars Thomas Hansen <> writes:

  Lars> So you really need to compare the _symbol_ returned from
  Lars> GENSYM with a standard symbol with the same print name. (If
  Lars> they compare eq?, I'd say you have cause for complaint :-)

Actually I tracked down the code for gensym, and I don't think gensym
will do what I would like. The code is in scheme and uses a simple
counter captured in a closure.

I don't see anyway that it could possibly "know" about symbols already

This is part of a larger issue for me, and probably lots of others,
which is the "saving data in scheme and then reading it back in and
re-establishing all of the references" problem.

I was trying to generate data files which could be read back in using
ONLY, (load "filename"), and the loaded expressions would "do the
right thing". I was very successful with this approach until I
realized I had data-structures which required references to other

When saving structures which contain shared data I found that you have
to create temporary variables/data-structures as you read the data
back in. This would require making the "saved" data quite complex,
i.e. I would have to start introducing closures in the saved file.

I'm using object save routines I received from David Fox (??), and it
uses a eq? hash-table to check the data as it writes and then saves
the item in an alternate format if it is a reference (i.e. is already
in the table). When reading you have to set up the hash table again.
You also have to read in the data item, know that it is a reference
and not a ergular scheme datum, and then look it up in the table.

I was trying very hard to avoid using

(let* ((datum (read port))
       (eval datum))

There is something aesthetically pleasing about writing out the file
in a manner which in which it can simply be load'ed, but I think that
the need to establish references kills that approach.

Or maybe I just need to think harder :-)


(define gensym
  (let ((counter 0))
    (lambda prefix
      (set! counter (+ counter 1))
         (string-append (if (null? prefix) "G" (car prefix))
                        (number->string counter))))))
Received on Thu Jun 24 1999 - 17:07:22 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST