Re: strange behaviour in loop
Frederic Udina <[email protected]> Wed, 24 Apr 2002 19:11:29 +0200 (MET DST)
| Newsgroups | gmane.lisp.statistics |
|---|---|
| Message-ID | <[email protected]> |
OK, thanks for your time on it.
I agree with your observations.
On Wed, 24 Apr 2002, Steven Majewski wrote:
~~~
~~~On Wed, 24 Apr 2002, Frederic Udina wrote:
~~~
~~~> I observed that loop has a strange behaviour:
~~~...
~~~> > (loop foo foo (incf ii) foo (when (> ii 10000) (return)))
~~~> NIL
~~~>
~~~> doesnt give any error despite foo isn't bound to anything
~~~...
~~~> Why is that? Is it a bug or is something I do not know about loop?
~~~
~~~Loop is supposed to evaluate each form, however in xlcont.c/xloop I
~~~see the code fragment:
~~~
~~~ for (argv = xlargv, argc = xlargc; ; xlargv = argv, xlargc = argc) {
~~~ while (moreargs()) {
~~~ arg = nextarg();
~~~ if (consp(arg)) ## <-- !
~~~ xleval(arg);
~~~ }
~~~
~~~So it loops like it only evals conses.
~~~
~~~Thank looks like a bug.
~~~
~~~However, other than your expected error message, is there any other
~~~effect that you could expect from merely evaluating a symbol in that
~~~position ? I guess you COULD look at it as a 'feature' of the
~~~optimization of omitting NO-OPs.
~~~
~~~Bug or feature ?
~~~
~~~I think I'ld still vote bug: mainly because that allows it to accept
~~~the syntax for the more complex Common Lisp extended LOOP macro
~~~without either an error message or correct evaluation:
~~~
~~~> ( loop for i from 1 to 10 (print 1) (return))
~~~
~~~1
~~~NIL
~~~>
~~~
~~~
~~~-- Steve
~~~
~~~
Frederic Udina
____________________________________________________________________
<[email protected]> Dept. D'Economia i Empresa Universitat Pompeu Fabra
Ramon Trias Fargas, 25-27 08005 Barcelona SPAIN
tel. 34- 935421756/1763 fax: 34- 935421746 http://libiya.upf.es/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are many here among us who feel that life is but a joke B.Dy.