Skip to Content.
Sympa Menu

maude-help - [Maude-help] question on rule writing

maude-help AT lists.cs.illinois.edu

Subject: Maude-help mailing list

List archive

[Maude-help] question on rule writing


Chronological Thread 
  • From: Scott Christley <schristley AT mac.com>
  • To: maude-help AT cs.uiuc.edu
  • Subject: [Maude-help] question on rule writing
  • Date: Mon, 07 Feb 2011 12:32:03 -0600
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/maude-help>
  • List-id: <maude-help.cs.uiuc.edu>

Hello,

I'm writing some rules where I want to add items to a "list" of things. In
the case of when the "list" is empty then I want to create the list (kind of
like an initial condition or tail-end of recursion). Otherwise when the list
is already there then I just want to add to it. So I'm writing two rules,
one non-conditional rule for when the list is not there, and another
conditional rule for when the list is there. But I'm worried that one rule
(the non-conditional rule) is too general and always matches.

For example I have these two rules, where I match a "foo" in the first part,
then I add "bar" to a list of results for "foo". The first non-conditional
rule creates the first "result" while the second conditional rule adds "bar"
to the existing list of results.


rl [test] : test( X foo, answers(Y) )
=> test( X, answers(Y result(foo, bar)) ) .


crl [test] : test( X foo, answers(Y result(Z, W)) )
=> test( X, answers(Y result(Z, add(W, bar))) )
if Z = foo .



My concern is that it seems that the non-conditional rule will always match.
Is this true? Or will a conditional rule which matches always override a
more general rule?

What is the correct way to write such rules? I can think of one change by
changing the non-conditional rule into a conditional rule that checks for
non-existence, something like this:


crl [test] : test( X foo, answers(Y) )
=> test( X, answers(Y result(foo, bar)) ) .
if not(contains(foo, Y)) .


thanks
Scott





Archive powered by MHonArc 2.6.16.

Top of Page