guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Uninterned symbols


From: Marius Vollmer
Subject: Re: Uninterned symbols
Date: 18 May 2001 00:15:15 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102

[Taken to guile-devel.]

Dirk Herrmann <address@hidden> writes:

> Maybe I am too blind to see, but:  What are the problems with providing
> unique symbols?  We have one single hash table in guile, thus it should be
> possible to determine whether a symbol exists or not.

It is possible to create a new symbol that has not existed previously,
but it is not possible to guarantee that all symbols that will be
created elsewhere are also different from this new symbol.

For example (contrived):

    guile> (define g (gensym))
    guile> g
    g0                                     ; g0 is unique
    guile> (define gg 'g0)                 ; but no longer
    guile> (eq? g 'g0)
    #t

Even when gensym makes sure that there was no symbol with the name
"g0" prior to its call, it can not make sure that string->symbol wont
return it later.

I find it difficult to come up with a good example where this is a
problem.  One might be a macro that wants to introduce some top-level
binding that should be guaranteed not to conflict with other top-level
bindings.  Like

    (define-macro (define-counter name)
      (let ((c (gensym)))
        `(begin
           (define ,c 0)
           (define (,(symbol-append name '-up)) (set! ,c (1+ ,c)))
           (define (,(symbol-append name '-down)) (set! ,c (1- ,c)))
           (define (,name) ,c))))

(There might be better ways to write this, but that's not the point here.)

The global definition of the gensym name can conflict with code that
is `read' later and executed in the same module.

> All other suggestions seem strange to me: Why add the concept of
> uninterned symbols?

Because they are a sure-fire way to have a guaranteed unique symbol
object that is guaranteed to not be used accidentally for unwanted
purposes.  Such a guarantee might not be as important to have in
Scheme as in Common Lisp, since in Scheme symbols have fewer uses.

> How can two uninterned symbols be eq?,

If they are `eq?', they are only one symbol! ;)

> how do you print them uniquely (seems impossible: with
> string->symbol you should be able to create any interned symbol you
> like and make it look like an uninterened one.),

Uninterned symbols must be printed differently from interned symbols.
Identical uninterned symbols could be identified in printed output by
using the notation for shared structure to flag them.  Like, assuming
gensym returns uninterned symbols, and uninterned symbols are printed
with a "#~" prefix:

    guile> (define g (gensym))
    guile> (define h (list g g))
    guile> h
    (#1=#~g0 #1#)

We would have to fix the reader and printer to get this right, I
think.

> and if you want to be able to read the same uninterened symbols
> twice,

Reading a "#~" object would create a new uninterned symbol with the
given name, and recreating the original structure would be achieved
with the `#n=' and `#n#' notation.


Does this make sense?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]