[Openmcl-devel] Loop in function that should fail with type error

Gary Byers gb at clozure.com
Thu Jul 9 18:15:13 PDT 2015


CLHS says that the function - "might signal a type-error" if one or more 
arguments is not a number.

The result of the subtraction in your example is ignored.  CCL sees no 
reason to perform the operation
in this case.

I'm a little surprised that CCL didn't perform the operation even when 
your code was compiled with
(optimize (safety 3)) in effect; I'm fairly sure that fairly recent 
versions did so, and there is some argument
for performing operations for the sole reason of detecting (possible) 
errors in that case.  If CLHS said that
"an error should be signaled (in safe code)", that argument would be 
stronger.

Given the terminology that's actually used, you can't count on an error 
being signaled even when SAFETY = 3,
though the practical benefits of doing the subtraction for no (other) 
reason might outweigh whatever is gained
by not doing it.  Those practical benefits include not having to write 
(or ask anyone to read) explanations like this
again.


On 07/09/2015 04:33 PM, Renzo Orsini wrote:
> The following (absurd) function:
>
> (defun wrong(l)
>     (if (eq nil l)
>         l
>        (- (car (cdr l)) (car l)))
>    (wrong (cdr l)))
>
> if called as in: (wrong ‘(10 5)) should terminate with an error due to the application of the operator “-“ to NIL (this for instance happen in SBCL). But when I try it in CCL it seems to enter in an infinite loop. Is this an error? Some effect of the compiler optimization?
>
> Should I open a ticket?
>
> Thanks,
>
> Renzo
>
>




More information about the Openmcl-devel mailing list