Your problems don't require an understanding of the *engine*; it's just the
Jess syntax you're grappling with. The deffacts construct contains - after
the name - a list of facts. (The syntactic pattern given in the Jess User
Manual in section 17.1, deffacts, is slightly in contradiction with the
syntax shown for the assert function, in section 16.21, but here are the
correct patterns):

deffacts-construct ::= ( deffacts deffact-name ["comment"] fact* )
assert-function ::= ( assert fact+ )
fact ::= ( template-name slot-definition* )
slot-definition ::= ( slot-name expression* )

Please note that a fact is *not* an expression in the sense of "something
that returns a value"; hence, what syntactically represents a fact cannot be
used within another fact's slot construction. Since you want to represent
your link facts as pairs of references to gnode facts, you need something
that creates a fact *and* returns a reference to that fact. This, however,
is exactly what the assert function does for you.

You could use a deffacts construct with assert calls in the appropriate
slots, but I don't think that this would be a good idea since almost all
graphs have nodes that sprout more that one link - this requires that you
use the very same reference in more than one place, and you can't do that
using assert. (Basic Law: Creating another fact identical to an existing one
just isn't possible - assert returns FALSE.)

Thus, the only path that leads to your graph is by using assert to make some
gnode facts, storing the return values in variables and using them as slot
values in assert calls creating links.

I'd prefer the gnode and link templates with two slots each to the ordered
fact forms. So you'd write calls like these:

(bind ?n_1_1 (assert (gnode (x 1)(y 1))))
(bind ?n_2_2 (assert (gnode (x 2)(y 2))))
(bind ?l_1_1_2_2 (assert (link (start ?n_1_1)(end ?n_2_2))))

HTH
-W

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Levent Kent
Sent: Sonntag, 28. September 2008 22:57
To: [email protected]
Subject: JESS: How to use templates inside facts


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.

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

Here, I am trying to describe links of nodes with 2 coordinates.
How should I do that?

I also tried this version:
(deftemplate gnode (slot x) (slot y))
(deftemplate link (slot start) (slot end))

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

I am always geetıng the error message:
Jess reported an error in routine Funcall.execute
    while executing (gnode3 0 0)
    while executing assert from deffacts MAIN::graph-links3
    while executing (reset).
  Message: Undefined function gnode3.

or

Jess reported an error in routine Funcall.execute
    while executing (gnode (x 0) (y 0))
    while executing assert from deffacts MAIN::graph-links
    while executing (reset).
  Message: Undefined function gnode.

Some little help would save me from confusion.

I hope this message will be accepted by the mailing list, because I am not
sure if my messages are delivered successfully.

Thanks,

Levent
--
View this message in context:
http://www.nabble.com/How-to-use-templates-inside-facts-tp19715452p19715452.html
Sent from the Jess mailing list archive at Nabble.com.

Reply via email to