Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: Loopy LOOP Date: Sun, 1 Sep 2024 07:09:51 -0000 (UTC) Organization: A noiseless patient Spider Lines: 72 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Sun, 01 Sep 2024 09:09:52 +0200 (CEST) Injection-Info: dont-email.me; posting-host="7e907f5110a71d53531627f1039d0356"; logging-data="1498601"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/JeHe6dmycv/FvAcFQ7mUQ" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:N6Kt7qgIu57wnj4gbAzJ4iRvLnE= Bytes: 3673 P. Seibel wrote: > Pascal Bourguignon writes: > > > Peter Seibel writes: > > > >> Pascal Bourguignon writes: > >> > >> > rpw3@rpw3.org (Rob Warnock) writes: > >> >> > (loop for i below 4 > >> >> for j below 4 > >> >> finally (return (list i j))) > >> >> > >> >> (4 3) > >> >> > > >> >> > >> >> Oh. Duh. > >> >> > >> >> LOOP is definitely one of the parts of CL where you learn something new > >> >> every day... ;-} ;-} > >> > > >> > Actually, the variables i and j could very well not be available in > >> > the finally clause. > >> > >> How do you figure that? Why would the finally clause be any different > >> from any of the other clauses? > >> > >> > Note how clisp returns a conforming but differnet result too: > >> > > >> > [193]> (loop for i below 4 > >> > for j below 4 > >> > finally (return (list i j))) > >> > (4 4) > >> > >> Hmmm. I'm not sure I buy that that's conforming. Given that LOOP > >> provides AND for specifying parallel stepping, why should CLISP's > >> behavior here be considered correct? > > > > Because the loop variables don't have to be available in the finally > > clause! If they're available, their value is unspecified. > > And why do you say they don't have to be available in the finally > clause? Granted I can't see anything in the spec that *specifically* > says they have to be but I can't see anything that specifically says > they have to available *anywhere*. Why should the finally clause be > any different from any other LOOP clause? In "ANSI Common Lisp", Paul Graham writes: 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.