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/
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"]
·········@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?
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
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
"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__
"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
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]
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
* "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
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
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
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
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 ***
"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__
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.
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.
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__
······@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
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
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
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
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
"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__
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/