[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string > symbol?
- To: Ken Tilton <71460.744@compuserve.com>
- Subject: Re: string > symbol?
- From: slh@digitool.com (Steve Hain)
- Date: Fri, 17 Mar 1995 16:00:02 -0500
- Cc: MCL <info-mcl@digitool.com>
- Sender: owner-info-mcl@digitool.com
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