From: Pascal Costanza
Subject: Re: Read-from-string
Date: 
Message-ID: <6s6tifF4ctlsU1@mid.individual.net>
Francogrex wrote:
> When I do this:
> (list (read-from-string "lala tata bobo"))
> the output is: (LALA)
> 
> but I want the output to be: (lala tata bobo), a list of symbols. How
> can this be done. Thanks.

(with-input-from-string (s "lala tata bobo")
   (loop repeat 3 collect (read s)))


Pascal

-- 
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/

From: ·········@yahoo.com
Subject: Re: Read-from-string
Date: 
Message-ID: <5e9cc7df-c0be-4eb4-b100-1c8b6b07ff65@w24g2000prd.googlegroups.com>
On Jan 2, 11:12 am, Francogrex <······@grex.org> wrote:
> On Jan 2, 5:26 pm, Pascal Costanza <····@p-cos.net> wrote:
>
> > (with-input-from-string (s "lala tata bobo")
> >    (loop repeat 3 collect (read s)))
>
> Hi thanks Pascal, but above was an example where I know that I have 3
> words, but in reality I'll be reading from an input where the number
> of words is unknown to me. Is there a way to circumvent this "repeat
> 3", because it would be "repeat n" and n is unknwon (it's as many
> words that the string contains).

Ruby:

"lala tata bobo  lame lisp".split
    ==>["lala", "tata", "bobo", "lame", "lisp"]
"lala tata bobo  lame lisp".scan(/\w+/)
    ==>["lala", "tata", "bobo", "lame", "lisp"]
From: D Herring
Subject: Re: Read-from-string
Date: 
Message-ID: <495e50e4$0$17067$6e1ede2f@read.cnntp.org>
·········@yahoo.com wrote:
> On Jan 2, 11:12 am, Francogrex <······@grex.org> wrote:
>> On Jan 2, 5:26 pm, Pascal Costanza <····@p-cos.net> wrote:
>>
>>> (with-input-from-string (s "lala tata bobo")
>>>    (loop repeat 3 collect (read s)))
>> Hi thanks Pascal, but above was an example where I know that I have 3
>> words, but in reality I'll be reading from an input where the number
>> of words is unknown to me. Is there a way to circumvent this "repeat
>> 3", because it would be "repeat n" and n is unknwon (it's as many
>> words that the string contains).
> 
> Ruby:
> 
> "lala tata bobo  lame lisp".split
>     ==>["lala", "tata", "bobo", "lame", "lisp"]
> "lala tata bobo  lame lisp".scan(/\w+/)
>     ==>["lala", "tata", "bobo", "lame", "lisp"]

Noob.  Can you not distinguish between a string and a symbol?
From: Alex Mizrahi
Subject: Re: Read-from-string
Date: 
Message-ID: <49620f7f$0$90265$14726298@news.sunsite.dk>
 wx> "lala tata bobo  lame lisp".split
 wx>     ==>["lala", "tata", "bobo", "lame", "lisp"]

* (cl-ppcre:split " " "fuck this ruby troll")

("fuck" "this" "ruby" "troll")
From: D Herring
Subject: Re: Read-from-string
Date: 
Message-ID: <495e5513$0$17070$6e1ede2f@read.cnntp.org>
Francogrex wrote:
> On Jan 2, 5:26 pm, Pascal Costanza <····@p-cos.net> wrote:
>> (with-input-from-string (s "lala tata bobo")
>>    (loop repeat 3 collect (read s)))
> 
> Hi thanks Pascal, but above was an example where I know that I have 3
> words, but in reality I'll be reading from an input where the number
> of words is unknown to me. Is there a way to circumvent this "repeat
> 3", because it would be "repeat n" and n is unknwon (it's as many
> words that the string contains).

One approach is to loop until READ signals an end-of-file.

Something like
(with-input-from-string (s "lala tata bobo")
    (let ((forms nil))
      (block nil
        (handler-bind
	((end-of-file (lambda (x)
			(declare (ignore x))
			(return))))
	(do ()
	    (nil)
	  (push (read s t) forms))))
      forms))

Though I'm sure there are more elegant implementations.

Another approach is to (read s nil :special-token) until 
:special-token appears.  Here, I use a gensym to ensure there is no 
collision with an actual read value (e.g. nil might be bad).

(with-input-from-string (s "lala tata bobo")
    (let ((forms nil)
	 (special-token (gensym)))
      (loop for x = (read s nil special-token)
	   until (eql x special-token)
	   do (push x forms))
      forms))


