(loop for (string eofp) = (read-line stream)
...
Is there any way to do something like this with the Common Lisp LOOP
macro? Are there any specific LOOP implementations that could be
extended to do such a thing?
(loop for (string eofp) = (values-list (read-line stream)) ...)
(loop with string eofp
do (multiple-value-setq (string eofp) (read-line stream))
...)
--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, 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.
> In article <ouywvs2...@panix6.panix.com>,
> Carl Shapiro <sam...@panix.com> wrote:
> >Within a LOOP expression I would like to use something similar to its
> >destructuring capabilities to handle functions that return multiple
> >values. For example:
> >
> > (loop for (string eofp) = (read-line stream)
> > ...
> >
> >Is there any way to do something like this with the Common Lisp LOOP
> >macro? Are there any specific LOOP implementations that could be
> >extended to do such a thing?
>
> (loop for (string eofp) = (values-list (read-line stream)) ...)
>
> (loop with string eofp
> do (multiple-value-setq (string eofp) (read-line stream))
> ...)
Just a couple weeks ago I had to do this exact same thing. I went
with:
(loop with eofp
for string = (multiple-value-setq (string eofp)
(read-line stream nil nil))
while string
do ...
until eofp)
Originally I went with your first version (you got VALUES-LIST mixed
up with MULTIPLE-VALUE-LIST, which does the exact opposite), except
this conses up a list only to immediately destructure it and was thus
unacceptable. I prefer to do bindings in FOR clauses, but I guess your
second way is probably the best overall. There really should be a
succinct _and_ efficient way to do this....
Christopher
> Within a LOOP expression I would like to use something similar to its
> destructuring capabilities to handle functions that return multiple
> values. For example:
>
> (loop for (string eofp) = (read-line stream)
> ...
>
> Is there any way to do something like this with the Common Lisp LOOP
> macro? Are there any specific LOOP implementations that could be
> extended to do such a thing?
Yes. In Allegro CL's "src/" subdirectory, as well as in the CMU
sources, you will find the source code to LOOP. You'll want to check
out ADD-LOOP-PATH, DEFINE-LOOP-<blah>-PATH, etc. These are neither
simple nor intuitive to use, and I don't know where you can find
documentation for them.
Christopher
> Carl Shapiro <sam...@panix.com> writes:
>
> > Is there any way to do something like this with the Common Lisp LOOP
> > macro? Are there any specific LOOP implementations that could be
> > extended to do such a thing?
>
> Yes. In Allegro CL's "src/" subdirectory, as well as in the CMU
> sources, you will find the source code to LOOP. You'll want to check
> out ADD-LOOP-PATH, DEFINE-LOOP-<blah>-PATH, etc. These are neither
> simple nor intuitive to use, and I don't know where you can find
> documentation for them.
I once digged into MIT loop to implement some looping paths, and wrote
up a couple of sentences on what is what in MIT loop on the way. I've
appended the file, which also implements a couple of specialized looping
paths, below. Though the code won't work because the functionality it
is built atop is missing, the examples should give an idea about how to
write new paths.
Ignore the copyright bearing header for this file and use as you
wish. Have fun...
Regs, Pierre.