Lisp HUG Maillist Archive

Symbols vs strings

Please excuse me if this is too simple a question:
 
If I QUOTE a name I get this:
 
CL-USER 1 > 'foo
FOO
 
I can use STRING to get this:
 
CL-USER 2 > (string 'foo)
"FOO"
My question is, is there something like an UNSTRING type function to get this:
 
CL-USER 3 > (unstring "foo")
FOO
 
Thanks in advance!
 
Bruce.
 

Re: Symbols vs strings

On Wednesday 31 May 2006 11:44 pm, Bruce J. Weimer, MD wrote:
> My question is, is there something like an UNSTRING type function to get
> this:
>
> CL-USER 3 > (unstring "foo")
> FOO

I think that you're asking how to convert a string to a symbol.

The function is "intern", as in (intern "FOO").

I think that "intern" is an mnemonic for "internalize" - i.e. to make 
something into an internal symbol (a symbol which has been entered into the 
reader's symbol table) (btw. it is possible to create symbols that are not in 
the reader's symbol table, for example by using unintern to remove the symbol 
from the symbol table).

Use capital letters, since CL treats non-caps as escaped chars, i.e. (intern 
"foo") results in the symbol |foo|, not FOO.

pt


Re: Symbols vs strings

Bruce J. Weimer, MD wrote:

> Please excuse me if this is too simple a question:
>  
> If I QUOTE a name I get this:
>  
> CL-USER 1 > 'foo
> FOO
>  
> I can use STRING to get this:
>  
> CL-USER 2 > (string 'foo)
> "FOO"
> My question is, is there something like an UNSTRING type function to 
> get this:
>  
> CL-USER 3 > (unstring "foo")
> FOO
>  
> Thanks in advance!
>  
> Bruce.
>  
>

intern is what you are looking for:
CL-USER 31 > (intern "NEWSYMBOL")
NEWSYMBOL
NIL


but beware:
CL-USER 32 > (intern "newsymbol")
|newsymbol|
NIL



 http://www.lispworks.com/reference/HyperSpec/Body/f_intern.htm will 
give you more information.


Cheers, Denis.




Re: Symbols vs strings


'foo is a symbol and "foo" is a string.

If you want the name of the symbol as a string you can use symbol-name
or just string:

    (symbol-name 'foo) => "FOO"
    (string 'foo) => "FOO"

To create a symbol you can use intern:

    (intern "FOO") => 'FOO

The Cookbook has a section on this:

  http://cl-cookbook.sourceforge.net/strings.html#symbols

Hope that helps!

Cheers,
Chris Dean

http://www.lispworks.com/documentation/HyperSpec/Body/f_string.htm
http://www.lispworks.com/documentation/HyperSpec/Body/f_symb_2.htm
http://www.lispworks.com/documentation/HyperSpec/Body/f_intern.htm



Updated at: 2020-12-10 08:48 UTC