CLIPS>
(defclass PERSON
(is-a USER)
(slot sex))
CLIPS>
(defclass MAN
(is-a PERSON)
(slot sex (default male)))
CLIPS> (make-instance of PERSON)
[gen1]
CLIPS> (send [gen1] print)
[gen1] of PERSON
(sex nil)
CLIPS> (make-instance of MAN)
[gen2]
CLIPS> (send [gen2] print)
[gen2] of MAN
(sex male)
CLIPS>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2009-05-01
Thanks Gary. I don't mean to be picky, but is there a way to do this without redefining the slot in the subclass? I am not saying that is a bad approach but it seems to me there must be a way to do it without redefining.
In other langauages (as you know) you would set the value in a constructor.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Say I have a class PERSON with a slot 'sex'.
I also have a class MAN which is a sub class of PERSON.
In the definition of MAN, how do I set the value of 'sex' to 'male'.
I know this must be simple but I am not able to get it right.
Thanks
CLIPS>
(defclass PERSON
(is-a USER)
(slot sex))
CLIPS>
(defclass MAN
(is-a PERSON)
(slot sex (default male)))
CLIPS> (make-instance of PERSON)
[gen1]
CLIPS> (send [gen1] print)
[gen1] of PERSON
(sex nil)
CLIPS> (make-instance of MAN)
[gen2]
CLIPS> (send [gen2] print)
[gen2] of MAN
(sex male)
CLIPS>
Thanks Gary. I don't mean to be picky, but is there a way to do this without redefining the slot in the subclass? I am not saying that is a bad approach but it seems to me there must be a way to do it without redefining.
In other langauages (as you know) you would set the value in a constructor.
CLIPS>
(defclass PERSON
(is-a USER)
(slot sex))
CLIPS>
(defclass MAN
(is-a PERSON))
CLIPS>
(defmessage-handler MAN init after ()
(send ?self put-sex male))
CLIPS>
Cool. Thanks.