From: OCID
Subject: Simple Type Conversion question
Date: 
Message-ID: <b9rbpj$r7s$1@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

From: Barry Margolin
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <Hqawa.16$kc4.873@paloalto-snr1.gtei.net>
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.
From: Franz Kafka
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <dvawa.6341$3X6.5025@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)
From: Franz Kafka
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <rwawa.6698$tC1.1798@news01.roc.ny.frontiernet.net>
"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.
From: Barry Margolin
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <hBawa.18$kc4.522@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.

-- 
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.
From: Andrew Wolven
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <YRiwa.70924$4P1.6467006@newsread2.prod.itd.earthlink.net>
"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.
>
From: Peter Seibel
Subject: Re: Simple Type Conversion question
Date: 
Message-ID: <m3u1byxjrg.fsf@javamonkey.com>
"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