Re: strange behaviour in loop

Steven Majewski <[email protected]> Wed, 24 Apr 2002 12:22:14 -0400 (EDT)
Newsgroups gmane.lisp.statistics
Message-ID <Pine.OSX.4.43.0204241205360.849-100000@d-128-61-180.bootp.Virginia.EDU>
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