On Sep 28, 2008, at 4:57 PM, Levent Kent wrote:


Hi,

I am a new user fo Jess and try to get some understanding for the engine.
I cant understand why the code below does not work.

Well, the short answer is that the syntax is bad. If the Jess parser sees a pair of parentheses, it will assume that they surround a function call, *except* for certain special situations. For example, here:


(deffacts graph-links3
   (link3 (gnode3 0 0) (gnode3 2 1))
   )


If "link3" isn't declared to be an unordered template, then when the parser sees the "(gnode", it assumes gnode is a function that should be called to obtain data for the fact.



(deffacts graph-links
   (link (start (gnode (x 0) (y 0))) (end (gnode (x 2) (y 1))))



Here, "link" has slots "start" and "end". While parsing slot data, again, the parser sees "(gnode" and interprets that the same way, as a function to be called to supply the slot data.

Although there's no way to do what you want inside a deffacts construct, it is possible to assert your links and gnodes in the same statement (but see below.) You just need to use a function call to return the slot data. "assert" is a function, and it does the right thing, so let's use it. For example

(assert (link (start (assert (gnode (x 0) (y 0))))
              (end   (assert (gnode (x 2) (y 1)))))

So we explicitly assert three facts here; we use the return value of "assert" to tie the gnodes to the link.

Now, one problem here is that if you have many such facts, I imagine you'll have links that share some nodes. If that happens, this syntax isn't going to work for you; asserting a fact that already exists will return FALSE. Therefore you might need to factor the gnode assertions out:

(bind ?n00 (assert (gnode (x 0) (y 0))))
(bind ?n21 (assert (gnode (x 2) (y 1))))
(bind ?n02 (assert (gnode (x 0) (y 2))))

(assert (link (start ?n00) (end ?n21)))
(assert (link (start ?n02) (end ?n21)))

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, 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]
--------------------------------------------------------------------

Reply via email to