Sorry, but this isn't possible in current versions of Jess. The slot
names in patterns must be known at the time that a rule is compiled;
they're converted into numeric indices at that time. Therefore slot
names can't be matched or wildcarded.
The closest you could come would be to write something like this:
(defrule newMessage
?message<-(message ?p ?t)
?participant<-(participant (nom ?p))
=>
(bind ?val (fact-slot-value ?participant ?t))
(eval (str-cat "(modify " ?participant " (" ?t " " (+ ?val 1) "))"))
(retract ?message)
)
This doesn't rely on matching on an unknown slot, and buildsthe
(modify) funcall only after the slot name is known.
I think [S_bastien] GEORGE wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi all,
>
> I have a question and I don't know if it's possible to resolve it
>
> I explain me with an example
>
> (deftemplate participant "a participant"
> (slot nom (type STRING))
> (slot Question (default 0))
> (slot Answer (default 0))
> (slot Aknowledge (default 0))
> ...
> )
>
> The I assert a participant
> (assert (participant (nom "Duke")))
>
> Inside a rule, I want to access a slot with a variable
>
> (defrule newMessage
> ?message<-(message ?p ?t)
> ?participant<-(participant (nom ?p) (?t ?val) ; here's the problem
> =>
> (modify ?participant (?t (+ ?val 1)) ) ; and there's too
> (retract ?message)
> )
>
> and then I assert a message
>
> (assert (message "Duke" Question))
>
> But it doesn't work ...
> The problem is (participant (?t ?val))
> How to transform a variable into a name of a field ?
>
> Thanks for answers or comments
>
> S_bastien George
>
>
> ---------------------------------------------------------------------
> 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]
---------------------------------------------------------------------