Thank you -- that's the exact solution I was searching for, and it works
perfectly.
Just out of curiosity, is there a particular reason that the
Userfunction you provided also implements the Serializable interface? I
know the example user function implementation online just implements the
Userfunction interface and not the Serializable one. When we make our
own Userfunctions, is it good practice for us to implement Serializable
as well?
Thanks again for the help!
- Eithon
Ernest Friedman-Hill wrote:
On Mar 14, 2007, at 8:40 PM, Eithon Cadag wrote:
Hi all,
Is binding a lambda function to a variable, and then using that
function, possible in Jess?
You know, I don't think there *is* a way to do this. You can use the
"map" function, but you'll get back the answer inside a list, which
isn't terribly convenient. The "apply" function should be modified to
handle lambdas as well as names. Here's a version of "apply" which
does the right thing:
--------------------------------------------------------------
class Apply implements Userfunction, Serializable {
public String getName() {
return "apply";
}
public Value call(ValueVector vv, Context context) throws
JessException {
Userfunction uf = vv.get(1).functionValue(context);
ValueVector args = new ValueVector();
args.add(uf.getName());
for (int i = 2; i < vv.size(); i++)
args.add(vv.get(i));
return uf.call(args, context);
}
}
--------------------------------------------------------------
Then (apply ?fnc 2) would return "4".
---------------------------------------------------------
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]
--------------------------------------------------------------------
--------------------------------------------------------------------
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]
--------------------------------------------------------------------