I think Jack Kerkhof wrote:
> Thank you for that clarification, Ernest.
>
> A couple of follow-ups:
> 1) NOT to belabor the issue, but I'll assume that the not 'function' behaves as the
> test function in that non TRUE or FALSE atoms are evaluated to TRUE (resulting in
> the not function returning the atom FALSE), correct?
>
Yes, this is correct. It's actually documented in the manual, this
time (see section 8.97 in the Jess 6.x manual).
> 2) ... What is the relative performance of coding (not (test xxx))
> vs (test (not xxx)), particularly where this same pattern occurs in
> multiple rules?
Well, this is a good question. First of all, note that we're only
talking about (not (test)) vs (test (not)). (not (some-other-pattern))
can do all sorts of stuff that (test (not)) can't, of course.
In general (test (not)) is going to be more efficient, for several
reasons. (not) nodes (the Java class is called NodeNot2) have to store
the tokens they receive, while (test) (or NodeTest) nodes don't. So
there's some unneeded overhead associated with storing tokens if you
use (not (test)). Secondly, NodeNot2's cannot be shared in the Rete
network (technically, the reason is that each NodeNot2 has to keep
independent negation counts in the tokens it stores) whereas NodeTests
can. Thirdly, and becuase of the above, the tokens passed in to a
NodeNot2 have to be copied, since they may be modified. And lastly,
(not (test)) will create a NodeNot2 -and- a NodeTest, while (test
(not)) will create only the NodeTest.
Now, there may be some reasons why you'd want to write (not (test)),
but I actually can't think of any right now.
> Jack
>
> [EMAIL PROTECTED] wrote:
>
> > Hi Jack,
> >
> > The 'test' CE succeeds when the function call evaluates to a value
> > that is not the atom FALSE. I.e., other atoms, numbers, TRUE, external
> > addresses, etc, all succeed. Only the atom FALSE fails. This is an
> > excellent question, and I was surprised to find that the manual
> > doesn't state this specifically. It will now!
> >
> > Now, the 'not' CE is entirely different. The 'not' CE doesn't work
> > with function calls, it works with other CEs. If you write, as you do
> > below,
> >
> > (defrule foo1
> > ...
> > (not (str-index "foo" "foo was here"))
> > ...
> > (not (+ 1 1))
> >
> > these patterns will succeed as long as there are no -facts- which look
> > like (str-index "foo" "foo was here") or (+ 1 1). I.e., these CEs have
> > nothing whatsoever to do with the functions str-index or + despite
> > appearances. The functions will never be called.
> >
> > You can write (not (test (function-call))), though, and this is more
> > or less the same as (test (not (function-call))), but implemented
> > differently. In the first case, you're using the 'not' CE -- i.e.,
> > there's a 'not' node in the Rete network. In the second case, you're
> > using the 'not' function: i.e., the 'test' CE's evaluates a 'not'
> > function with a 'function-call' function call as an argument.
> >
> > I think Jack Kerkhof wrote:
> > > Hi all,
> > >
> > > What is the DEFINED behavior for CE's (I.E. 'not' & 'test') when they
> > > are passed a non-boolean value?
> > >
> > > Context:
> > >
> > > A number of the Jess functions return EITHER a boolean or some other
> > > value (I.E. str-index, member$, system...)
> > > When these are used in a CE, what is the DEFINED behavior when the
> > > function return value is non-boolean?
> > >
> > > Experimentation seems to indicate that the non-boolean value is
> > > generally evaluated to true, but I don't really see this documented, so
> > > I'm not sure how to properly handle such cases.
> > >
> > > In particular, what is the RIGHT way to code function patterns with two
> > > possible return types?
> > >
> > > A few examples:
> > >
> > > (defrule foo1
> > > (test (str-index "foo" "foo was here"))
> > > (test (> (str-index "foo" "foo was here") 0) )
> > > (not (str-index "foo" "foo was here"))
> > > (not (str-index "goo" "foo was here"))
> > > =>
> > > (printout t "index " (str-index "foo" "foo was here") " matches
> > > test, test >0, not, not goo!" crlf)
> > > )
> > >
> > >
> > > (defrule foo2-contrived-eg
> > > (test (+ 1 1)) ; Dont' try this at home - but jess does accept it...
> > >
> > > (not (+ 1 1))
> > > =>
> > > (printout t "1+1 both tests and not!" crlf)
> > > )
> > >
> > > The apparent overloaded behavior of test and not can be useful in some
> > > contexts, but is it legitimate?
> > >
> > > Jack
> > >
> > > (ps tested in jess 5.xxx)
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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]
> > > ---------------------------------------------------------------------
> > >
> >
> > ---------------------------------------------------------
> > Ernest Friedman-Hill
> > Distributed Systems Research Phone: (925) 294-2154
> > Sandia National Labs FAX: (925) 294-2234
> > Org. 8920, MS 9012 [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 (use your own address!) 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 9012 [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 (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------