[plt-scheme] String -> listof symbols

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Mon May 17 13:42:50 EDT 2010

> Is there an easy way to convert a string like this -- "(a or (b and c))" --
>  to a list-of-symbols equivalent to '(a or (b and c)) ?
> (string->symbol "(a or (b and c))" returns '|(a or (b and c))|" .

You can use read, which knows how to consume the content of an input
port,  in combination with open-input-string, which knows how to turn
a string into an input port.

    http://docs.plt-scheme.org/reference/Reading.html?q=read#(def._((quote._~23~25kernel)._read))

    http://docs.plt-scheme.org/reference/stringport.html?q=open-input-string#(def._((quote._~23~25kernel)._open-input-string))



> What do
> the the vertical lines which book-end the output value signify?

The default writer is introducing those bars as a way of saying "this
is a symbol, but there's enough funny characters that I'll delimit it
for you."  The gory details on when this happens are in the section:

    http://docs.plt-scheme.org/reference/printing.html?q=writer&q=open-input-string


Posted on the users mailing list.