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

Re: string > symbol?



At 10:43 AM 3/17/95, 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".
>
>Is there a way to do what we are trying, or am I just taking a non-Lisp
>approach to a problem?
>
>Cheers, Ken

I suggest reading the description of *print-case* and its interaction
with readtable-case, in section 22.1.6 of CLtL2. What print-name symbols
are interned with and how they are printed depend on such settings. If
you want to associate a function with more than one string (i.e., a
case-insensitive association), you can use an "equalp" hash table:

? (setq ht (make-hash-table :test 'equalp))
#<HASH-TABLE :TEST EQUALP size 0/60 #x1603C79>
? (setf (gethash "foo" ht) 'foo-fn)
FOO-FN
? (gethash "FOO" ht)
FOO-FN
T
? (gethash "Foo" ht)
FOO-FN
T
? 

- Steve Hain

Digitool, Inc.
______________________________________________________________________________
                       One Main Street   7th Floor   Cambridge, MA 02142   USA
                              Internet: slh@digitool.com   AppleLink: digitool
                                      World Wide Web: http://www.digitool.com/
                                         Tel: 617 441-5000   Fax: 617 576-7680