Menu

Problem with typage and save/load/restore-instances

Help
2016-10-07
2016-10-09
  • Chaubert Jérôme

    The following clips code :

    (defclass X (is-a USER)
      (slot symb (type SYMBOL)(visibility public)(storage shared)(create-accessor read-write)))
    
    (defrule start
    =>
      (make-instance [sym1] of X
        (symb (sym-cat 42)))
      (printout t "Integer egality : " (eq 42 (send [sym1] get-symb)) ", Symbol egality : " (eq (sym-cat 42) (send [sym1] get-symb)) crlf)
      (save-instances "C:/acor_dev/bugSave.ins" visible))
    
    (defrule sym
      ?x <- (object (is-a X)
              (symb ?s&:(eq ?s (sym-cat 42))))
    =>
     (send ?x delete)
     (restore-instances "C:/acor_dev/bugSave.ins")
     (printout t "Integer egality : " (eq 42 (send [sym1] get-symb)) ", Symbol egality : " (eq (sym-cat 42) (send [sym1] get-symb)) crlf))
    

    give the following result if dynamic-constraint-checking is FALSE:

    FIRE 1 start: *
    ==> Activation 0      sym: [sym1]
    Integer egality : FALSE, Symbol egality : TRUE
    FIRE 2 sym: [sym1]
    Integer egality : TRUE, Symbol egality : FALSE
    <== Focus MAIN
    

    I would expected that my "42" would be a SYMBOL after restore.

    If dynamic-constraint-checking is TRUE we get an error :

    FIRE 1 start: *
    ==> Activation 0      sym: [sym1]
    Integer egality : FALSE, Symbol egality : TRUE
    FIRE 2 sym: [sym1]
    [CSTRNCHK1] 42 for slot symb of instance [sym1] found in function make-instance
    does not match the allowed types.
    [INSFILE1] Function restore-instances could not completely process file C:/acor_dev/bugSave.ins.
    [PRCCODE4] Execution halted during the actions of defrule sym.
    <== Focus MAIN
    

    With or without dynamic-constraint-checking, I would expected my "42" to be a SYMBOL after restore is there a way to keep the type of a slot ?

     

    Last edit: Chaubert Jérôme 2016-10-07
  • Gary Riley

    Gary Riley - 2016-10-08

    CLIPS doesn't support a lexical mechanism for coercing a non-symbol value into a symbol (e.g. using single quotes around the integer 42 to indicate it should be a symbol). So when the coerced symbol 42 is written out as text it's indistinguishable from the integer 42. You can get around this limitation either by coercing 42 to a string rather than to a symbol, or by using bsave-instances/bload-instances which saves in a binary format that preserves the type.

     
  • Chaubert Jérôme

    Ok, thanks for your quick answer. I thought there is a way to check type slot from the class definition at load but it would certainly be complicated....
    In fact there is another problem with load : if instances with name "gen" are saved and loaded, the "gensym" counter is not updated at load. After that it could try to make instance "gen" with an already taken name, this throws an error... but it is not a big problem... i can rename my instances...

     

Log in to post a comment.