- Daniel
From: Carl Taylor
Subject: Re: Read-from-string
Date: 
Message-ID: <qYs7l.251066$Mh5.116071@bgtnsc04-news.ops.worldnet.att.net>
Francogrex wrote:
> On Jan 2, 5:26 pm, Pascal Costanza <····@p-cos.net> wrote:
>> (with-input-from-string (s "lala tata bobo")
>> (loop repeat 3 collect (read s)))
>
> Hi thanks Pascal, but above was an example where I know that I have 3
> words, but in reality I'll be reading from an input where the number
> of words is unknown to me. Is there a way to circumvent this "repeat
> 3", because it would be "repeat n" and n is unknwon (it's as many
> words that the string contains).


(with-input-from-string (s "lala tata bobo dada qwerty moo goo")
   (loop for token = (read s nil nil nil)
           while token
               collect token))

clt
From: Pascal J. Bourguignon
Subject: Re: Read-from-string
Date: 
Message-ID: <878wptk11i.fsf@informatimago.com>
"Carl Taylor" <··········@att.net> writes:

> Francogrex wrote:
>> On Jan 2, 5:26 pm, Pascal Costanza <····@p-cos.net> wrote:
>>> (with-input-from-string (s "lala tata bobo")
>>> (loop repeat 3 collect (read s)))
>>
>> Hi thanks Pascal, but above was an example where I know that I have 3
>> words, but in reality I'll be reading from an input where the number
>> of words is unknown to me. Is there a way to circumvent this "repeat
>> 3", because it would be "repeat n" and n is unknwon (it's as many
>> words that the string contains).
>
>
> (with-input-from-string (s "lala tata bobo dada qwerty moo goo")
>    (loop for token = (read s nil nil nil)
>            while token
>                collect token))
>


(let ((data  "lala tata bobo dada nil qwerty moo goo"))
  (with-input-from-string (s data)
     (loop for token = (read s nil nil nil)
             while token
                 collect token))) 
-> (LALA TATA BOBO DADA)

-- 
__Pascal Bourguignon__
From: Carl Taylor
Subject: Re: Read-from-string
Date: 
Message-ID: <Qqz7l.251774$Mh5.222651@bgtnsc04-news.ops.worldnet.att.net>
"Pascal J. Bourguignon" <···@informatimago.com> wrote in message 
···················@informatimago.com...
> "Carl Taylor" <··········@att.net> writes:
>
> (let ((data  "lala tata bobo dada nil qwerty moo goo"))
>  (with-input-from-string (s data)
>     (loop for token = (read s nil nil nil)
>             while token
>                 collect token)))
> -> (LALA TATA BOBO DADA)
>


CL-USER 17 >

(with-input-from-string (s "moo goo gai pan nil foo bar baz")
  (loop with eos = (gensym)
          for token = (read s nil eos nil)
          if (eq token eos)
            do (return token-list)
          else
            collect token into token-list))

(MOO GOO GAI PAN NIL FOO BAR BAZ)

clt
From: William James
Subject: Re: Read-from-string
Date: 
Message-ID: <gjmqrd0mcf@enews1.newsguy.com>
Carl Taylor wrote:

> "moo goo gai pan nil foo bar baz"

Ruby:

"moo goo gai pan nil foo bar baz".split.map{|x| x.to_sym}
    ==>[:moo, :goo, :gai, :pan, :nil, :foo, :bar, :baz]
From: William James
Subject: Re: Read-from-string
Date: 
Message-ID: <gjmr140mip@enews1.newsguy.com>
Carl Taylor wrote:

> 
> "Pascal J. Bourguignon" <···@informatimago.com> wrote in message
> ···················@informatimago.com...  >"Carl Taylor"
> <··········@att.net> writes:
> > 
> > (let ((data  "lala tata bobo dada nil qwerty moo goo"))
> > (with-input-from-string (s data)
> >    (loop for token = (read s nil nil nil)
> >            while token
> >                collect token)))
> >-> (LALA TATA BOBO DADA)
> > 
> 
> 
> CL-USER 17 >
> 
> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>  (loop with eos = (gensym)
>          for token = (read s nil eos nil)
>          if (eq token eos)
>            do (return token-list)
>          else
>            collect token into token-list))
> 
> (MOO GOO GAI PAN NIL FOO BAR BAZ)
> 
> clt


Ruby:

"moo goo gai pan nil foo bar baz".split.map{|x| x.to_sym}
    ==>[:moo, :goo, :gai, :pan, :nil, :foo, :bar, :baz] 
