JESS: Scoping Question

2011-11-10 Thread David Scuse
Hi Ernest:
I came across a strange feature of Jess as a result of a typing error.
It appears as though Jess uses dynamic scoping -- any variables defined in a 
rule
are visible in any functions called by the RHS of the rule.
I looked for references to this in the book and the manual but couldn't find 
anything.
Is this the expected behaviour? (This is just a curiosity question.)
Thanks
David


(deftemplate person  (slot name) (slot age))

(deffacts initialFacts
 (person (name bill) (age 20))
 (person (name will) (age 25))
 (person (name dill) (age 25))
 (person (name jill) (age 22)) )

(defrule findOldest
?f - (person (age ?max))
(not (person (age ?less:( ?less ?max
=
(my-function) )

(deffunction my-function ()
(printout t crlf Processing fact  (?f toString) crlf)
(printout t crlf Max age is  ?max crlf)
(printout t crlf Max age is  ?f.age crlf crlf) )

(reset)
(run)
(facts)


RE: JESS: Scoping Question

2011-11-10 Thread Friedman-Hill, Ernest
Since control structures are functions in Jess, the ability for a function to 
peek from one stack frame to another is important.  I could have implemented 
this using some kind of special form or keyword -- like the Tcl uplevel 
function -- but in the first go-round, I think I just took the easy way out, 
and this behavior has stuck ever since. Note that it's read-only by default: 
binding a value to a variable in a deffunction creates a new variable in the 
local scope. That's why recursive functions are possible.





From: owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] On 
Behalf Of David Scuse
Sent: Wednesday, November 09, 2011 11:43 AM
To: jess-users
Subject: JESS: Scoping Question

Hi Ernest:
I came across a strange feature of Jess as a result of a typing error.
It appears as though Jess uses dynamic scoping -- any variables defined in a 
rule
are visible in any functions called by the RHS of the rule.
I looked for references to this in the book and the manual but couldn't find 
anything.
Is this the expected behaviour? (This is just a curiosity question.)
Thanks
David


(deftemplate person  (slot name) (slot age))

(deffacts initialFacts
 (person (name bill) (age 20))
 (person (name will) (age 25))
 (person (name dill) (age 25))
 (person (name jill) (age 22)) )

(defrule findOldest
?f - (person (age ?max))
(not (person (age ?less:( ?less ?max
=
(my-function) )

(deffunction my-function ()
(printout t crlf Processing fact  (?f toString) crlf)
(printout t crlf Max age is  ?max crlf)
(printout t crlf Max age is  ?f.age crlf crlf) )

(reset)
(run)
(facts)


Re: JESS: Scoping Question

2011-11-10 Thread David Scuse
That makes perfect sense.
Thank you.
  - Original Message - 
  From: Friedman-Hill, Ernest 
  To: jess-users 
  Sent: Thursday, November 10, 2011 2:15 PM
  Subject: RE: JESS: Scoping Question


  Since control structures are functions in Jess, the ability for a function to 
peek from one stack frame to another is important.  I could have implemented 
this using some kind of special form or keyword -- like the Tcl uplevel 
function -- but in the first go-round, I think I just took the easy way out, 
and this behavior has stuck ever since. Note that it's read-only by default: 
binding a value to a variable in a deffunction creates a new variable in the 
local scope. That's why recursive functions are possible.





--

  From: owner-jess-us...@sandia.gov [mailto:owner-jess-us...@sandia.gov] On 
Behalf Of David Scuse
  Sent: Wednesday, November 09, 2011 11:43 AM
  To: jess-users
  Subject: JESS: Scoping Question


Hi Ernest:
I came across a strange feature of Jess as a result of a typing error.
It appears as though Jess uses dynamic scoping -- any variables defined in 
a rule
are visible in any functions called by the RHS of the rule.
I looked for references to this in the book and the manual but couldn't 
find anything.
Is this the expected behaviour? (This is just a curiosity question.)
Thanks
David


(deftemplate person  (slot name) (slot age))

(deffacts initialFacts
 (person (name bill) (age 20))
 (person (name will) (age 25))
 (person (name dill) (age 25))
 (person (name jill) (age 22)) )

(defrule findOldest
?f - (person (age ?max))
(not (person (age ?less:( ?less ?max
=
(my-function) )

(deffunction my-function ()
(printout t crlf Processing fact  (?f toString) crlf)
(printout t crlf Max age is  ?max crlf)
(printout t crlf Max age is  ?f.age crlf crlf) )

(reset)
(run)
(facts)


JESS: Ignore slots when matching lhs of rules

2011-11-10 Thread Hunter McMillen
Hi everyone,

 I am trying to match the lhs of a rule using a template that has 112 slots
that is defined from a Java class.

 Here is the template definition (from show-deftemplates):

 (deftemplate MAIN::unit
$JAVA-OBJECT$ eisbot.proxy.model.Unit
(declare (from-class eisbot.proxy.model.Unit)))

Now every time that I encounter a unit object in my application I define an
instance of the unit to Jess from Java:

engine.defclass(unit, eisbot.proxy.model.Unit, null, true); (I only do
this the first time)

Unit unit = //retrieve a unit
engine.definstance(unit, unit, false);

All of this above is working as it should be, but now when I try to match a
unit in a rule I am having trouble:

String unitSeen = (defrule unitSeen  +
  (unit (ID ?id) (typeID ?typeID))  +
  =  +
  (printout t \Unit seen with ID: \ ?id crlf));

engine.executeCommand(unitSeen);

The problem is that the Unit class has 112 attributes, I am only listing
two ID and typeID, and there are probably only another handful that I care
about and need to use. Is there any way to ignore the rest of the slots in
the template, matching only on a few slots?

Goal:

The main goal of what I am trying to is that when I encounter a Unit in my
game application, I want to assert that unit object to Jess as a fact, then
match rules on the existence of a Unit. Right now I only want to match on
the existence of ANY unit, but later on the matches will be more specific.

Any help would be most appreciated.

Thanks.
Hunter McMillen