How do I bind the value of a global variable to a slot?

61 Views Asked by At

I am trying to bind a slot to global variable but doesn't seem to work.

I have tried the below but the rules I created don't work.

*(defrule getusermalinfo
(user  (usinfo  ?usr))
=>
(bind ?usr ?*degreeofyes*)  
)*

After, I want to use the slot value to make some decisions. Like the rule below:

*(defrule not-likely
(user {usinfo <= 10})
=>
(printout t "Not suffering from Kwashiorkor" crlf)
)*
1

There are 1 best solutions below

1
laune On

One cannot use (bind) for modifying a fact's slot values. You need to use (modify), something like this:

(defrule getusermalinfo
  ?user <- (user)
 =>
  (modify ?user (usinfo ?*degreeofyes*))
)

Note, however, that you may have to add something to the LHS of this rule to select some specific user fact and/or avoid repeated firing of this rule after the modification.