I think Matthew Hutchinson wrote:
> 
> 1. Why can't defrule be used directly within a user function?

Basically because it's executed by the parser, not by the runtime
engine. It's executed immediately when it's encountered in the
source. If you look in the back of the (Jess 7) manual, you'll find an
appendix listing all the "constructs", separate from the list of
"functions"; all the constructs are the same way. In standard
Lisp-ese, these are known as "special forms".

> 2. What is the scope of a variabled bound (binded?) within a user function?

Limited to that user function.

> 3. If "build" comes across a variable ( ?someVar ) in a string it is
> evaluating, does it treat it like a variable?
> 

That depends on what the variable means in the code being parsed by
"build." If you're "build"-ing a function call, then that function
call will be evalulated right away, using the deffunction's execution
context to find the values for variables.  So, for example,

  (bind ?x 1)
  (build "(printout t ?x crlf)")

prints "1". But if you're build-ing a defrule, then the parser knows
that variables are supposed to be inserted literally into the defrule
itself. It's exactly as if the rule were included at the top level of
your Jess program. Your variable "?matches" is eventually interpreted
in the context of the firing defrule; the deffunction context is long
gone by then. 

Since you basically want ?matches to be a global variable shared by
multiple rule firings, you need to make it a global variable. Use a
defglobal for this.


> 
> (clear)
> (reset)
> 
> (import java.util.ArrayList)
> 
> (deftemplate street_name_alias (slot actual_name) (slot actual_type) (slot
> dli_id) (slot soundex) (multislot alias) (slot lga) (slot locality) )
> (load-facts "road_facts.fct")
> 
> (deffunction street-names-soundex (?input)
>     (bind ?matches (new ArrayList 0) )
>     (bind ?code (str-cat "\""?input"\"") )
>     (printout t ?code crlf)
> 
>     (bind ?rule (str-cat "(defrule name-from-soundex (street_name_alias
> (soundex " ?code ") (actual_name ?name)) => (call ?matches add ?name)  )") )
>     (build ?rule)
> 
>     (return true)
>     )
> 
> (street-names-soundex "M640")
> (run)
> 
> -------------------------------------------------------
> 
> When I refer to ?matches in my RHS, shouldn't it see the variable I have
> already established, which points to the ArrayList?
> 
> 
> As always thanks. I posted this I have been stuck for ages.
> 
> Cheers,
> Matt
> 
> 
> 
> --
> Matthew Hutchinson
> Ph.D. Candidate
> Department of Spatial Sciences
> Curtin University of Technology
> GPO Box U1987
> Perth, Western Australia 6845
> 
> Visiting Scholar
> Department of Geography and Planning
> University of Akron
> Akron, Ohio USA



---------------------------------------------------------
Ernest Friedman-Hill  
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
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