Sadly, statically typed Lisp is a contradiction in terms. It would be in the same category as dynamically typed Haskell.
But the experiment shows nicely how little you need to bootstrap something lispy.
But the experiment shows nicely how little you need to bootstrap something lispy.
* (defun foo (x) x)
FOO
* (declaim (ftype (function (fixnum)) foo))
* (defun bar (y) (declare (string y)) (foo y))
; in: DEFUN BAR
; (FOO Y)
;
; caught WARNING:
; Derived type of Y is
; (VALUES STRING &OPTIONAL),
; conflicting with its asserted type
; FIXNUM.
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
BAR
One could also declare the function signature first (perhaps in skeleton code generated by modelling tools). Then, if someone implements it incorrectly, the compiler will throw an error (again, SBCL): * (declaim (ftype (function (fixnum)) qux))
* (defun qux (z) (car z))
; in: DEFUN QUX
; (CAR Z)
;
; caught WARNING:
; Derived type of Z is
; (VALUES FIXNUM &OPTIONAL),
; conflicting with its asserted type
; LIST.
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
QUX
Here's a good discussion of static typing in Common Lisp:http://www.lispforum.com/viewtopic.php?f=2&t=191
TL;DR is that many CL implementations will check types at compile time, but for appropriate speed and safety settings, they will also generate code that checks types at runtime, too.
char *foo(char *bar) {
return bar;
}
int main(int argc, char *argv[]) {
foo(1);
return 0;
}
I get compile-time warnings from clang substantially similar to what SBCL emits: $ cc test.c
test.c:6:7: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'char *' [-Wint-conversion]
foo(1);
^
test.c:1:17: note: passing argument to parameter 'bar' here
char *foo(char *bar) {
^
1 warning generated.
I'm sure that with suitable flags set, both compilers would throw type errors at compile-time instead of warnings.But that's possible (and available).