10 ms·
> This underlines the fact that Lisp projects can very easily end in spectacular disasters. This is not specific to Lisp, it happens to all dynamically typed l
by hota_mazi 6y ago
> This underlines the fact that Lisp projects can very easily end in spectacular disasters.
This is not specific to Lisp, it happens to all dynamically typed languages.
And this is why "holding invariants in my head" doesn't scale. Your objects have a type. Why not put it in the code and ask the compiler to verify it, so that future developers on that code (including yourself) will have an easier time reading it and evolving it?
- lispm 6y agoCommon Lisp allows to annotate code with type information, which can be checked at runtime. Also it's object system works on classes and thus generic function have arguments for those classes. Something like Common Lisp is a dynamically typed language, but where implementations can use knowledge about types, either at runtime or even sometimes at compile time. SBCL * (defvar *foo*) ; a global variable *FOO* *FOO* We tell SBCL that the type of the variable is an integer between 0 and 10. * (declaim (type (integer 0 10) *foo*)) (*FOO*) Now we try to set it to 30: * (setf *foo* 30) SBCL detects the problem: ; in: SETF FOO ; (SETF FOO 30) ; --> SETQ ; ==> ; (THE (MOD 11) 30) ; ; caught WARNING: ; Constant 30 conflicts with its asserted type (MOD 11). ; See also: ; The SBCL Manual, Node "Handling of Types"
- sevensor 6y agoThat's amazing. I want that. I like how clear it is about what it's for, which is the sort of thing one does all the time in other languages that lack a vocabulary for it. I'm going to assume you could put any predicate you wanted in there?