Hi,

Two-part answer.

First, you can of course create the argument to "build" by calling other Jess functions; that's what you need to do here. The "str-cat" function pastes together the values of its arguments into one string; the value of a variable is of course the contents of that variable. So something like this:


(build (str-cat "(defrule  checkLeave_" ?userName "
                     (user (name " ?userName ") (isInRoom ~Office1))
                     =>
(printout t User " ?userName " \" has left Office1\" crlf))"))

If you look carefully, you'll see that all three occurrences of ? userName are outside the string quotes.

Now, second: rather than creating a new rule in this case, consider instead using a single rule and creating relevant data instead. So, for example, just one rule like:

(defrule  checkLeave
    ?m <- (watch-to-leave (name ?userName) (room ?room))
    (user (name ?userName) (isInRoom ~?room))
    =>
    (retract ?m)
    (printout t "User " ?userName " has left " ?room crlf))

Now, when you want to watch that Fred stays in Office1, you just assert a fact like

(watch-to-leave (name Fred) (room Office1))

This is a much more efficient way to do what you want.



On Jan 4, 2008, at 12:52 PM, [EMAIL PROTECTED] wrote:

Hello, I'm a relatively new Jess user and I'm having difficulties with a rule. I need to create a rule for a context-aware application that monitors if a user leaves a room. For that a have the following deftemplate:

(deftemplate user
      (slot name)
      (slot isInRoom))

The rule should notify me whenever someone leaves an specific room. The solution I imagined has the following LHS

(defrule ruleCheckLeaveRoom
      (user (name ?userName) (isInRoom Office1))

My problem is that the RHS should create (using build) another rule for each person entering Office1. I tried the following but couldn't have a variable as part of the second rule's name:

(build "(defrule (checkLeave_?userName
                  (user (name ?userName) (isInRoom ~~Office1))
                  =>
                  (printout t User ?userName has left Office1 crlf)
)")

I also need to substitute the variable ?userName for its value so I can have the generation of the second rule like:

(defrule (checkLeave_John
                  (user (name John) (isInRoom ~Office1))
                  =>
                  (printout t User John has left Office1 crlf)
)

Is it possible? Do you have a suggestion for another solution?

Thanks,

Luiz Olavo Bonino
University of Twente


---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to