Re: Using :type slot option
"Bruno Emond (as emond dot bruno at gmail dot com)" <[email protected]>
| Newsgroups | gmane.lisp.lispworks.general |
|---|---|
| Message-ID | <[email protected]> |
For those who might be interested. Here is an updated version for the slot type verification code. It only relies on using a metaclass and LispWorks :optimize-slot-access, if one wants to verify slot accessors. Bruno > On Feb 18, 2025, at 11:44, Bruno Emond <[email protected]> wrote: > > I understand that the Common Lisp standard specifies that "The consequences of attempting to store in a slot a value that does not satisfy the type of the slot are undefined.”. > > However, I am wondering if there is a simpler way to implement slot type checking than the code I wrote (see file attached). > > A small annoyance with this code is that one need to always include: > 1) inheritance to a class that verify slot types when an instance is initialized (however this can be done once for the most general class), > 2) the metaclass option to verify a slot type when the slot value is set, and possibly (has to be done for every class definition), > 3) the class option :optimize-slot-access nil (has to be done for every class definition), if one also wants to verify the type of a slot when it is set using an accessor. > > Thanks for any suggestions. > > Bruno > > <typep-slots.lisp>
type-slots-class.lisp
(application/octet-stream, 3.2 KB) - not displayed