Can SBCL actually check at compile time that the arguments to fn-t are bytes? I wonder how that works with Lisp's extreme dynamism. Also wondering about the calling convention it uses.
But a good rule-of-thumb is that these compile-time type errors are more of a courtesy, rather than a guarantee. As soon as you abstract over fn-t with another function, like so:
(defun g (x y)
(fn-t x y))
and proceed to use g in your code, all the static checking won't happen anymore, because as far as g is concerned, it can take any input argument types.
Comments
FWIW, SBCL is pretty good at optimizing away dynamic type checks if you help it out.
Here are some examples under:
First example is a generic multiplication. x and y could be _any_ type at all. If we disassemble this function, we get the following: Note that it calls `GENERIC-*` which probably checks a lot of things and has a decent overhead.Now, if we tell it that x and y are bytes, it's going to give us much simpler code.
The resulting code uses the imul instruction.Can SBCL actually check at compile time that the arguments to fn-t are bytes? I wonder how that works with Lisp's extreme dynamism. Also wondering about the calling convention it uses.
It can detect simple-ish instances, like calling
But a good rule-of-thumb is that these compile-time type errors are more of a courtesy, rather than a guarantee. As soon as you abstract over fn-t with another function, like so: and proceed to use g in your code, all the static checking won't happen anymore, because as far as g is concerned, it can take any input argument types. No compile-time warning is issued. Contrast with Coalton: