4 ms·
Lisp's type system is fine. (defstruct adult (name 'error :type string) (age 'error :type (integer 18 200))) * (make-adult :name "Bob" :age 3) de
by NikkiA 2y ago
Lisp's type system is fine.
(defstruct adult (name 'error :type string) (age 'error :type (integer 18 200)))
* (make-adult :name "Bob" :age 3)
debugger invoked on a TYPE-ERROR @5529ACEE in thread
#<THREAD tid=426288 "main thread" RUNNING {1003F000A3}>:
The value
3
is not of type
(INTEGER 18 200)
when setting slot AGE of structure ADULT
* (make-adult :age 18)
debugger invoked on a TYPE-ERROR @5529ACF2 in thread
#<THREAD tid=426288 "main thread" RUNNING {1003F000A3}>:
The value
ERROR
is not of type
STRING
when setting slot NAME of structure ADULT
- lispm 2y agoNote that this behavior is completely implementation specific and totally undefined in the Common Lisp standard.
- ducktective 2y agoWhat is standard CL way to enforce these type conditions (apart from declaim)? Some spec library similar to the one Clojure has?
- NikkiA 2y ago`declaim` is just as implementation-dependant as the :type specifiers for defstruct, thus by lispm's rules, there are no 'standard' ways to apply type conditions. But then, the standard /is/ useless.
- lispm 2y agoThe standard leaves it to the implementations/implementors to decide what to do. An implementation can check all these type constraints. It may not do it, for example, if code gets compiled with the opimization quality SAFETY of 0 (and possibly SPEED = 3) or similar. It may not do it all. There are implementations which check these type constraints. So it is best to check the manual or ask the maintainers. IIRC there were implementations which added it on user requests. But don't think all "Common Lisp" implementations will check those constraints, for example ABCL does not. Some don't and in others it can be turned off.