default value for a sub class

Help
Anonymous
2009-05-01
2012-11-23
  • Anonymous - 2009-05-01

    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

     
    • Gary Riley

      Gary Riley - 2009-05-01

      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>

       
      • 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.

         
    • Gary Riley

      Gary Riley - 2009-05-02

      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>

       
      • Anonymous - 2009-05-02

        Cool. Thanks.

         

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks