[iterate-devel] type declarations from the Iterate package

Hoehle, Joerg-Cyril Joerg-Cyril.Hoehle at t-systems.com
Tue Mar 29 08:58:13 UTC 2005


Hi,

Marc Battyani wrote:
[Thanks for your feedback]
>> I was wondering (given zero e-mail traffic on this subject here) if
>>somebody had noticed that Iterate outputs quite dubious type declarations

>when being asked for them (i.e. (declare (iterate:declare-variables)))?
>I used it a few times. The (declare (iterate:declare-variables)).
> IIRC it worked for me.

I always tend to express myself too generally :-(

For *some* constructs, Iterate outputs wrong type declarations. It depends on a) the construct and b) the implementation (more precisely the results of TYPE-OF).

E.g. in CLISP, (type-of 0) -> BIT and
(macroexpand-1'(iter:iter(declare(iter:declare-variables))(iter:repeat 0)))
reveals (LET* ((#:COUNT3 0)) (DECLARE (TYPE BIT #:COUNT3)) ...)
whose type is evidently broken.

Obviously the code was written with (type-of 0) -> FIXNUM in mind.


Widening that topic, I'm wondering whether generally, even the implementation's LOOP or other iteration constructs always produce correct declarations in border cases.
E.g. suppose array-dimension-limit = most-positive-fixnum

Loop code traversing a vector could possibly be written like:
 (declare (fixnum running-var)) ; because array-dimension fits a fixnum
 (incf running-var step) ; might escape fixnum limit
 (when (> running-var limit) (loop-finish))
but not like this
 (let ((var (+ running-var step))) ; no type declaration for var,
                                   ; could be a bignum after last iteration
   (if (> var limit) (loop-finish))
       (setq running-var var))     ; in this case var is not too large

Similarly, consider
(dotimes (i most-positive-fixnum) (declare (fixnum i)) ...)
Within the user-visible body, the type declaration holds. Yet dotimes could be implemented using (incf i) (when (> i #:limit) ...), thereby breaking the type declaration.

Is that just academic and I'm worrying too much?

Regards,
	Jörg Höhle.



More information about the iterate-devel mailing list