Menu

using instance method in object pattern

Help
2011-02-21
2012-11-23
  • daniel raffin

    daniel raffin - 2011-02-21

    Hi,

    I don't think it is possible to invoke an instance method when using an object-pattern-CE
    Can you tell me how CLIPS shoul be modified in order to add the functionality below:
    (defrule R (object (is-a A) (test (send ?self <handler> <args>*))) =>)

    A possible workaround valid in a not-CE:
    (defclass A (is-a USER)
    (slot value)
    (slot me)
    )
    (defmessage-handler A init ()
    (bind ?self:me ?self)
    )
    (defmessage-handler A check (?arg)
    (printout t "check " (instance-name ?self) crlf)
    )
    (defrule checkobject
    (not
    (object (is-a A) (value ?val) (me ?ins))
    (test (send ?me check ?val))
    )
    =>
    )

    Thanks

     
  • Gary Riley

    Gary Riley - 2011-03-04

    Here are 3 ways to do it:

    CLIPS> 
    (defclass A (is-a USER)
       (slot value))
    CLIPS> 
    (defmessage-handler A check (?arg)
       (printout t "check " (instance-name ?self) crlf))
    CLIPS> 
    (defrule R1 
       (object (is-a A) (name ?name&:(send ?name check (send ?name get-value)))) 
       =>)
    CLIPS> 
    (defrule R2 
       (object (is-a A) (name ?name))
       (test (send ?name check (send ?name get-value))) 
       =>)
    CLIPS> 
    (defrule R3 
       ?o <- (object (is-a A))
       (test (send ?o check (send ?o get-value))) 
       =>)
    CLIPS> (make-instance a of A)
    check [a]
    check [a]
    check [a]
    [a]
    CLIPS>
    
     

Log in to post a comment.