3 ms·
That's dependent on the implementation, SBCL is particularly good at it. Others may just let things pass like: (defun foo () (* 1 "aoeu")) In SBCL gives me
by Jtsummers 4y ago
That's dependent on the implementation, SBCL is particularly good at it. Others may just let things pass like:
(defun foo () (* 1 "aoeu"))
In SBCL gives me this:
; in: DEFUN FOO
; (* 1 "aoeu")
;
; caught WARNING:
; Constant "aoeu" conflicts with its asserted type NUMBER.
; See also:
; The SBCL Manual, Node "Handling of Types"
;
; compilation unit finished
; caught 1 WARNING condition
But in CCL it gives me no warnings at all and only triggers an error at runtime.
- tmtvl 4y agoSchemer here, so this question may be silly, but can't you declare or declaim or proclaim or whatever (safety 3) to get stricter typechecking?
- Jtsummers 4y agoThose are only advice to the compiler, but importantly `safety` is about run-time error checking. Pushing `speed` higher and dropping `safety` to 0 means that runtime type checks might be removed for certain things, but it's not required to. Like if you've similarly declared that a variable definitely holds a `fixnum`, it'll believe you whether that turns out to be the right thing in the end or not. But again, it's advice. The compiler could leave those runtime checks in place, too.
- pfdietz 4y agoAn aside: never declare something to be a fixnum in Common Lisp. Fixnum means different things in different CL implementations, so this is a good way to get unportable code. Instead, use explicit integer range types.