Menu

#8 save-instances and load-instances does not work for instance-address slot types

1.0
accepted
None
2016-01-20
2015-12-31
Steve Menke
No

The load-instances command does not seem to be able to properly create a instance-address slot type. See the following code as and example:

CLIPS> (clear)
CLIPS> (defclass PARENT
(is-a USER) (role concrete)
(slot parent (type INSTANCE-ADDRESS) (create-accessor read-write)))
CLIPS> (make-instance [a] of PARENT)
[a]
CLIPS> (make-instance [b] of PARENT (parent (instance-address [a])))
[b]
CLIPS> (send [b] print)
[b] of PARENT
(parent <Instance-a>)
CLIPS> (save-instances "test.ins")
3
CLIPS> (load-instances "test.ins")
3
CLIPS> (send [b] print)
[b] of PARENT
(parent [a])
CLIPS>

I would expect that last print to return (parent <Instance-a>)

Discussion

  • Gary Riley

    Gary Riley - 2016-01-12

    Save-instances uses a text representation for the instances, so it doesn't support saving pointers (instance addresses, fact addresses, and external addresses). If you want to be able to save links between instances, you'll need to use instance names rather than instance addresses. I'l update the documentation to reflect this limitation and look into enhancing bsave-instances, which uses a binary representation, to restore instance addresses.

     
  • Gary Riley

    Gary Riley - 2016-01-12
    • status: new --> accepted
    • assigned_to: Gary Riley
     
  • Steve Menke

    Steve Menke - 2016-01-20

    Why can't you use (instance-address [a]) to load the data from text? Converting to use instance names affect the rules. Typical object matching returns the instance-address not the name. So, you have to use the name field in the RHS to use the match in other lines.

     
  • Gary Riley

    Gary Riley - 2016-01-20

    Using the instance-address function isn't a general solution. The instance needs to exist when instance-address is called, which in the following case it is not:

    (a of A (child (instance-address [b])))
    (b of B)
    

    You could do some analysis to try to figure out which instances are dependent on others and try to write them out in the appropriate order, but that will fail if there are circular dependencies:

    (a of A (child (instance-address [b])))
    (b of B (parent (instance-address [a])))
    
     

Log in to post a comment.