How to convert from string to list in the shortest possible way
String x = "(+ 1 2)"
(coerce x 'list) or (coerce x 'cons)
return
(#\( #\+ #\Space #\1 #\Space #\2 #\))
I can try a MAPCAR or a DOLIST over the coerced result .... however
I want to get back the list (+ 1 2)
Any suggestions?
Thanks
In article <············@mozo.cc.purdue.edu>, OCID <······@purdue.edu> wrote:
>How to convert from string to list in the shortest possible way
>
>String x = "(+ 1 2)"
>
>(coerce x 'list) or (coerce x 'cons)
>return
>(#\( #\+ #\Space #\1 #\Space #\2 #\))
>
>I can try a MAPCAR or a DOLIST over the coerced result .... however
>I want to get back the list (+ 1 2)
READ-FROM-STRING
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
"OCID" <······@purdue.edu> wrote in message
·················@mozo.cc.purdue.edu...
> How to convert from string to list in the shortest possible way
>
> String x = "(+ 1 2)"
>
> (coerce x 'list) or (coerce x 'cons)
> return
> (#\( #\+ #\Space #\1 #\Space #\2 #\))
>
> I can try a MAPCAR or a DOLIST over the coerced result .... however
> I want to get back the list (+ 1 2)
>
> Any suggestions?
>
> Thanks
>
try:
(read-from-string x)
(setf the-list (read-from-string x))
the-list == (+ 1 2)
read-from-string also evaluates the s-expression (+ 1 2)
"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com>
wrote in message ························@news02.roc.ny.frontiernet.net...
>
> "OCID" <······@purdue.edu> wrote in message
> ·················@mozo.cc.purdue.edu...
> > How to convert from string to list in the shortest possible way
> >
> > String x = "(+ 1 2)"
> >
> > (coerce x 'list) or (coerce x 'cons)
> > return
> > (#\( #\+ #\Space #\1 #\Space #\2 #\))
> >
> > I can try a MAPCAR or a DOLIST over the coerced result .... however
> > I want to get back the list (+ 1 2)
> >
> > Any suggestions?
> >
> > Thanks
> >
>
> try:
>
> (read-from-string x)
>
> (setf the-list (read-from-string x))
>
> the-list == (+ 1 2)
>
> read-from-string also evaluates the s-expression (+ 1 2)
>
Correction it does not eval. the s-expression it returns
a number as a second value in Corman Lisp
but I don't know what the number means.
In article <···················@news01.roc.ny.frontiernet.net>,
Franz Kafka <"The C++ Compiler is the Sadist; The C++ Programmer is the Masochist." Anon C++. Describing Debuging a memory leak in C++.;> wrote:
>
>"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com>
>wrote in message ························@news02.roc.ny.frontiernet.net...
>> read-from-string also evaluates the s-expression (+ 1 2)
>>
>
>Correction it does not eval. the s-expression it returns
>a number as a second value in Corman Lisp
>but I don't know what the number means.
It's the position in the string where READ stopped. This is useful if the
string has multiple objects in it:
"(+ 1 2) (+ 3 4)"
You can call READ-FROM-STRING a second time with :START being the value
returned from the previous call, and then it will return the next object
whose printed representation is in the string.
--
Barry Margolin, ··············@level3.com
Genuity Managed Services, a Level(3) Company, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
"Barry Margolin" <··············@level3.com> wrote in message
·····················@paloalto-snr1.gtei.net...
> In article <···················@news01.roc.ny.frontiernet.net>,
> Franz Kafka <"The C++ Compiler is the Sadist; The C++ Programmer is the
Masochist." Anon C++. Describing Debuging a memory leak in C++.;> wrote:
> >
> >"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com>
> >wrote in message
························@news02.roc.ny.frontiernet.net...
> >> read-from-string also evaluates the s-expression (+ 1 2)
> >>
> >
> >Correction it does not eval. the s-expression it returns
> >a number as a second value in Corman Lisp
> >but I don't know what the number means.
>
> It's the position in the string where READ stopped. This is useful if the
> string has multiple objects in it:
>
> "(+ 1 2) (+ 3 4)"
>
> You can call READ-FROM-STRING a second time with :START being the value
> returned from the previous call, and then it will return the next object
> whose printed representation is in the string.
ACL 5.0.1:
[3c] USER(143): (read-from-string "(+ 1 2) (+ 3 4)")
(+ 1 2)
8
[3c] USER(144): (read-from-string "(+ 1 2) (+ 3 4)" :start 8)
(+ 1 2)
8
[3c] USER(145): (read-from-string "(+ 1 2) (+ 3 4)" :start 9)
(+ 1 2)
8
[3c] USER(146):
CLISP:
[7]> (read-from-string "(+ 1 2) (+ 3 4)")
(+ 1 2)
7
[8]> (read-from-string "(+ 1 2) (+ 3 4)" :start 7)
(+ 1 2)
7
[9]> (read-from-string "(+ 1 2) (+ 3 4)" :start 8)
(+ 1 2)
7
[10]> (read-from-string "(+ 1 2) (+ 3 4)" :start 9)
(+ 1 2)
7
[11]>
?????
AKW
>
> --
> Barry Margolin, ··············@level3.com
> Genuity Managed Services, a Level(3) Company, Woburn, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to
newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the
group.
>
"Andrew Wolven" <·······@nospam.net> writes:
> "Barry Margolin" <··············@level3.com> wrote in message
> ·····················@paloalto-snr1.gtei.net...
> > In article <···················@news01.roc.ny.frontiernet.net>,
> > Franz Kafka <"The C++ Compiler is the Sadist; The C++ Programmer is the
> Masochist." Anon C++. Describing Debuging a memory leak in C++.;> wrote:
> > >
> > >"Franz Kafka" <Symbolics _ XL1201 _ Sebek _ Budo _ Kafka @ hotmail . com>
> > >wrote in message
> ························@news02.roc.ny.frontiernet.net...
> > >> read-from-string also evaluates the s-expression (+ 1 2)
> > >>
> > >
> > >Correction it does not eval. the s-expression it returns
> > >a number as a second value in Corman Lisp
> > >but I don't know what the number means.
> >
> > It's the position in the string where READ stopped. This is useful if the
> > string has multiple objects in it:
> >
> > "(+ 1 2) (+ 3 4)"
> >
> > You can call READ-FROM-STRING a second time with :START being the value
> > returned from the previous call, and then it will return the next object
> > whose printed representation is in the string.
>
> ACL 5.0.1:
>
> [3c] USER(143): (read-from-string "(+ 1 2) (+ 3 4)")
> (+ 1 2)
> 8
> [3c] USER(144): (read-from-string "(+ 1 2) (+ 3 4)" :start 8)
> (+ 1 2)
> 8
READ-FROM-STRING is one of a handful of functions in Common Lisp that
take both optional and keyword arguments. The arguments :start and 8
are being gobbled up by the optional argumens eof-error-p and
eof-value. To do what you want you need to write:
> (read-from-string "(+ 1 2) (+ 3 4)" t nil :start 8)
(+ 3 4)
15
-Peter
--
Peter Seibel ·····@javamonkey.com
The intellectual level needed for system design is in general
grossly underestimated. I am convinced more than ever that this
type of work is very difficult and that every effort to do it with
other than the best people is doomed to either failure or moderate
success at enormous expense. --Edsger Dijkstra