Occasionally, it is important to create new variables or to modify the value of previously bound variables on the RHS of a rule. The bind function provides this capability.
Syntax
(bind <variable> <expression>*)
where the first argument to bind, <variable>, is the local or global variable to be bound (it may have been bound previously). The bind function may also be used within a message-handler's body to set a slot's value.
If no <expression> is specified, then local variables are unbound and global variables are reset to their original value. If one <expression> is specified, then the value of <variable> is set to the return value from evaluating <expression>. If more than one <expression> is specified, then all of the <expressions> are evaluated and grouped together as a multifield value and the resulting value is stored in <variable>.
The bind function returns the symbol FALSE when a local variable is unbound, otherwise, the return value is the value to which <variable> is set.
Example 1
CLIPS> (defglobal ?*x* = 3.4) CLIPS> ?*x* 3.4 CLIPS> (bind ?*x* (+ 8 9)) 17 CLIPS> ?*x* 17 CLIPS> (bind ?*x* (create$ a b c d)) (a b c d) CLIPS> ?*x* (a b c d) CLIPS> (bind ?*x* d e f) (d e f) CLIPS> ?*x* (d e f) CLIPS> (bind ?*x*) 3.4 CLIPS> ?*x* 3.4 CLIPS>
Example 2
CLIPS> (defclass A (is-a USER) (role concrete) (slot x) (slot y)) CLIPS> (defmessage-handler A init after () (bind ?self:x 3) (bind ?self:y 4)) CLIPS> (make-instance a of A) [a] CLIPS> (send [a] print) [a] of A (x 3) (y 4) CLIPS>