Hi Eric,
Jess will automatically convert between fact-ids and integers as
necessary, but only in the context of a Jess function call; as soon as
you start passing things to Java functions, the automatic conversions
aren't done. They really can't be, or you'd have a combinatorial
explosion of possibilities evry time you invoked a Java method.
The (integer) function will convert any numeric type to an int,
including fact-ids - so just use (integer ?x) instead of ?x in your
example, and it'll work.
Editorial comment: long ago, when I was first learning CLIPS, the
precise nature of fact-ids was something that confused be greatly. You
could sometime use integers as fact-ids, and fact-ids as integers, but
sometimes not. None of the documentation explained any of the
rules. Anyway, I suppose I should have learned from this experience
and made Jess more sensible in theis regard, but I didn't. Maybe,
perhaps, there doesn't even need to be the notion of a fact-id as a
distinct type of value; maybe they should just uniformly be integers.
Does anybody see anything wrong with that? I don't.
I think [EMAIL PROTECTED] wrote:
>
> This is a followup to a message I sent to the userlist about a week ago asking
> if anyone had been able to retrieve the text form of a jess fact as a string,
> given its fact id.
>
> I am now able to get, as a java string, a fact. I made the
> jess.Rete.findFactByID method public, and was able to make a call like:
> (call (new jess.Fact (call (engine) findFactByID 0) (engine)) toString)
>
> findFactByID will return a ValueVector from of a fact given the integer fact
> ID. you can make it into a jess.Fact and then call the toString method. fine
> fine fine.
>
> But now, the big question.
>
> How do I turn a variable that has been bound to a fact-ID into the
> corresponding integer?
>
> for example
> (defrule foo ?x<-(foo ?)=>
> (printout t
> (call (new jess.Fact (call (engine) findFactByID ?x) (engine))
> toString)
> crlf)
> )
>
> this bombs out, because ?x is not an integer.
>
> In reading the README.html file, I noticed that the definition of what a jess
> variable is not all too clear. Originally, in section 2.7, it is stated that
> a variable can refer to "an atom, number or string", but later when referring
> to pattern bindings (2.15.1) it is stated that the variable is bound to a fact-id.
>
> In calls to retract, there seems to be an implicit conversion because the
> documentation states that retract takes integers as arguments, but it also
> works with variables bound to fact-IDs. Additionally, calling (new
> java.lang.Integer ?x) will fail if ?x is bound to a fact id.
>
> anyway. I am confused and lost in a sea of "but all I want to do is be able
> to call (facttostring <factid>) and have it return a string..."
>
> Thanks for all the help,
> Eric Eslinger
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list. List problems? Notify [EMAIL PROTECTED]
> ---------------------------------------------------------------------
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9214 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------