Hacker News new | past | comments | ask | show | jobs | submit login

There are declared types and derived types, which are obtained by type inference and propagation. As much as possible, those types are used by the compiler, at compile-time, to signal type errors that are bound to happen at runtime, given the known types.

But the code is robust and you can give a string to a function that is declared to accept a number (e.g. from the REPL): your program won't crash, because types are checked at runtime too (you have an exception).

So, with default safety and speed optimization levels, adding type declarations will actually add runtime checks. But if you say "trust me, this will be a fixnum, produce some efficient code", then the type discrimination that would happen at runtime is bypassed and you directly emit the opcodes related to your type and this is how you optimize your code. For example, requesting a high-level of speed and low safety/debug will report a lot of optimization notes from SBCL, like: "forced to do GENERIC-+ instead of FIXNUM-+ because of type uncertainty".

http://www.lispforum.com/viewtopic.php?f=2&t=191

http://www.xach.com/sbcl/doc/x282.html

http://www.pvk.ca/Blog/2013/11/22/the-weaknesses-of-sbcls-ty...




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: