How do I assert a fact in a CLIPS deffunction? -


i attempted using modify function doesn't , prints false, don't know doing wrong.

i used

(modify ?tv (v ?x)) 

it didn't work. used

    (retract ?tv)     (assert (v ?x)) 

instead, worked. don't want type out every time want modify fact, made deffunction me,

(deffunction modfact(?index ?factname ?factvalue)     (retract ?index)     (assert (?factname ?factvalue)) ) 

in gives syntax error of:

[prntutil2] syntax error:  check appropriate syntax first field of rhs pattern.  error: (deffunction main::modfact     (?index ?factname ?factvalue)     (retract ?index)     (assert (?factname 

which seems me saying can't make function because can't assert fact value of variable. how can work?

modify works facts have associated deftemplate defined slots:

clips>  (deftemplate task    (slot id)    (slot completed)) clips> (watch facts) clips> (assert (task (id x) (completed no))) ==> f-1     (task (id x) (completed no)) <fact-1> clips>  (defrule modit    ?f <- (task (completed ~yes))    =>    (modify ?f (completed yes))) clips> (run) <== f-1     (task (id x) (completed no)) ==> f-2     (task (id x) (completed yes)) clips> 

when using assert command, first field of fact must symbol. if must around restriction can use str-assert function.

clips>  (deffunction modfact (?index ?factname ?factvalue)    (retract ?index)    (str-assert (str-cat "(" ?factname " " ?factvalue ")"))) clips> (assert (v 3)) ==> f-3     (v 3) <fact-3> clips> (modfact 3 v 4) <== f-3     (v 3) ==> f-4     (v 4) <fact-4> clips>  

Comments