* Precedence of for clauses in cl-loop
@ 2018-09-06 18:33 Plamen Tanovski
2018-09-06 22:43 ` Noam Postavsky
0 siblings, 1 reply; 7+ messages in thread
From: Plamen Tanovski @ 2018-09-06 18:33 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
the CL info states:
If you include several ‘for’ clauses in a row, they are treated
sequentially (as if by ‘let*’ and ‘setq’).
but in this simple example
(cl-loop for y = x
for x in '(1 2)
for z in '(1 2))
the "for in" clauses are executed before the "for =" clause. Emacs is:
GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.16.7) of
2018-06-08
best regards
--
Plamen Tanovski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
2018-09-06 18:33 Precedence of for clauses in cl-loop Plamen Tanovski
@ 2018-09-06 22:43 ` Noam Postavsky
2018-09-07 7:08 ` Plamen Tanovski
0 siblings, 1 reply; 7+ messages in thread
From: Noam Postavsky @ 2018-09-06 22:43 UTC (permalink / raw)
To: Plamen Tanovski; +Cc: Help Gnu Emacs mailing list
On 6 September 2018 at 14:33, Plamen Tanovski <pgt@tanovski.de> wrote:
> in this simple example
>
> (cl-loop for y = x
> for x in '(1 2)
> for z in '(1 2))
>
>
> the "for in" clauses are executed before the "for =" clause.
I disagree. I invite you to prove me wrong.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
2018-09-06 22:43 ` Noam Postavsky
@ 2018-09-07 7:08 ` Plamen Tanovski
2018-09-07 11:16 ` Noam Postavsky
0 siblings, 1 reply; 7+ messages in thread
From: Plamen Tanovski @ 2018-09-07 7:08 UTC (permalink / raw)
To: help-gnu-emacs
Noam Postavsky <npostavs@gmail.com> writes:
> On 6 September 2018 at 14:33, Plamen Tanovski <pgt@tanovski.de> wrote:
>
>> in this simple example
>>
>> (cl-loop for y = x
>> for x in '(1 2)
>> for z in '(1 2))
>>
>>
>> the "for in" clauses are executed before the "for =" clause.
>
> I disagree. I invite you to prove me wrong.
simply edebug the loop shows the precedence, but below as example a loop
which gives error, beacuse the z part is executed before the y line:
(cl-loop
for x in (number-sequence 1 10)
for y = (1+ x)
for z in (elt (number-sequence 1 10) y))
--
Plamen Tanovski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
2018-09-07 7:08 ` Plamen Tanovski
@ 2018-09-07 11:16 ` Noam Postavsky
2018-09-07 12:35 ` Plamen Tanovski
0 siblings, 1 reply; 7+ messages in thread
From: Noam Postavsky @ 2018-09-07 11:16 UTC (permalink / raw)
To: Plamen Tanovski; +Cc: Help Gnu Emacs mailing list
On 7 September 2018 at 03:08, Plamen Tanovski <pgt@tanovski.de> wrote:
> gives error, beacuse the z part is executed before the y line:
>
> (cl-loop
> for x in (number-sequence 1 10)
> for y = (1+ x)
> for z in (elt (number-sequence 1 10) y))
This example also gives an error:
(cl-loop
for x in (number-sequence 1 10)
for z in (elt (number-sequence 1 10) (1+ x)))
because a `for VAR in LIST' clause evaluates LIST just once before the
loop starts.
The "treated sequentially" in the manual refers to the assignment of
VAR. For example, this gives an error:
(cl-loop
for y = (1+ x)
for x in (number-sequence 1 10))
And this does not:
(cl-loop
for x in (number-sequence 1 10)
for y = (1+ x))
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
2018-09-07 11:16 ` Noam Postavsky
@ 2018-09-07 12:35 ` Plamen Tanovski
2018-09-08 1:37 ` Noam Postavsky
[not found] ` <mailman.511.1536370625.1284.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Plamen Tanovski @ 2018-09-07 12:35 UTC (permalink / raw)
To: help-gnu-emacs
Noam Postavsky <npostavs@gmail.com> writes:
> On 7 September 2018 at 03:08, Plamen Tanovski <pgt@tanovski.de> wrote:
>> gives error, beacuse the z part is executed before the y line:
>>
>> (cl-loop
>> for x in (number-sequence 1 10)
>> for y = (1+ x)
>> for z in (elt (number-sequence 1 10) y))
>
> This example also gives an error:
>
> (cl-loop
> for x in (number-sequence 1 10)
> for z in (elt (number-sequence 1 10) (1+ x)))
>
> because a `for VAR in LIST' clause evaluates LIST just once before the
> loop starts.
But
(cl-loop
for x on (number-sequence 1 10)
for z in (elt (number-sequence 1 10) (car x)))
works fine, which means, x was assigned a value before the for z clause.
> The "treated sequentially" in the manual refers to the assignment of
> VAR.
That's what I don't understand. After a "for VAR in" clause VAR is not
assigned and available for the rest of the for clauses. Obviously "for in
(across, etc.)" behaves different than "for on" and other for clauses.
I've tested with SBCL and there seems to be the same issue.
best regards
--
Plamen Tanovski
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
2018-09-07 12:35 ` Plamen Tanovski
@ 2018-09-08 1:37 ` Noam Postavsky
[not found] ` <mailman.511.1536370625.1284.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 7+ messages in thread
From: Noam Postavsky @ 2018-09-08 1:37 UTC (permalink / raw)
To: Plamen Tanovski; +Cc: Help Gnu Emacs mailing list
On 7 September 2018 at 08:35, Plamen Tanovski <pgt@tanovski.de> wrote:
> (cl-loop
> for x on (number-sequence 1 10)
> for z in (elt (number-sequence 1 10) (car x)))
>
> works fine, which means, x was assigned a value before the for z clause.
Hmm, I wasn't aware of this, but it seems to be on purpose,
https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node239.html says:
All variables are initialized first, regardless of where the
establishing clauses appear in the source. The order of initialization
follows the order of these clauses.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Precedence of for clauses in cl-loop
[not found] ` <mailman.511.1536370625.1284.help-gnu-emacs@gnu.org>
@ 2018-09-08 14:41 ` Udyant Wig
0 siblings, 0 replies; 7+ messages in thread
From: Udyant Wig @ 2018-09-08 14:41 UTC (permalink / raw)
To: help-gnu-emacs
On 9/8/18 7:07 AM, Noam Postavsky wrote:
> Hmm, I wasn't aware of this, but it seems to be on purpose,
> https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node239.html says:
>
> All variables are initialized first, regardless of where the
> establishing clauses appear in the source. The order of initialization
> follows the order of these clauses.
>
Indeed. The Common Lisp Standard concurs:
<URL:http://www.lispworks.com/documentation/HyperSpec/Body/06_aaf.htm>
The phrasing is identical there.
Udyant Wig
--
We make our discoveries through our mistakes: we watch one another's
success: and where there is freedom to experiment there is hope to
improve.
-- Arthur Quiller-Couch
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-09-08 14:41 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-06 18:33 Precedence of for clauses in cl-loop Plamen Tanovski
2018-09-06 22:43 ` Noam Postavsky
2018-09-07 7:08 ` Plamen Tanovski
2018-09-07 11:16 ` Noam Postavsky
2018-09-07 12:35 ` Plamen Tanovski
2018-09-08 1:37 ` Noam Postavsky
[not found] ` <mailman.511.1536370625.1284.help-gnu-emacs@gnu.org>
2018-09-08 14:41 ` Udyant Wig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).