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

Re: string to symbol, how?



Excerpts from netnews.comp.lang.lisp.mcl: 5-May-95 Re: string to symbol,
how? by Tom McDougal@cs.uchicago 
> (let ((the-string "hello"))
>   (with-input-from-string (string-input-stream  the-string)
>     (read string-input-stream)))
> 

The problem with using the reader (in the above method or, equivalently,
using read-from-string) is that it is subject to errors. For example,
try the above with the string "foo:bar" or "(foo". Also, your symbol may
not contain the entire string (for example, if the string is "foo,bar").
In some cases, I use read-from-string, but always wrapped in
"ignore-errors".

As far as I know, intern never produces an error, although it can
produce some weird symbols. The only problem with intern is that, as
others mentioned, you need to worry about what package you're in and you
may have to force uppercase.