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

Ron Garret ron at flownet.com
Thu Jul 9 16:04:01 PDT 2015


It’s a compiler optimization.  This code:

>   (if (eq nil l) 
>       l 
>      (- (car (cdr l)) (car l)))

doesn’t change any state and the result is immediately discarded, so it’s dead code.

You can “fix” this by doing something with the value returned by that code snippet, e.g.:

(defun wrong(l)
    (setf *value* (if (eq nil l) 
                    l 
                    (- (car (cdr l)) (car l))))
    (wrong (cdr l)))

rg

On Jul 9, 2015, at 3:33 PM, Renzo Orsini <orsini at unive.it> 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
> 
> 
> -- 
> "Nota automatica aggiunta dal sistema di posta.
> Destina il 5 per mille per sostenere con borse di studio gli studenti 
> meritevoli di Ca' Foscari.
> E' un atto volontario, non costa nulla e non sostituisce l'8 per mille.
> Scegli Ca' Foscari: codice fiscale 80007720271
> Please note that the above message is addressed only to individuals filing 
> Italian income tax returns."
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> https://lists.clozure.com/mailman/listinfo/openmcl-devel




More information about the Openmcl-devel mailing list