From: Christopher N Toomey
Subject: Loop Macro Type Declarations
Date: 
Message-ID: <1991Jul11.183632.2862@neon.Stanford.EDU>
I've run into a problem with the automatic LOOP type declarations and I hope
that you can suggest a workaround.

I'm doing a simple iteration loop of the form
	(loop for b from start to end by step do ...),
and each of my loop variables (b, start, end, step) are BIGNUMs (universal
times).

The problem is that in the loop expansion, all of these variables are declared
to be FIXNUMs.  Thus, arithmetic functions in the body such as ">" will work
incorrectly in compiled code.  Although I can declare "b" to be of type
INTEGER, I'm not aware of any way to declare the others to be of type INTEGER,
nor to tell loop not to declare them as any type.

Is there some I've missed to have my loop construct work with BIGNUMs?  

Thanks,
Chris

P.S. I'm using the "officially sanctioned" version of LOOP from MIT as
supplied with MacIntosh Common Lisp v. 2.0.

From: Barry Margolin
Subject: Re: Loop Macro Type Declarations
Date: 
Message-ID: <1991Jul12.045853.794@Think.COM>
In article <·····················@neon.Stanford.EDU> ······@neon.Stanford.EDU (Christopher N Toomey) writes:
>I'm doing a simple iteration loop of the form
>	(loop for b from start to end by step do ...),
>and each of my loop variables (b, start, end, step) are BIGNUMs (universal
>times).
>
>The problem is that in the loop expansion, all of these variables are declared
>to be FIXNUMs.  

That seems like a bug in your version of LOOP.  I don't have my CLtL2 handy
at the moment, but I believe from-to-by iteration only requires that the
parameters be real numbers (so that < or > can be used in the end test).
Automatic FIXNUM declarations are an unwarranted assumption.

>		 Thus, arithmetic functions in the body such as ">" will work
>incorrectly in compiled code.  Although I can declare "b" to be of type
>INTEGER, I'm not aware of any way to declare the others to be of type INTEGER,
>nor to tell loop not to declare them as any type.

I don't know whether it will help, but the way to declare the others is to
use THE:

(loop for b of-type integer from (the integer start)
			    to (the integer end)
			    by (the integer step) ...)

If that doesn't help, you could use a different iteration preposition,
e.g.:

(loop for b first start then (+ b step) while (<= b end) do ...)

>P.S. I'm using the "officially sanctioned" version of LOOP from MIT as
>supplied with MacIntosh Common Lisp v. 2.0.

I guess the official sanctioners screwed up....
-- 
Barry Margolin, Thinking Machines Corp.

······@think.com
{uunet,harvard}!think!barmar
From: Chris Toomey
Subject: Re: Loop Macro Type Declarations
Date: 
Message-ID: <1015@laic.rdd.lmsc.lockheed.com>
In article <····················@Think.COM> ······@think.com writes:
>
>That seems like a bug in your version of LOOP.  I don't have my CLtL2 handy
>at the moment, but I believe from-to-by iteration only requires that the
>parameters be real numbers (so that < or > can be used in the end test).
>Automatic FIXNUM declarations are an unwarranted assumption.
>

I agree.  In fact, it looks like that assumption has been removed in a
subsequent version of the LOOP implementation which was provided with Allegro
Common Lisp v. 4.0.1. (it declares untype-specified variables to be of type T
rather than FIXNUM).

>
>I don't know whether it will help, but the way to declare the others is to
>use THE:
>
>(loop for b of-type integer from (the integer start)
>			    to (the integer end)
>			    by (the integer step) ...)
>

This won't solve the problem as the macro expansion would then become
something like:

	((LAMBDA (B LOOP-BIND-132 LOOP-STEP-BY-132)
	   (DECLARE (TYPE FIXNUM LOOP-STEP-BY-132)
		    (TYPE FIXNUM LOOP-BIND-132)
		    (TYPE FIXNUM B))
	   (BLOCK NIL
	     (LET ()
	       (TAGBODY
		LOOP::NEXT-LOOP (WHEN (> B LOOP-BIND-132) (GO LOOP::END-LOOP))
			(PRINT B)
			(SETQ B (+ B LOOP-STEP-BY-132))
			(GO LOOP::NEXT-LOOP)
			(GO LOOP::END-LOOP)
		LOOP::END-LOOP))))
	 (THE INTEGER START) (THE INTEGER END) (THE INTEGER STEP))
		
which would lead to type-conflict errors.

The underlying trouble with LOOP at this point is that most implementations
predate CLtL2 and thus don't conform to a standard specification (and are
prone to taking dangerous liberties such as the FIXNUM declarations).