Is there some well-known (or not so well known) idiom for receiving
multiple values (as you would with a multiple-value-bind) in a `for'
clause of an invocation of the loop macro?
Cheers,
--ag
--
Artie Gold -- Austin, Texas
Artie Gold wrote:
> Is there some well-known (or not so well known) idiom for receiving
> multiple values (as you would with a multiple-value-bind) in a `for'
> clause of an invocation of the loop macro?
(loop for (a b c) = (multiple-value-list (foo))
...)
If your loop macro implementation is really good, it could do this with
multiple-value-bind or multiple-value-setq.
Paul
Paul F. Dietz wrote:
> Artie Gold wrote:
>
>> Is there some well-known (or not so well known) idiom for receiving
>> multiple values (as you would with a multiple-value-bind) in a `for'
>> clause of an invocation of the loop macro?
>
>
> (loop for (a b c) = (multiple-value-list (foo))
> ...)
>
> If your loop macro implementation is really good, it could do this with
> multiple-value-bind or multiple-value-setq.
>
Please allow me to yell:
THANKS! ;-)
--ag
--
Artie Gold -- Austin, Texas
On Sat, 15 May 2004 14:56:21 -0500, Artie Gold <·········@austin.rr.com> wrote:
> Is there some well-known (or not so well known) idiom for receiving
> multiple values (as you would with a multiple-value-bind) in a `for'
> clause of an invocation of the loop macro?
Not that I know of. But see this thread
<http://www.google.com/groups?threadm=87y8tfc5v9.fsf%40bird.agharta.de>
for some food for thought.
Edi
On Sat, 15 May 2004 22:48:27 +0200, I wrote:
> Not that I know of.
By that I meant that I don't know of an /efficient/ one - one that
doesn't cons. However I do (thanks to Carl Shapiro):
<http://www.google.com/groups?selm=ouy4qrrm6zr.fsf%40panix3.panix.com&output=gplain>
(Note to self: Do something about your memory...)
Cheers,
Edi.
Edi Weitz wrote:
> By that I meant that I don't know of an /efficient/ one - one that
> doesn't cons. However I do (thanks to Carl Shapiro):
>
> <http://www.google.com/groups?selm=ouy4qrrm6zr.fsf%40panix3.panix.com&output=gplain>
>
> (Note to self: Do something about your memory...)
Use of the multiple-value-list scheme may not use much memory:
(1) If the LOOP macro recognizes the idiom, it may be able to
convert it to multiple-value-bind or multiple-value-setq (or
some internal thing.)
(2) Even if it can't, if the consing of m-v-l occurs inline,
then the compiler may be able to determine that all those
cons cells have dynamic extent, and then stack allocate them,
and then possibly optimize them away completely.
I don't know if any compiler does (2).
Paul
"Paul F. Dietz" <·····@dls.net> writes:
> Use of the multiple-value-list scheme may not use much memory:
In practice, no compiler I have ever used has had the wherewithal to
demodulate list destructurings of lists from values forms into a
straight-away values bindings.
Moreover, writing code this way is truly an exercise in bad style. I
consider it to be a transgression similar to outputting data with
printf() for the sole purpose of immediately reading the data back in
using the input format conversions of scanf(). Yuck.
If you have the good fortune of using a Lisp with an extensible LOOP
implementation you may be empowered to write a LOOP iteration path
which will perform values bindings under a familiar surface syntax.
Carl Shapiro wrote:
> "Paul F. Dietz" <·····@dls.net> writes:
>
>
>>Use of the multiple-value-list scheme may not use much memory:
>
>
> In practice, no compiler I have ever used has had the wherewithal to
> demodulate list destructurings of lists from values forms into a
> straight-away values bindings.
>
> Moreover, writing code this way is truly an exercise in bad style. I
> consider it to be a transgression similar to outputting data with
> printf() for the sole purpose of immediately reading the data back in
> using the input format conversions of scanf(). Yuck.
>
> If you have the good fortune of using a Lisp with an extensible LOOP
> implementation you may be empowered to write a LOOP iteration path
> which will perform values bindings under a familiar surface syntax.
So in extrapolating from this discussion, it seems like (as I *really*
need to keep things as implementation neutral as possible at the moment)
the `multiple-value-setq' idea is the Way To Go.
Do I have this right?
Many thanks,
--ag
--
Artie Gold -- Austin, Texas
Artie Gold <·········@austin.rr.com> writes:
> So in extrapolating from this discussion, it seems like (as I *really*
> need to keep things as implementation neutral as possible at the
> moment) the `multiple-value-setq' idea is the Way To Go.
>
> Do I have this right?
If you consider non-CONSing values bindings important and do not mind
looking at the side-effect generating MULTIPLE-VALUE-SETQ call, then I
think it is the only way to go. Otherwise, using list destructuring
with MULTIPLE-VALUE-LIST is the logical alternative.
Carl Shapiro wrote:
> Artie Gold <·········@austin.rr.com> writes:
>
>
>>So in extrapolating from this discussion, it seems like (as I *really*
>>need to keep things as implementation neutral as possible at the
>>moment) the `multiple-value-setq' idea is the Way To Go.
>>
>>Do I have this right?
>
>
> If you consider non-CONSing values bindings important and do not mind
> looking at the side-effect generating MULTIPLE-VALUE-SETQ call, then I
> think it is the only way to go. Otherwise, using list destructuring
> with MULTIPLE-VALUE-LIST is the logical alternative.
I deeply appreciate your assistance.
--ag
--
Artie Gold -- Austin, Texas
Edi Weitz <···@agharta.de> writes:
> (Note to self: Do something about your memory...)
If you find a way to improve your personal memory, please share it. I
hate mine, but the manufacturer refuses to do anything about it.
--
I wouldn't mind the rat race so much if it wasn't for all the damn cats.
"Edi Weitz" <···@agharta.de> wrote
>
> By that I meant that I don't know of an /efficient/ one - one that
> doesn't cons. However I do (thanks to Carl Shapiro):
>
>
<http://www.google.com/groups?selm=ouy4qrrm6zr.fsf%40panix3.panix.com&output
=gplain>
From this post:
(loop with v1 and v2 and v3
...
for nil = (multiple-value-setq (v1 v2 v3) form)
...
This kind of hack shows the limitations of loop. I am (or was) a loop fan
but, because of the fuzzyness of the standard and the fact that at least one
implementation has a different interpretation of that standard, I'm
switching to iterate in cl-pdf and cl-typesetting (and in my other stuff as
well)
Iterate is a more lispy superset of loop. For instance you can do this:
(iter
(for a from 10 to 20)
(for (values q r) = (truncate a 3))
(format t "~d ~d~%" q r))
3 1
3 2
4 0
4 1
4 2
5 0
5 1
5 2
6 0
6 1
6 2
nil
Now that Andreas Fuchs has taken the time to clean up iterate and is
maintaining it, it is a worthwhile alternative to loop.
Marc
Marc Battyani wrote:
> "Edi Weitz" <···@agharta.de> wrote
>>
>> By that I meant that I don't know of an /efficient/ one - one that
>> doesn't cons. However I do (thanks to Carl Shapiro):
>>
>>
>
<http://www.google.com/groups?selm=ouy4qrrm6zr.fsf%40panix3.panix.com&output
> =gplain>
>
> From this post:
>
> (loop with v1 and v2 and v3
> ...
> for nil = (multiple-value-setq (v1 v2 v3) form)
> ...
Why the for?
It seems to me that replacing "for nil =" with "do" would give the same
effect and confuse fewer people. Yes, it could be improved, but no, it
doesn't strike me as a creeping horror.
On Sun, 16 May 2004 17:14:30 +0200, Svein Ove Aas <··············@brage.info> wrote:
>> (loop with v1 and v2 and v3
>> ...
>> for nil = (multiple-value-setq (v1 v2 v3) form)
>> ...
>
> Why the for?
> It seems to me that replacing "for nil =" with "do" would give the
> same effect and confuse fewer people. Yes, it could be improved, but
> no, it doesn't strike me as a creeping horror.
With FOR it's a "variable clause," with DO it's a "main clause"
(following the nomenclature from the CLHS dictionary entry for
LOOP). A variable clause can be followed by other variable clauses, a
main clause can't. (Some Lisps will allow that but it's not portable.)
Edi.