From: ······@corporate-world.lisp.de
Subject: Re: Read-from-string
Date: 
Message-ID: <bfb8726c-de99-40c9-b8cc-674ef7921d0a@z6g2000pre.googlegroups.com>
On 3 Jan., 05:53, "William James" <·········@yahoo.com> wrote:
> Carl Taylor wrote:
>
> > "Pascal J. Bourguignon" <····@informatimago.com> wrote in message
> >···················@informatimago.com...  >"Carl Taylor"
> > <··········@att.net> writes:
>
> > > (let ((data  "lala tata bobo dada nil qwerty moo goo"))
> > > (with-input-from-string (s data)
> > >    (loop for token = (read s nil nil nil)
> > >            while token
> > >                collect token)))
> > >-> (LALA TATA BOBO DADA)
>
> > CL-USER 17 >
>
> > (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> >  (loop with eos = (gensym)
> >          for token = (read s nil eos nil)
> >          if (eq token eos)
> >            do (return token-list)
> >          else
> >            collect token into token-list))
>
> > (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
> > clt
>
> Ruby:
>
> "moo goo gai pan nil foo bar baz".split.map{|x| x.to_sym}
>     ==>[:moo, :goo, :gai, :pan, :nil, :foo, :bar, :baz]

CL-USER 13 > "|william does| not\\ get it \"right again\""
"|william does| not\\ get it \"right again\""

CL-USER 14 > (with-input-from-string (input *)
              (loop for item = (read input nil input) until (eql item
input) collect item))
(|william does| NOT\ GET IT "right again")
From: D Herring
Subject: Re: Read-from-string
Date: 
Message-ID: <495fa9d2$0$17067$6e1ede2f@read.cnntp.org>
······@corporate-world.lisp.de wrote:
> On 3 Jan., 05:53, "William James" <·········@yahoo.com> wrote:
>> Ruby:
>>
>> "moo goo gai pan nil foo bar baz".split.map{|x| x.to_sym}
>>     ==>[:moo, :goo, :gai, :pan, :nil, :foo, :bar, :baz]
> 
> CL-USER 13 > "|william does| not\\ get it \"right again\""
> "|william does| not\\ get it \"right again\""
> 
> CL-USER 14 > (with-input-from-string (input *)
>               (loop for item = (read input nil input) until (eql item
> input) collect item))
> (|william does| NOT\ GET IT "right again")

A few more forms for Dorothy's magic ruby splitter:
"1234 #.(+ 1 2) #-sbcl stuff #b10001 #xdead #S(bus :driver Crabtree)"
From: Kenneth Tilton
Subject: Re: Read-from-string
Date: 
Message-ID: <495f70c1$0$14311$607ed4bc@cv.net>
Francogrex wrote:
> On Jan 3, 2:45 am, "Carl Taylor" <··········@att.net> wrote:
>> "Pascal J. Bourguignon" <····@informatimago.com> wrote:
>>> (let ((data  "lala tata bobo dada nil qwerty moo goo"))
>>>  (with-input-from-string (s data)
>>>     (loop for token = (read s nil nil nil)
>>>             while token
>>>                 collect token)))
>>> -> (LALA TATA BOBO DADA)
>> CL-USER 17 >
>>
>> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>>   (loop with eos = (gensym)
>>           for token = (read s nil eos nil)
>>           if (eq token eos)
>>             do (return token-list)
>>           else
>>             collect token into token-list))
>>
>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
> 
> Hmm, this is curious! How come in the first time around the processing
> of the strings to a list of symbols just stopped when it encountered
> "nil"? 

Because when the string "NIL" got read it became a Lisp nil.
Said nil got bound to the variable token.
Then came "while token..."


I guess I will need to analyse this to understand better.
> Although in reality I doubt that I will encouter the word "nil" in any
> of my data, but you never know.

I agree, the chances of that are nil.*

hth,kenneth

Yes, this is valid English natural language. k
From: William James
Subject: Re: Read-from-string
Date: 
Message-ID: <gjnlgh01ljr@enews1.newsguy.com>
Carl Taylor wrote:

> 
> "Pascal J. Bourguignon" <···@informatimago.com> wrote in message
> ···················@informatimago.com...  >"Carl Taylor"
> <··········@att.net> writes:
> > 
> > (let ((data  "lala tata bobo dada nil qwerty moo goo"))
> > (with-input-from-string (s data)
> >    (loop for token = (read s nil nil nil)
> >            while token
> >                collect token)))
> >-> (LALA TATA BOBO DADA)
> > 
> 
> 
> CL-USER 17 >
> 
> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>  (loop with eos = (gensym)
>          for token = (read s nil eos nil)
>          if (eq token eos)
>            do (return token-list)
>          else
>            collect token into token-list))
> 
> (MOO GOO GAI PAN NIL FOO BAR BAZ)
> 
> clt

