Skip to Content.
Sympa Menu

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

maude-help AT lists.cs.illinois.edu

Subject: Maude-help mailing list

List archive

Re: [Maude-help] question on rule writing


Chronological Thread 
  • From: Steven Eker <eker AT csl.sri.com>
  • To: maude-help AT cs.uiuc.edu
  • Subject: Re: [Maude-help] question on rule writing
  • Date: Mon, 7 Feb 2011 12:15:58 -0800
  • List-archive: <http://lists.cs.uiuc.edu/pipermail/maude-help>
  • List-id: <maude-help.cs.uiuc.edu>
  • Organization: SRI International

WIthout the signature, it's hard to know what you are trying to do or what a
given pattern will match. Always post complete modules.

If you are just manipulating data in a functional way (instead of changing
state with alternative possibilities that might have to be explored using
search or model checking) you are much better off using equations - they are
_much_ faster and allow common subexpression evaluation (with rules, common
subexpressions might evaluate differently in each occurrence).

Steven

On Monday 07 February 2011 10:32:03 am Scott Christley wrote:
> 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
>
> _______________________________________________
> Maude-help mailing list
> Maude-help AT cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/maude-help
>




Archive powered by MHonArc 2.6.16.

Top of Page