how to implement a counter in tefkat
so that i get unique names link1,link2 ......
gaurav
> how to implement a counter in tefkat
> so that i get unique names link1,link2 ......
A very interesting question. Assuming that the things you want to
"count" correspond to a set of source instances that can be matched in
a single query, then the rule below should do what you want.
More specifically, the rule is intended to make one Link instance for
every Bar instance that is referenced by the (singleton) Foo. It will
not work as intended (i.e., uniquely numbered names for the Link
instances) if there is more than one Foo instance.
In your specific case, I imagine there will only be a single root
instance, BusinessProcessDiagram and you can use a path expression to
do multiple steps to navigate to the relevant source items to
construct list. Eg WHERE BusinessProcessDiagram diag AND list =
diag.foo.bar.baz{}
TRANSFORMATION example: src -> tgt
RULE makeLinks
WHERE Foo root // match the singleton root instance
AND list = root.reference{} // compute the (ordered) set of
source instances
AND element = root.reference // "iterate" over the individual elements
AND i = list.indexOf(element) // find its index in the list
MAKE Link l FROM link(element) // make one Link per element
SET l.name = append("link", i) // set its name
;
If you're just after unique names, then there is a simple solution:
RULE links
FORALL Foo f
MAKE Link l
SET l.name = append("link", f.hashCode())
;
Cheers,
michael
MAKE Link l FROM link(element)
in above statement , what does link(element) means?
thanks
Brajesh
On Jan 31, 5:54 am, "michael lawley" <mich...@lawley.id.au> wrote:
In short, it means make one Link instance per unique element instance.
michael
RULE R1
WHERE p(x)
MAKE Foo y FROM f(x)
;
RULE R2
WHERE q(a)
MAKE Foo b FROM f(a)
Both rules use the same injection name, 'f', meaning that both rules
will 'MAKE' the same object if x = a. However if the injections have
different names, then the target objects will be distinct. So for
example, the following three rules all create distinct ys:
RULE R1
WHERE p(x)
MAKE Foo y FROM f(x)
;
RULE R2
WHERE q(x)
MAKE Foo y FROM g(x)
;
RULE R3
WHERE r(x)
MAKE Foo y FROM f(x, "hello")
;
Finally, if you don't specify an injection (a FROM part) in a rule,
then one gets inserted implicitly for you based on the variables that
appear in the FORALL part of the rule.
RULE R
FORALL Foo x, Bar y
MAKE Baz z
;
is essentially equivalent to:
RULE R1
FORALL Foo x, Bar y
MAKE Baz z FROM f(x, y)
;
i.e. you get a unique z for each unique combination of x and y. This
means that all the following rules have different semantics.
RULE R2
FORALL Foo x
WHERE Bar y
MAKE Baz z
;
RULE R3
FORALL Bar y
WHERE Foo x
MAKE Baz z
;
RULE R4
WHERE Foo x AND Bar y
MAKE Baz z
;
In rule R2, you get a unique z for each unique x (regardless of how
many ys there are), in R3 you get a unique z for each unique y, and in
R4 you get just the one z. Of course you can override this by
explicitly adding your own FROM part.
Hope this helps,
-David
PS If you like logic programming, then a quick explanation is that the
FROM clause describes the logical identity of target objects in terms
of a function symbol.