[Openmcl-devel] declare

Stas Boukarev stassats at gmail.com
Thu Jun 4 21:41:48 PDT 2009


slepstein at mindspring.com writes:

> I believe in type checking, but the declare usage is puzzling me, and I think it has changed in the last 6 months or so…
>
> What (I think) used to work and was acceptable in MCL:
> (defun foo-1 (x)
>     (declare (integer x y))
>     (let* ((y 3))
>       (+ x y)))
> ;Compiler warnings :
> ;   In FOO-1: TYPE declaration for unknown variable Y
>
> This compiles without warnings:
> (defun foo-2 (x)
>     (declare (integer x))
>     (let* ((y 3))
>       (declare (integer y))
>       (+ x y)))
>
> But this doesn’t:
> (defun foo-3 (x)
>     (declare (integer x))
>     (let* ((y 3))
>      	 (z (+ x y)))
>       (declare (integer y z))
>       (+ x y z)))
> Error: While compiling FOO-3 :
> DECLARE not expected in (DECLARE (INTEGER Y Z))., in process Listener(6).
>  
> Nor does this:
> (defun foo-4 (x)
>     (let* ((y 3))
>       (z (+ x y)))
>   (declare (integer x  y z))
>       (+ x y z))
>> Error: While compiling FOO-4 :
>>        DECLARE not expected in (DECLARE (INTEGER X Y Z))., in process Listener(6).
>
> It looks as if the declare has to come early, but how does one type z?
> Thanks for your help.
Your paranthesis are wrongly balanced.

(defun foo-3 (x)
  (declare (integer x))
  (let* ((y 3)
         (z (+ x y)))
    (declare (integer y z))
    (+ x y z)))

(defun foo-4 (x)
  (let* ((y 3)
         (z (+ x y)))
    (declare (integer x y z))
    (+ x y z)))

-- 
With best regards, Stas.



More information about the Openmcl-devel mailing list