Ruby:

token_list=[]
    ==>[]
"moo goo gai pan nil foo bar".scan(/\S+/){token_list << $&.to_sym}
    ==>"moo goo gai pan nil foo bar"
token_list
    ==>[:moo, :goo, :gai, :pan, :nil, :foo, :bar]
From: Madhu
Subject: Re: Read-from-string
Date: 
Message-ID: <m3r63keamo.fsf@moon.robolove.meer.net>
* "Carl Taylor" <·······················@bgtnsc04-news.ops.worldnet.att.net> :
Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
|
| (with-input-from-string (s "moo goo gai pan nil foo bar baz")
|   (loop with eos = (gensym)
|           for token = (read s nil eos nil)
|           if (eq token eos)
|             do (return token-list)
|           else
|             collect token into token-list))
|
| (MOO GOO GAI PAN NIL FOO BAR BAZ)


You can avoid the gensym by passing the stream itself.  IIRC I
spotted this technique first on CLL in an EN post.

(with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
   (loop with *READ-EVAL* = NIL ;[1]
         for token = (read stream nil stream)
         if (eql token stream)
             do (return token-list)
         else
             collect token into token-list))

[1] I recommend getting into the compulsive habit of binding *READ-EVAL*
    to NIL unless you have good reason to EVAL]

--
Madhu
From: Marco Antoniotti
Subject: Re: Read-from-string
Date: 
Message-ID: <cc1ef81e-c7a4-4f08-a3ca-e6b15ec09d20@e1g2000pra.googlegroups.com>
On Jan 3, 9:18 am, Madhu <·······@meer.net> wrote:
> * "Carl Taylor" <·······················@bgtnsc04-news.ops.worldnet.att.net> :
> Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
> |
> | (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> |   (loop with eos = (gensym)
> |           for token = (read s nil eos nil)
> |           if (eq token eos)
> |             do (return token-list)
> |           else
> |             collect token into token-list))
> |
> | (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
> You can avoid the gensym by passing the stream itself.  IIRC I
> spotted this technique first on CLL in an EN post.
>
> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>    (loop with *READ-EVAL* = NIL ;[1]
>          for token = (read stream nil stream)
>          if (eql token stream)
>              do (return token-list)
>          else
>              collect token into token-list))
>
> [1] I recommend getting into the compulsive habit of binding *READ-EVAL*
>     to NIL unless you have good reason to EVAL]
>
> --
> Madhu

Yep.

Just a little twist.

(with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
   (loop with *READ-EVAL* = NIL
         for token = (read stream nil stream)
         if (eql token stream)
             do (loop-finish)
         else
             collect token))

Cheers
--
Marco Antoniotti
www.european-lisp-symposium.org
From: Stanisław Halik
Subject: Re: Read-from-string
Date: 
Message-ID: <gjoi8s$23dk$1@opal.icpnet.pl>
thus spoke Madhu <·······@meer.net>:

> You can avoid the gensym by passing the stream itself.  IIRC I
> spotted this technique first on CLL in an EN post.
> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>   (loop with *READ-EVAL* = NIL ;[1]
>         for token = (read stream nil stream)
>         if (eql token stream)
>             do (return token-list)
>         else
>             collect token into token-list))
> [1] I recommend getting into the compulsive habit of binding *READ-EVAL*
>    to NIL unless you have good reason to EVAL]

How about that:

(with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
  (loop with *READ-EVAL* = NIL ;[1]
        ;; here
        for token = (read stream nil #1='#:foo)
        if (eql token #1#)
            do (return token-list)
        else
            collect token into token-list))

-- 
You only have power over people so long as you don’t take everything
away from them. But when you’ve robbed a man of everything he’s no longer
in your power — he’s free again. -- Aleksandr Isayevich Solzhenitsyn
From: Carl Taylor
Subject: Re: Read-from-string
Date: 
Message-ID: <U1T7l.253895$Mh5.6519@bgtnsc04-news.ops.worldnet.att.net>
Madhu wrote:
> * "Carl Taylor"
> <·······················@bgtnsc04-news.ops.worldnet.att.net> : Wrote
> on Sat, 03 Jan 2009 01:45:20 GMT:
>>
>> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>>   (loop with eos = (gensym)
>>           for token = (read s nil eos nil)
>>           if (eq token eos)
>>             do (return token-list)
>>           else
>>             collect token into token-list))
>>
>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
>
> You can avoid the gensym by passing the stream itself.  IIRC I
> spotted this technique first on CLL in an EN post.
>
> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>   (loop with *READ-EVAL* = NIL ;[1]
>         for token = (read stream nil stream)
>         if (eql token stream)
>             do (return token-list)
>         else
>             collect token into token-list))
>
> [1] I recommend getting into the compulsive habit of binding
>    *READ-EVAL* to NIL unless you have good reason to EVAL]


