How to construct fail using rule

2 views
Skip to first unread message

Seyed H. HAERI (Hossein)

unread,
Feb 5, 2012, 9:18:19 AM2/5/12
to ki...@googlegroups.com
Dear all,

Is there any way to simulate the combinator fail using Kiama's rule combinator?

TIA,
--Hossein

--------------------------------------------------------------------------------------------------------------

Seyed H. HAERI (Hossein)

Research Assistant
Institute for Software Systems (STS)
Technical University of Hamburg (TUHH)
Hamburg, Germany

ACCU - Professionalism in programming - http://www.accu.org/
--------------------------------------------------------------------------------------------------------------

Tony Sloane

unread,
Feb 5, 2012, 12:56:10 PM2/5/12
to ki...@googlegroups.com
On 05/02/2012, at 3:18 PM, Seyed H. HAERI (Hossein) wrote:

> Is there any way to simulate the combinator fail using Kiama's rule combinator?

rule (f) is constrained by applicability of the partial function f, so you can get fail if f is a partial function that is never applicable. I don't think it's possible to build one of those with the function shorthand in Scala, but you could create one specifically using the PartialFunction class (just make the isDefinedAt method always return false).

A far easier method to get fail is to use one of the strategy* variants of rule. E.g.,

def strategyf (f : Term => Option[Term]) : Strategy

This function exposes the success/fail result to your control using an Option return type for the argument function. strategyf (f) fails exactly when f returns None, and succeeds with t when f returns Some (t). Therefore you can get fail by writing

strategyf (_ => None)

Tony

Seyed H. HAERI (Hossein)

unread,
Feb 5, 2012, 4:22:57 PM2/5/12
to ki...@googlegroups.com
Hi Tony,

>> Is there any way to simulate the combinator fail using Kiama's rule combinator?
>
> rule (f) is constrained by applicability of the partial function f, so you can get fail if f is a partial function that is never applicable.

That's exactly what I thought but...

> you could create one specifically using the PartialFunction class (just make the isDefinedAt method always return false).

... I didn't make thus far. Nice job. :)

> A far easier method to get fail is to use one of the strategy* variants of rule.  E.g.,

<snip>

Sure. As a riddle, this only occurred to me and I though it would be
interesting to share... :)

Thanks,

Reply all
Reply to author
Forward
0 new messages