Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

recursive message handler

pyc
2012-03-11
2012-11-23
  • pyc
    pyc
    2012-03-11

    Is there a capability in COOL to write a recursive message handler?
    I tried to call an internal-instance handler from within an instance handler.
    The internal-instance and the instance are of the same class.
    The instance is made according to has-a pattern, where the instance's multislot is made from internal-instance.
    Such inclusion could be to any depth, so it would be convenient to call handlers of internal-instances from the handler of the instance, for example to print all instances.
    I got "No applicable primary message-handlers found for print." when tried to call (send  print) inside print handler for the class.
    Is there something I am missing regarding recursiveness of the handlers (not possible?) ?
    Is there an alternative way to achieve similar functionality?
    Thanks,
    Pyc.

     
  • pyc
    pyc
    2012-03-11

    I made mistakes, sorry. The recursive message handling works for COOL.

     
  • Gary Riley
    Gary Riley
    2012-03-11

    It sounds like what you did was to send to the specific instance  rather than the instance variable ?self:inner-instance.

            CLIPS (6.30 8/15/11)
    CLIPS> 
    (defclass EXAMPLE
       (is-a USER)
       (slot inner-instance (type INSTANCE)))
    CLIPS>    
    (definstances example
       ([a] of EXAMPLE (inner-instance ))
       ( of EXAMPLE (inner-instance [c]))
       ([c] of EXAMPLE))
    CLIPS>    
    (defmessage-handler EXAMPLE my-print ()
       (send ?self print)
       (if (instance-existp ?self:inner-instance)
          then
          (send [inner-instance] my-print)))
    CLIPS> (send [a] my-print)
    [a] of EXAMPLE
    (inner-instance )
    [MSGPASS2] No such instance inner-instance in function send.
    [PRCCODE4] Execution halted during the actions of message-handler my-print primary in class EXAMPLE
    FALSE
    CLIPS>    
    (defmessage-handler EXAMPLE my-print ()
       (send ?self print)
       (if (instance-existp ?self:inner-instance)
          then
          (send [inner-instance] my-print)))
    CLIPS>    
    (defmessage-handler EXAMPLE my-print ()
       (send ?self print)
       (if (instance-existp ?self:inner-instance)
          then
          (send ?self:inner-instance my-print)))
    CLIPS> (send [a] my-print)
    [a] of EXAMPLE
    (inner-instance )
     of EXAMPLE
    (inner-instance [c])
    [c] of EXAMPLE
    (inner-instance [nil])
    FALSE
    CLIPS>