I don't understand the role of *read-eval* in this scenario.  The 
passing of the stream still works without the WITH clause and with 
*read-eval* equal to T.  Also EQ works as well here.

CL-USER 9 > *read-eval*
T

CL-USER 10 >

(with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
   (loop for token = (read stream nil stream)
         if (eql token stream)
             do (return token-list)
         else
             collect token into token-list))

(MOO GOO GAI PAN NIL FOO BAR BAZ)


Carl Taylor
From: Barry Margolin
Subject: Re: Read-from-string
Date: 
Message-ID: <barmar-7B29E2.19100103012009@mara100-84.onlink.net>
In article <·····················@bgtnsc04-news.ops.worldnet.att.net>,
 "Carl Taylor" <··········@att.net> wrote:

> Madhu wrote:
> > * "Carl Taylor"
> > <·······················@bgtnsc04-news.ops.worldnet.att.net> : Wrote
> > on Sat, 03 Jan 2009 01:45:20 GMT:
> >>
> >> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> >>   (loop with eos = (gensym)
> >>           for token = (read s nil eos nil)
> >>           if (eq token eos)
> >>             do (return token-list)
> >>           else
> >>             collect token into token-list))
> >>
> >> (MOO GOO GAI PAN NIL FOO BAR BAZ)
> >
> >
> > You can avoid the gensym by passing the stream itself.  IIRC I
> > spotted this technique first on CLL in an EN post.
> >
> > (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
> >   (loop with *READ-EVAL* = NIL ;[1]
> >         for token = (read stream nil stream)
> >         if (eql token stream)
> >             do (return token-list)
> >         else
> >             collect token into token-list))
> >
> > [1] I recommend getting into the compulsive habit of binding
> >    *READ-EVAL* to NIL unless you have good reason to EVAL]
> 
> 
> I don't understand the role of *read-eval* in this scenario.  The 
> passing of the stream still works without the WITH clause and with 
> *read-eval* equal to T.

It has nothing to do with passing of the stream as the eof-value.  It's 
just a general recommendation to prevent unexpected evaluation.  This is 
important if the string is received from an untrusted source, like a 
network client.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Pascal J. Bourguignon
Subject: Re: Read-from-string
Date: 
Message-ID: <87mye7dhun.fsf@informatimago.com>
"Carl Taylor" <··········@att.net> writes:

> Madhu wrote:
>> * "Carl Taylor"
>> <·······················@bgtnsc04-news.ops.worldnet.att.net> : Wrote
>> on Sat, 03 Jan 2009 01:45:20 GMT:
>>>
>>> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>>>   (loop with eos = (gensym)
>>>           for token = (read s nil eos nil)
>>>           if (eq token eos)
>>>             do (return token-list)
>>>           else
>>>             collect token into token-list))
>>>
>>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
>>
>>
>> You can avoid the gensym by passing the stream itself.  IIRC I
>> spotted this technique first on CLL in an EN post.
>>
>> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>>   (loop with *READ-EVAL* = NIL ;[1]
>>         for token = (read stream nil stream)
>>         if (eql token stream)
>>             do (return token-list)
>>         else
>>             collect token into token-list))
>>
>> [1] I recommend getting into the compulsive habit of binding
>>    *READ-EVAL* to NIL unless you have good reason to EVAL]
>
>
> I don't understand the role of *read-eval* in this scenario.  The 
> passing of the stream still works without the WITH clause and with 
> *read-eval* equal to T.  Also EQ works as well here.
>
> CL-USER 9 > *read-eval*
> T
>
> CL-USER 10 >
>
> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>    (loop for token = (read stream nil stream)
>          if (eql token stream)
>              do (return token-list)
>          else
>              collect token into token-list))
>
> (MOO GOO GAI PAN NIL FOO BAR BAZ)

Try that:

 (with-input-from-string (stream "MOO GOO #.(ext:shell \"format c:\") GAI PAN NIL FOO BAR BAZ")
    (loop for token = (read stream nil stream)
          if (eql token stream)
              do (return token-list)
          else
              collect token into token-list))


