From: Joe Marshall
Subject: Re: static typing
Date: 
Message-ID: <1154969890.284637.236860@p79g2000cwp.googlegroups.com>
Pascal Bourguignon wrote:

>
> Anyways, if you want to declare types, you can.
>
> (defun f (x)
>   (declare (integer x))
>   (+ 1 x))
>
> (f 3.0)
> --> debugger invoked on a TYPE-ERROR: The value 3.0 is not of type INTEGER.

Just to clarify.  A Common Lisp implementation is not required to
produce an error here.

A type declaration in Common Lisp is a promise from you to the compiler
that your program will always use the declared type.  The compiler is
allowed to trust you competely on this point and could produce code
that has undefined consequences if you happen to be incorrect about the
declaration or lie to the compiler.  For instance,

 (defun f (x)
   (declare (integer x))
   (+ 1 x))

(f 3.0)
--- whirring noise --- reboot --- BIOS ERROR:  UNFORMATED MEDIUM ----

The CHECK-TYPE macro causes an explicit type-check to be performed and
it is what you should use if you are interested in having the system
raise an error.

(defun f (x)
  (check-type x integer)
  (+ x 1))

(f 3.0)
---> Enters error handler.