On Mar 22, 2007, at 11:42 AM, Shi Paul wrote:
Hi there,
I'm a novice, so pls forgive me if I ask something stupid. I'd like
to add an user function which is doing exactly the same thing as
(assert (abc(slot1 ?s1)(slot2 ?s2))). The parameter for the fact I
got within that function (vv.get(1)) is an instanceof FuncallValue,
how could I turn that parameter into a Fact or maybe a String, so
that I can use engine.assertFact(xx) or engine.assertString(xx)?
Every set of parentheses in Jess code denotes a function call...
except when they don't. These special cases where they don't are
traditionally (in Lisp) called "special forms." Special forms are
handled by the parser itself. "defrule" is a special form, as are
other constructs like 'deftemplate', 'defquery', etc. "assert" is
also a special form, because its arguments are facts, not function
calls. In other words, you can't do what you're asking, because the
parser is going to have already decided your fact, above, is a call
to function "abc" with calls to "slot1" and "slot2" as arguments.
Because Jess does extremely late binding, the fact that these
functions don't exist won't be determined until you invoke the
functions by calling Value.resolveValue() or any of the xxxValue()
functions that return a scalar like symbolValue() or intValue().
Strictly, the only way to do what you want is by modifying the parser
itself (the class jess.Jesp).
But if you're willing to live with the fact that the parser won't
error-check your facts (because it doesn't know they are facts) I can
actually describe a hack that *would* work. The argument to your
function will look like a FuncallValue, and you can call funcallValue
() to get a jess.Funcall. This latter class is a subclass of
ValueVector. The first element in the ValueVector is the name of the
function, and the later elements are the arguments. So what you'd
have to do is take the name of the top-level Funcall, and use that as
the "head" of the fact; then collect all the nested Funcalls; each of
their names will actually be a slot name, and their first (and only)
argument will be the slot value. Given these values, you can build a
jess.Fact yourself and assert it.
Gross, huh?
---------------------------------------------------------
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://www.jessrules.com
--------------------------------------------------------------------
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]
--------------------------------------------------------------------