-- 
__Pascal Bourguignon__
From: ······@corporate-world.lisp.de
Subject: Re: Read-from-string
Date: 
Message-ID: <1d0e9acf-781a-4e7b-bc81-3695a7a2f44f@r15g2000prh.googlegroups.com>
On 4 Jan., 01:40, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> "Carl Taylor" <··········@att.net> writes:
> > Madhu wrote:
> >> * "Carl Taylor"
> >> <·······················@bgtnsc04-news.ops.worldnet.att.net> : Wrote
> >> on Sat, 03 Jan 2009 01:45:20 GMT:
>
> >>> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> >>>   (loop with eos = (gensym)
> >>>           for token = (read s nil eos nil)
> >>>           if (eq token eos)
> >>>             do (return token-list)
> >>>           else
> >>>             collect token into token-list))
>
> >>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
> >> You can avoid the gensym by passing the stream itself.  IIRC I
> >> spotted this technique first on CLL in an EN post.
>
> >> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
> >>   (loop with *READ-EVAL* = NIL ;[1]
> >>         for token = (read stream nil stream)
> >>         if (eql token stream)
> >>             do (return token-list)
> >>         else
> >>             collect token into token-list))
>
> >> [1] I recommend getting into the compulsive habit of binding
> >>    *READ-EVAL* to NIL unless you have good reason to EVAL]
>
> > I don't understand the role of *read-eval* in this scenario.  The
> > passing of the stream still works without the WITH clause and with
> > *read-eval* equal to T.  Also EQ works as well here.
>
> > CL-USER 9 > *read-eval*
> > T
>
> > CL-USER 10 >
>
> > (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
> >    (loop for token = (read stream nil stream)
> >          if (eql token stream)
> >              do (return token-list)
> >          else
> >              collect token into token-list))
>
> > (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
> Try that:
>
>  (with-input-from-string (stream "MOO GOO #.(ext:shell \"format c:\") GAI PAN NIL FOO BAR BAZ")
>     (loop for token = (read stream nil stream)
>           if (eql token stream)
>               do (return token-list)
>           else
>               collect token into token-list))
>
> --
> __Pascal Bourguignon__

I think I'll put you in my killfile for your nasty examples.
From: Raffael Cavallaro
Subject: Re: Read-from-string
Date: 
Message-ID: <2009010514275043658-raffaelcavallaro@pasespamsilvousplaitmaccom>
On 2009-01-05 12:11:37 -0500, ·······@corporate-world.lisp.de" 
<······@corporate-world.lisp.de> said:

> I think I'll put you in my killfile for your nasty examples.

You think he would have learned from the negative reactions the first 
time posted one of these nasties.


-- 
Raffael Cavallaro, Ph.D.
From: Pascal J. Bourguignon
Subject: Re: Read-from-string
Date: 
Message-ID: <87iqotbeke.fsf@informatimago.com>
Raffael Cavallaro <················@pas.espam.s.il.vous.plait.mac.com>
writes:

> On 2009-01-05 12:11:37 -0500, ·······@corporate-world.lisp.de"
> <······@corporate-world.lisp.de> said:
>
>> I think I'll put you in my killfile for your nasty examples.
>
> You think he would have learned from the negative reactions the first
> time posted one of these nasties.

I've been told  FORMAT C:\  doesn't do anything nasty anymore, so it
just conveys the message without being really as dangerous as my lisp code.

-- 
__Pascal Bourguignon__
From: Carl Taylor
Subject: Re: Read-from-string
Date: 
Message-ID: <XLr8l.257660$Mh5.239467@bgtnsc04-news.ops.worldnet.att.net>
······@corporate-world.lisp.de wrote:
> On 4 Jan., 01:40, ····@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> "Carl Taylor" <··········@att.net> writes:
>>> Madhu wrote:
>>>> * "Carl Taylor"
>>>> <·······················@bgtnsc04-news.ops.worldnet.att.net> :
>>>> Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
>>
>>>>> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>>>>> (loop with eos = (gensym)
>>>>> for token = (read s nil eos nil)
>>>>> if (eq token eos)
>>>>> do (return token-list)
>>>>> else
>>>>> collect token into token-list))
>>
>>>>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
>>
>>>> You can avoid the gensym by passing the stream itself. IIRC I
>>>> spotted this technique first on CLL in an EN post.
>>
>>>> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>>>> (loop with *READ-EVAL* = NIL ;[1]
>>>> for token = (read stream nil stream)
>>>> if (eql token stream)
>>>> do (return token-list)
>>>> else
>>>> collect token into token-list))
>>
>>>> [1] I recommend getting into the compulsive habit of binding
>>>> *READ-EVAL* to NIL unless you have good reason to EVAL]
>>
>>> I don't understand the role of *read-eval* in this scenario. The
>>> passing of the stream still works without the WITH clause and with
>>> *read-eval* equal to T. Also EQ works as well here.
>>
>>> CL-USER 9 > *read-eval*
>>> T
>>
>>> CL-USER 10 >
>>
>>> (with-input-from-string (stream "MOO GOO GAI PAN NIL FOO BAR BAZ")
>>> (loop for token = (read stream nil stream)
>>> if (eql token stream)
>>> do (return token-list)
>>> else
>>> collect token into token-list))
>>
>>> (MOO GOO GAI PAN NIL FOO BAR BAZ)
>>
>> Try that:
>>
>> (with-input-from-string (stream "MOO GOO #.(ext:shell \"format c:\")
>> GAI PAN NIL FOO BAR BAZ") (loop for token = (read stream nil stream)
>> if (eql token stream)
>> do (return token-list)
>> else
>> collect token into token-list))
>>
>> --
>> __Pascal Bourguignon__
>
> I think I'll put you in my killfile for your nasty examples.

