3 ms·
Here is my counter-example. It is the console output of Clisp 2.49: Break 1 [2]> (declaim (ftype (function (string) t) foo)) NIL Break 1 [2]> (defun foo (x)
by twblalock 10y ago
Here is my counter-example. It is the console output of Clisp 2.49:
Break 1 [2]> (declaim (ftype (function (string) t) foo))
NIL
Break 1 [2]> (defun foo (x) (print x))
FOO
Break 1 [2]> (foo "hello")
"hello"
"hello"
Break 1 [2]> (foo nil)
NIL
NIL
Break 1 [2]>
There were no errors. The function accepted nil and printed it. You must have some other type restrictions going on than what you mentioned. The output is the same whether I put the declaim statement before or after defun foo.
- junke 10y agoThe behavior is undefined if a value does not match its type declaration, and implementations are free to ignore some declarations, like CLISP. So for a portable approach just add a CHECK-TYPE: (defun foo (s) (check-type s string) (print s)) The main point is that (TYPEP NIL 'STRING) is NIL.