From: John S. Lewocz
Subject: string to symbol conversion
Date: 
Message-ID: <80761@eerie.acsu.Buffalo.EDU>
Is there any way to convert an arbitrary string like "bob" into the 
symbol bob in Common Lisp?

Thanks.

--John

From: Tim Moore
Subject: Re: string to symbol conversion
Date: 
Message-ID: <1991Jun21.102756.29132@hellgate.utah.edu>
In article <·····@eerie.acsu.Buffalo.EDU> ······@pegasus.cs.Buffalo.EDU (John S. Lewocz) writes:
>Is there any way to convert an arbitrary string like "bob" into the 
>symbol bob in Common Lisp?

(intern "bob") =>
|bob|
NIL

(intern (string-upcase "bob")) =>
BOB
NIL

-- 
Tim Moore                    ·····@cs.utah.edu {bellcore,hplabs}!utah-cs!moore
"Ah, youth. Ah, statute of limitations."
		-John Waters
From: David F. Skoll
Subject: Re: string to symbol conversion
Date: 
Message-ID: <dfs.677520608@spock>
In <·····@eerie.acsu.Buffalo.EDU> ······@pegasus.cs.Buffalo.EDU
(John S. Lewocz) writes:
>Is there any way to convert an arbitrary string like "bob" into the 
>symbol bob in Common Lisp?

If you don't have any weird characters in the string,

	(setq foo "bob")
	(read-from-string foo)  ;; ---> The symbol BOB

should work.  If you have some weird characters, but no "bars" (|) in the
string, then

	(setq foo "A #Bunch^&OfWeird**Cha#r$")
	(read-from-string
	   (concatenate 'string "|" foo "|"))

should do it.  If your string contains "|", then it's tougher, and
I don't feel like figuring it out right now. :-)

(Of course, if you place bars around the string, you may not get the
symbol in upper-case or whatever your Lisp's default is.)

--
David F. Skoll
From: kevin gallagher
Subject: Re: string to symbol conversion
Date: 
Message-ID: <32421@dime.cs.umass.edu>
An excellent programming principle is to use the least powerful
method for acheiving your objective.  This is especially important in
lisp because there are always several ways to do something, each with
widely different costs.  Using a big stick when a small one will do will
make your program run slower, probably lead to unexpected bugs, and
contribute to the misperception that `lisp is slow.'

In the case of converting a string to a symbol use INTERN.  INTERN looks
for an existing symbol with the specified name and creates one if no
such symbol exists.  It returns the symbol that was found or created.
(If you expect the symbol to already exist you should use FIND-SYMBOL
which returns nil no symbol with the specified name is found.)

As was pointed out in other messages, intern doesn't do case conversion
or anything else.

    (intern "Foo") => |Foo|
    (intern "FOO") => FOO

The function READ-FROM-STRING is too big a stick.  It invokes the reader
which is a large program by itself.  (On my Explorer (intern string) is
6-7 times faster than (read-from-string string) and it doesn't cons at
all.)  Perhaps even worse, INTERN will *always* return a string.
READ-FROM-STRING can return (and in fact *do*) anything.

    (intern "(cons 1 2)") => |(cons 1 2)|

    (read-from-string "(cons 1 2)" => (CONS 1 2)

    (catch 'exit (read-from-string "#.(throw 'exit 'dumb)")) => DUMB

EVAL, READ, and READ-xxx are the functions that are most overused when a
smaller stick will do.  Also, FORMAT and the other printing functions
can often be replaced with less powerful (and less costly) functions.

Kevin Gallagher
From: Marty Hall
Subject: Re: string to symbol conversion
Date: 
Message-ID: <1991Jun21.163755.16953@aplcen.apl.jhu.edu>
In article <·····@eerie.acsu.Buffalo.EDU> ······@pegasus.cs.Buffalo.EDU 
(John S. Lewocz) writes:

>Is there any way to convert an arbitrary string like "bob" into the 
>symbol bob in Common Lisp?

(read-from-string "bob") --> BOB

					- Marty Hall
------------------------------------------------------
····@aplcen.apl.jhu.edu, ···········@jhunix.bitnet, ..uunet!aplcen!hall
Artificial Intelligence Lab, AAI Corp, PO Box 126, Hunt Valley, MD 21030

(setf (need-p 'disclaimer) NIL)