To match the contents of the list, you use a "multifield" -- a
variable starting with a "$" character:
(defrule display
(B::acceptedPapers $?papers)
=>
(printout t $?papers crlf))
To modify a fact, you must always use the "modify" function. This
function operates only on unordered facts, which means that the
ordered fact you're using here won't work. You need to define a
template:
(deftemplate B::acceptedPapers (multislot papers))
Then you write the rule to match the existing slot contents and modify
the slot:
(defrule accept
?cmd <- (accept ?newPaper)
?acceptedPapers <- (B::acceptedPapers (papers $?oldPapers))
=>
(modify ?acceptedPapers (papers ?newPaper ?oldPapers)
(retract ?cmd)
)
I added a line to retract the "accept" fact so you don't get an
infinite loop.
On Apr 14, 2009, at 6:06 AM, Aycan Adal wrote:
Hello everyone,
What I am trying to do is doing list operations like inserting,
removing getting the first element and so... on the lists that are
on the working memory. Here is how I try:
(deffacts B::facts
(B::acceptedPapers (create$))
)
and then:
(defrule accept
(accept ?paper)
?acceptedPapers <- (B::acceptedPapers)
=>
(insert$ ?acceptedPapers 1 ?paper)
)
and when accept is fired, I get the error:
Jess reported an error in routine Value.listValue
while executing (insert$ ?acceptedPapers 1 ?paper)
while executing defrule accept.
Message: '<Fact-12>' is a fact, not a list.
How can I keep a list of accepted papers in this case and add and
remove from it? I couldn't get it to work no matter how I tried. So
any help is appreciated.
Regards,
Aycan Adal
---------------------------------------------------------
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].
--------------------------------------------------------------------