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

Re: string > symbol?



At 10:43 3/17/95 -0500, Ken Tilton wrote:
>We keep running into the need to make a string into a symbol, but things are
>not going well.
>
>"intern" is not really working for us, but I gather that is the way to go.
>here's the scoop.
>
>Suppose we have a string we wish to parameterize: 'Hi, I'm #name#". We want to
>take the bit between #s and treat it as a slot accessor:
>
>  (expand a-string a-target), which would lead to (at some point):
>
>     (funcall (string-to-symbol (stuff-between #\# a-string)) a-target)
>
>which would be in this case the same as (name a-target).
>
>But this don't work. Intern is advertised in CLtL as converting a string to a
>symbol, but I note the returned value is |NAME|, not "name".


On my MCL it returns |name|.  If you want to get the same symbol as'name gets,
do (intern (string-upcase "name")) or arrange for the #name# in the original
string to be #NAME#.  Also be sure that *PACKAGE* is bound to the right package
around your calls to INTERN.

Using INTERN is fine, especially if you want to keep other things associated with
the symbol (e.g. properties), but might be overkill.  You could always keep your
own mapping between the strings and the functions, in an a-list (using ASSOC
to do the lookup) if there are only a small number of them or in a hash-table if
there are many.

>
>Is there a way to do what we are trying, or am I just taking a non-Lisp
>approach to a problem?
>
>Cheers, Ken