That's not related to Lisp per se. But in the general case, dynamic
Henry Bigelow wrote:
> hi everyone,
> just wanted to say thanks for the posts. very enlightening!
> would it be possible to write a system of macros, say, to make
> available the abstract, recursive, inferred, variant etc. yet static
> typesystem of O'Caml in lisp? say, in the way CLOS was an extension of
> lisp to objects.
> or is there a reason why this is impossible to do in lisp?
typing and static typing are not compatible. In Common Lisp, there are a
lot of cases where you can very conveniently change types at runtime. So
a static check of types would be a great burden. Here is my standard
example for this:
(defclass person ()
((name :initarg :name)))
(let ((p (make-instance 'person :name "Pascal")))
(setf (slot-value p 'address) "Brussels"))
There is no chance to see upfront whether this program will fail or not,
since the user can redefine the class person when (eval (read)) is
executed. At that time, the slot 'address could be added to the class
person. This is a contrived example, but similar things are indeed
actually quite useful in a certain class of programs. (Think of
frame-based knowledge representation systems, for example.)
On the other hand, in a statically typed language (with a sufficiently
interesting type system, like Hindley-Milner type systems), you can do
things like dispatch on the expected return type of a function. In a
dynamically typed language, you don't have any guarantees about future
computations, but in statically typed language, you can ensure that only
certain types (or a certain type) is returned from a function.
So in the extreme case, dynamically typed and statically typed languages
offer different kinds of expressiveness, and depending on what you want
to do, the one approach is indeed better suited for a problem at hand
than the other. If you don't want to take advantage of the specific
advantages, then it's rather just a matter of taste.
All other claims about static vs. dynamic types are bogus and unfounded,
and based on anecdotal evidence at best. Especially the typical claims
wrt efficiency and safety are unfounded. These claims are typically
demonstrated on small toy programs, and this doesn't prove anything.
> why is it not possible to 'turn off' static typechecking for individual Because this would change the semantics of the language.
> functions while compiling o'caml?
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/