Nah, give the poor guy a break. I have a sneaking suspicion it's the 
only way he can achieve orgasm.

clt
From: John Thingstad
Subject: Re: Read-from-string
Date: 
Message-ID: <op.um7h51jout4oq5@pandora.alfanett.no>
P� Sat, 03 Jan 2009 15:18:23 +0100, skrev Madhu <·······@meer.net>:

>
> * "Carl Taylor"  
> <·······················@bgtnsc04-news.ops.worldnet.att.net> :
> Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
> |
> | (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> |   (loop with eos = (gensym)
> |           for token = (read s nil eos nil)
> |           if (eq token eos)
> |             do (return token-list)
> |           else
> |             collect token into token-list))
> |
> | (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
>

*read-eval* in this context is pointless. If you want it dsabled by  
default just set it so at the toplevel.

(setf *read-eval nil)

(with-input-from-string (stream "MOO GOO PAN NIL FOO BAR BAZ")
               (loop for token = (read stream nil stream)
                     until (eq token stream)
                     collect token))
(MOO GOO PAN NIL FOO BAR BAZ)

--------------
John Thingstad
From: D Herring
Subject: Re: Read-from-string
Date: 
Message-ID: <49602d2b$0$17068$6e1ede2f@read.cnntp.org>
John Thingstad wrote:
> P� Sat, 03 Jan 2009 15:18:23 +0100, skrev Madhu <·······@meer.net>:
> 
>>
>> * "Carl Taylor" 
>> <·······················@bgtnsc04-news.ops.worldnet.att.net> :
>> Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
>> |
>> | (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>> |   (loop with eos = (gensym)
>> |           for token = (read s nil eos nil)
>> |           if (eq token eos)
>> |             do (return token-list)
>> |           else
>> |             collect token into token-list))
>> |
>> | (MOO GOO GAI PAN NIL FOO BAR BAZ)
>>
>>
> 
> *read-eval* in this context is pointless. If you want it dsabled by 
> default just set it so at the toplevel.
> 
> (setf *read-eval* nil)

People generally want *read-eval* true; its bad when #-feature bombs 
while loading a package.  OTOH, when you're reading untrusted data...

- Daniel
From: Rob Warnock
Subject: Re: Read-from-string
Date: 
Message-ID: <9aOdnQDKtehroP3UnZ2dnUVZ_sninZ2d@speakeasy.net>
D Herring  <········@at.tentpost.dot.com> wrote:
+---------------
| John Thingstad wrote:
| > *read-eval* in this context is pointless. If you want it dsabled by 
| > default just set it so at the toplevel.
| > (setf *read-eval* nil)
| 
| People generally want *read-eval* true; its bad when #-feature bombs 
| while loading a package.
+---------------

You're confused. *READ-EVAL* affects *only* the "#." readmacro,
not "#+" or "#-".

Were you perhaps mistaking it for *READ-SUPPRESS*? Even there,
most readmacros are still parsed and dispatched to their defining
functions, with the exception only of "#n#" and "#n=". In particular,
sub-expressions containing "#+" and "#-" are still parsed properly.


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: D Herring
Subject: Re: Read-from-string
Date: 
Message-ID: <49603ec4$0$17066$6e1ede2f@read.cnntp.org>
Rob Warnock wrote:
> D Herring  <········@at.tentpost.dot.com> wrote:
> +---------------
> | John Thingstad wrote:
> | > *read-eval* in this context is pointless. If you want it dsabled by 
> | > default just set it so at the toplevel.
> | > (setf *read-eval* nil)
> | 
> | People generally want *read-eval* true; its bad when #-feature bombs 
> | while loading a package.
> +---------------
> 
> You're confused. *READ-EVAL* affects *only* the "#." readmacro,
> not "#+" or "#-".

You're right.  I was thinking of another set of read macros.  My bad.

- Daniel
From: Pascal J. Bourguignon
Subject: Re: Read-from-string
Date: 
Message-ID: <87iqovdhqd.fsf@informatimago.com>
"John Thingstad" <·······@online.no> writes:

> P� Sat, 03 Jan 2009 15:18:23 +0100, skrev Madhu <·······@meer.net>:
>
>>
>> * "Carl Taylor"
>> <·······················@bgtnsc04-news.ops.worldnet.att.net> :
>> Wrote on Sat, 03 Jan 2009 01:45:20 GMT:
>> |
>> | (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>> |   (loop with eos = (gensym)
>> |           for token = (read s nil eos nil)
>> |           if (eq token eos)
>> |             do (return token-list)
>> |           else
>> |             collect token into token-list))
>> |
>> | (MOO GOO GAI PAN NIL FOO BAR BAZ)
>>
>>
>
> *read-eval* in this context is pointless. If you want it dsabled by
> default just set it so at the toplevel.
>
> (setf *read-eval nil)
>
> (with-input-from-string (stream "MOO GOO PAN NIL FOO BAR BAZ")
>               (loop for token = (read stream nil stream)
>                     until (eq token stream)
>                     collect token))
> (MOO GOO PAN NIL FOO BAR BAZ)


It is good to reset it globally, but it is much better to reset it
lexically everwhere you read random data.

-- 
__Pascal Bourguignon__
From: William James
Subject: Re: Read-from-string
Date: 
Message-ID: <gnt02r0fn7@enews5.newsguy.com>
Carl Taylor wrote:

> 
> "Pascal J. Bourguignon" <···@informatimago.com> wrote in message ···················@informatimago.com...
> >"Carl Taylor" <··········@att.net> writes:
> > 
> > (let ((data  "lala tata bobo dada nil qwerty moo goo"))
> > (with-input-from-string (s data)
> >    (loop for token = (read s nil nil nil)
> >            while token
> >                collect token)))
> >-> (LALA TATA BOBO DADA)
> > 
> 
> 
> CL-USER 17 >
> 
> (with-input-from-string (s "moo goo gai pan nil foo bar baz")
>  (loop with eos = (gensym)
>          for token = (read s nil eos nil)
>          if (eq token eos)
>            do (return token-list)
>          else
>            collect token into token-list))
> 
> (MOO GOO GAI PAN NIL FOO BAR BAZ)
> 
> clt

Clojure:

(map #(symbol %) (.split "moo goo gai pan nil foo bar baz" " "))
From: Marco Antoniotti
Subject: Re: Read-from-string
Date: 
Message-ID: <3dbe4275-ac50-447e-bd1e-75bd7f3a4f0b@p13g2000yqc.googlegroups.com>
On Feb 23, 3:02 am, "William James" <·········@yahoo.com> wrote:
> Carl Taylor wrote:
>
> > "Pascal J. Bourguignon" <····@informatimago.com> wrote in ··························@informatimago.com...
> > >"Carl Taylor" <··········@att.net> writes:
>
> > > (let ((data  "lala tata bobo dada nil qwerty moo goo"))
> > > (with-input-from-string (s data)
> > >    (loop for token = (read s nil nil nil)
> > >            while token
> > >                collect token)))
> > >-> (LALA TATA BOBO DADA)
>
> > CL-USER 17 >
>
> > (with-input-from-string (s "moo goo gai pan nil foo bar baz")
> >  (loop with eos = (gensym)
> >          for token = (read s nil eos nil)
> >          if (eq token eos)
> >            do (return token-list)
> >          else
> >            collect token into token-list))
>
> > (MOO GOO GAI PAN NIL FOO BAR BAZ)
>
> > clt
>
> Clojure:
>
> (map #(symbol %) (.split "moo goo gai pan nil foo bar baz" " "))

That ain't Ruby.  Beside....

(mapcar 'intern (split-sequence #\Space "moo goo gai pan nil foo bar
baz" " "))


Cheers
--
Marco
From: =?UTF-8?B?QW5kcsOpIFRoaWVtZQ==?=
Subject: Re: Read-from-string
Date: 
Message-ID: <gnub7b$jep$1@news.motzarella.org>
William James schrieb:
> Carl Taylor wrote:

> Clojure:
> 
> (map #(symbol %) (.split "moo goo gai pan nil foo bar baz" " "))

(map symbol (.split "moo goo gai pan nil foo bar baz" " "))


André
-- 
Lisp is not dead. It’s just the URL that has changed:
http://clojure.org/