LOOP maximize with type to return bogus values.

Bug #1618518 reported by Andrzej Walczak
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
Invalid
Undecided
Unassigned

Bug Description

The LOOP maximize function behaves different if typed with fixnum or integer.

(loop for node in nil maximize 42)
=>
0

(loop for node in nil maximize 42 of-type fixnum)
=>
-4611686018427387904

.................

("Linux" "3.13.0-88-generic"
 "X86-64" "Intel(R) Xeon(R) CPU E5-1650 0 @ 3.20GHz"
 "SBCL" "1.3.5.7-890140a")

Tags: loop
Revision history for this message
Jan Moringen (scymtym) wrote :

I think SBCL's behavior is conforming. CLHS 6.1.3 "Value Accumulation Clauses" says

The maximize and minimize constructs compare the value of the supplied form obtained during the first iteration with values obtained in successive iterations. The maximum (for maximize) or minimum (for minimize) value encountered is determined (as if by the function max for maximize and as if by
the function min for minimize) and returned. If the maximize or minimize clause is never executed, the accumulated value is unspecified.

Revision history for this message
Andrzej Walczak (andrzejwalczak) wrote :

I agree, there is the standard and there is the surprise.
As in: changed program semantics by adding a declaration which the compiler is allowed to ignore.

Since the identity elements for infimum/supremum are +inf/-inf generally,
we have a hole in the standard - mainly because the +inf/-inf values are not well defined in it.

The next best value to settle on would be 0.

tags: added: loop
Revision history for this message
Stas Boukarev (stassats) wrote :

I don't see any problem with returning most-negative-fixnum, just don't depend on undefined behavior.

Changed in sbcl:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.