Hi,
I want to check that the value of a slot in a class (defined when the class is created) is appropriate based on the values of other slots (e.g., in the example below that the value val is within the range of min and max) and to produce an error if this is not the case. I've not been able to find a solution so far. I'd be very grateful for advice. Thank you.
(defclass foo ()
((min :initarg :min)
(max :initarg :max)
(val :initarg :val))
Checking consistency between class slots
Re: Checking consistency between class slots
You can enforce such checks when setting the value by creating custom accessor methods. Possibly as an auxiliary method. You can add such a check at instance creation time by adding an :after method to SHARED-INITIALIZE.
More detailed description of using CL object system is in a book by Sonya Keene. Unfortunately it is not available for free on the net.
More detailed description of using CL object system is in a book by Sonya Keene. Unfortunately it is not available for free on the net.
Re: Checking consistency between class slots
see also the Object Initialization section of http://www.gigamonkeys.com/book/object- ... asses.html
Re: Checking consistency between class slots
Many thanks to you both. I have managed to develop a solution using (defmethod initialize-instance :after ...) My problem arose because I misunderstood how this worked.
Thanks again
Thanks again