Hi Kevin, This is mostly just a syntax issue -- both approaches you tried are perfectly reasonable. Given that you've made the store() call as described below, the first approach looks like
(defrule fuelLow (fuel ?f&:(eq ?f (fetch x1))) => ... You can use the return value constraint to write this in shorthand: (defrule fuelLow (fuel =(fetch x1)) => ... If you use "ppdefrule fuelLow" to look at how Jess interpreted this rule, you'll see that it looks like the first version. The problem with the second version is that local variables at the global level aren't really global; if you want global variables you have to use a "defglobal" to formally define them. So you could have (defglobal ?*X1* = (fetch x1)) instead of the "bind" commmand, and then the rule looks like (defrule fuelLow (fuel ?*X1*) => ... Note that defglobal names always start and end with an asterisk. I think Kevin Kelly Aug wrote: > [EMAIL PROTECTED] wrote: > > > > There are many ways you could do this; one simple way is to use the > > fetch and store functions. There's an example in section 4.4.4 of the > > manual. > > I looked at these but they don't show them used in the manner I am > trying to use them and I'm not sure the proper way to acomplish it. > Here is an example: > > I have a fact called "fuel" which has a single parameter: of > java.lang.Integer which defines the amount of fuel available. > > I want to have a rule that determines if the fuel is low. I know the > fuel can only be decrimented by one at a time. > > the rule I want is: > > (defrule fuelLow (fuel java.lang.Integer(4)) > => > (assert (lowFuelLevel))) > > obviously I can't just do it like that so I have tried a couple of > different things, neither of them work. > > I have stored the java.lang.Integer on the java side using > Rete.store("x1", new java.lang.Integer(4)). Then I create the string > that looks like: > > (defrule fuelLow (fuel (fetch x1)) => ... > > using Rete.executeCommand() this gave me a parse error. > > I then tried the same store but tried to use bind to get what I needed. > I sent in "(bind ?X1 (fetch x1))" in executeCommand() and used the > following for my rule: > > (defrule fuelLow (fuel ?X1) => ... > > This would allow ?X1 to be bound to any external address though (treated > as if unbound - which does make sense in a rule). > > I am a bit at a loss here. It is possible I just can't do what I want > to do. > > I realise that I could just use a primitive JESS type rather than > java.lang.Integer but this is just a simple example. I need to be able > to do this for a general case with many different user defined classes. > I also have a large set of facts and the rules can be defined > dynamically so I need to be able to generate it rather than hard code > anything. > > Anyway, I am a major newbie to JESS (though I used CLIPS long ago) and > I just can't figure out how to do this. > > Kevin Kelly > > -------------------------------------------------------------------- > 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] > -------------------------------------------------------------------- > --------------------------------------------------------- Ernest Friedman-Hill Distributed Systems Research Phone: (925) 294-2154 Sandia National Labs FAX: (925) 294-2234 Org. 8920, MS 9012 [EMAIL PROTECTED] PO Box 969 http://herzberg.ca.sandia.gov Livermore, CA 94550 -------------------------------------------------------------------- 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] --------------------------------------------------------------------