[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: different LOOP results

William James

6/7/2015 8:31:00 PM

Dr. Edmund Weitz wrote:

> The following input
>
> (loop for x in '(1 2 3 4)
> for y upfrom 0
> collect x into temp
> when (oddp y)
> collect temp
> and do (print temp)
> (setq temp nil))
>
> results in
>
> (1 2)
> (3 4)
> ((1 2) (3 4))
>
> with CLISP and LispWorks - which is what I expected. But CMUCL shows
>
> (1 2)
> (1 2 3 4)
> ((1 2 3 4) (1 2 3 4))
>
> instead. Is this a bug or are both behaviors conforming?

In "ANSI Common Lisp", Graham makes the following comments:

The loop macro was originally designed to help inexperienced
Lisp users write iterative code. Instead of writing Lisp code,
you express your program in a form meant to resemble English,
and this is then translated into Lisp. Unfortunately, loop is
more like English than its designers ever intended: you can
use it in simple cases without quite understanding how it
works, but to understand it in the abstract is almost
impossible.
....
the ANSI standard does not really give a formal specification
of its behavior.
....
The first thing one notices about the loop macro is that it
has syntax. A loop expression contains not subexpressions but
clauses. The clauses are not delimited by parentheses;
instead, each kind has a distinct syntax. In that, loop
resembles traditional Algol-like languages. But the other
distinctive feature of loop, which makes it as unlike Algol as
Lisp, is that the order in which things happen is only
loosely related to the order in which the clauses occur.
....
For such reasons, the use of loop cannot be recommended.

--
[Jesse Jackson] would spit into the food of white patrons he hated and then
smilingly serve it to them. He did this, he said, "because it gave me
psychological gratification." -- Life Magazine, 1969-11-29