From: Nicholas Brownlow
Subject: Uncreating symbols in Common Lisp
Date: 
Message-ID: <3njsnd$rnf@cantaloupe.srv.cs.cmu.edu>
Can Lucid Common Lisp be persuaded to forget about a symbol completely --
to remove the symbol and its name string from whatever internal tables
hold this information?

I have an application which tokenizes its input by making symbols out
of strings (by INTERNing them in the :USER package), and I'd like to
get rid of the symbols once I'm done with them in order to reclaim the
memory.  I assume UNINTERN isn't sufficient, since uninterned symbols
remain in Lisp as data objects.

If symbols, once created, are "permanent" in CL, I'll have to change
the tokenizer.

Thanks,
Nicholas Brownlow

From: Pete Halverson
Subject: Re: Uncreating symbols in Common Lisp
Date: 
Message-ID: <pch-2604950826070001@m142.mystech.com>
In article <··········@cantaloupe.srv.cs.cmu.edu>, ····@cs.cmu.edu
(Nicholas Brownlow) wrote:

> Can Lucid Common Lisp be persuaded to forget about a symbol completely --
> to remove the symbol and its name string from whatever internal tables
> hold this information?
> 
> I have an application which tokenizes its input by making symbols out
> of strings (by INTERNing them in the :USER package), and I'd like to
> get rid of the symbols once I'm done with them in order to reclaim the
> memory.  I assume UNINTERN isn't sufficient, since uninterned symbols
> remain in Lisp as data objects.

I can't speak for LCL in particular, but I would expect that as long as
you have no other references to a symbol other than through its
SYMBOL-PACKAGE (e.g. nothing like (SETF *SOME-GLOBAL* (FIND-SYMBOL
"FOO"))), UNINTERNing the symbol should permit the space to be reclaimed
by the garbage collector.    

If you're doing stuff like this, though, you really don't want to be
interning into USER. When I'm genning lots of arbitrary symbols which
aren't otherwise connected to application definitions, I typically create
a separate package:

   (defpackage TOKENS
     (:use))

Note the explicit null :USE list.  This ensures that if the user supplies
input like "Provide the first car if special", you won't end up trying to
unintern Common Lisp symbols (as would happen if you were using :USER, or
any other package that :USEd CL).   Isolating symbols like this also lets
you release your tokens en masse with a DELETE-PACKAGE (again, as long as
there aren't any other references hanging around.)

pch
From: Barry Margolin
Subject: Re: Uncreating symbols in Common Lisp
Date: 
Message-ID: <3nud90$2ek@tools.near.net>
In article <··········@cantaloupe.srv.cs.cmu.edu> ····@cs.cmu.edu (Nicholas Brownlow) writes:
>If symbols, once created, are "permanent" in CL, I'll have to change
>the tokenizer.

No data in Lisp is "permanent" (unless you're using some kind of persistant
storage library, which saves the data to an external database).  Symbols
will be GC'ed when there are no references to them, just like any other
data.  The only difference with most other data types is that symbols are
normally interned, which is an implicit reference.  But if you unintern a
symbol from all the packages that reference it, and drop all other
references, the garbage collector will get it.

Some Lisps will also unintern symbols if their only reference is from a
single package.  Since this violates strict CL semantics (it changes the
behavior of DO-SYMBOLS and APROPOS, but it's otherwise undetectable), it
generally requires use of an implementation-specific feature.  MacLisp used
to call this feature "GCTWA" (GC Truly Worthless Atoms).
-- 
Barry Margolin
BBN Planet Corporation, Cambridge, MA
······@bbnplanet.com