Thanks, great idea for the defglobal.
When it comes to the rule name ( similar_rule ), what happens if this user
function was called multiple times simultaneously? Couldn't there be
problems with the rule over-writing itself? And wouldn't there be siilar
problems for the ?s1 variable?
Cheers,
Matt
On 5/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
You could use the "gensym" function to give you a unique symbol to use
for a variable name, and then use "build" to create your defglobal the
same way you've done here for the defrule; or use gensym to create a
symbol, but use it as a key to store your ArrayList with "store" and
"fetch".
I think Matthew Hutchinson wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi everyone,
>
> The following function is typical of the sort of code I'm writing in
Jess:
>
>
----------------------------------------------------------------------------------
> (defglobal ?*similar_result_array* = (new ArrayList 0) )
> (deffunction dynamic-similar-search (?p1 ?p2 ?p3 ?p4)
> (bind ?s1 (str-cat "(defrule similar_rule ("?p1" ("?p2" \""?p3"\")
> ("?p4" ?qwerty)) => (call ?*similar_result_array* add ?qwerty) )"))
> (build ?s1)
> (return ?*similar_result_array*)
> )
>
----------------------------------------------------------------------------------
>
> It basically just asserts a rule dynamically using some paraemters I
supply
> it. It also stores results in an ArrayList and then returns this object