Steel Bank Common Lisp

(loop sum 2 count 1 repeat 3) => expansion error

Reported by Anton Kovalenko on 2011-06-16
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Low
Unassigned

Bug Description

(loop sum 2 count 1 repeat 3)

[...first, just a warning, it may be ok...]
WARNING: unequal datatypes specified in different LOOP value accumulations
into NIL: FIXNUM and NUMBER
current LOOP context: COUNT 1 REPEAT.

[...but after that, expansion fails...]
The specified data type NUMBER is not a subtype of REAL.
current LOOP context: COUNT 1 REPEAT.
(signalled by LOOP-CHECK-DATA-TYPE called by LOOP-SUM-COLLECTION)

After reordering sum and count clauses, loop is expanded successfully:
(loop count 1 sum 2 repeat 3)

Notes:
1. Per CLHS 6.1.3 mixing sum, count, min and max is allowed.

2. Signalling a type-related error at macro-expansion time is obviously _bad_ when it's not the error of macro-function evaluation, but rather a result of some clever type checking. The whole loop form could be dead code, after all -- then it would be a conforming program, and I'd expect it to compile successfully.

3. Instead of examining subtype relations during loop body expansion, it would be both safer and easier to combine all type requirements for each collector with '(AND). The final result may be checked, if necessary, for being a subtype of NIL (i.e. the impossible, empty-domain type). SBCL is usually able to detect such type relations, e.g.: (SUBTYPEP '(AND FIXNUM CONS) NIL) => T T.

Changed in sbcl:
importance: Undecided → Low
status: New → Triaged
tags: added: loop
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers