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
Subject: JESS: Scoping Question
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
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
Is this the expected behaviour? (This is just a curiosity question.)
(deftemplate person "" (slot name) (slot age))
(person (name bill) (age 20))
(person (name will) (age 25))
(person (name dill) (age 25))
(person (name jill) (age 22)) )
?f <- (person (age ?max))
(not (person (age ?less&:(> ?less ?max))))
(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) )