LOOP destructuring and multiple values 
Author Message
 LOOP destructuring and multiple values

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?



Fri, 19 Apr 2002 03:00:00 GMT  
 LOOP destructuring and multiple values


Quote:
>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))
     ...)

--

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.



Fri, 19 Apr 2002 03:00:00 GMT  
 LOOP destructuring and multiple values

Quote:



> >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



Sat, 20 Apr 2002 03:00:00 GMT  
 LOOP destructuring and multiple values

Quote:

> 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



Sat, 20 Apr 2002 03:00:00 GMT  
 LOOP destructuring and multiple values


Quote:

> > 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.

  loop.cl
6K Download

--

  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]



Sat, 20 Apr 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Destructuring / pattern-matching (was: Multiple return values)

2. Destructuring / pattern-matching (was: Multiple return values)

3. LOOP and destructuring

4. changing the value of loop-control variable in loop

5. Loop variable value after loop finish

6. display values while looping through a for loop

7. (values (multiple-value-form)) whats the point?

8. Multiple-value-list with no values.

9. multiple exit points in a loop?

10. use of global variable with multiple state machines and loops

11. DO..WHILE ..LOOP (was: Detecting Multiple Events )

12. How Can I Stop multiple while loops using subVI

 

 
Powered by phpBB® Forum Software