Eric and I were discussing some Stratego code and we came up with a
useful extension to the standard strategies generated for invoking
dynamic rules (bagof-Foo, once-Foo, etc). The new strategy would be
thread-Foo for a dynamic rule Foo.

The idea is that it is in general useful to apply a sequence of
dynamic rules, but not produce all possible results, but thread every
result to the next dynamic rule invocation.

So, suppose that you have two dynamic rules defined:

Foo : x -> (1, x)
Foo : x -> (2, x)

With these two rules defined, applying 0 will result in
(2, (1, 0)).

In this way, you can apply a series of dynamic rules to a term. Note
that you can achieve this with repeat(once-Foo) as well, but once-Foo
will remove the rule from the environment, which is not always wanted.

I’ve implemented this in a small sample (attached), which also
includes a demo of thread versus bigthread (which is comparable to
bigbagof versus bagof).

The output is:
———————————————————
Thread Foo: [“Ext3”,“Ext4”]
Bigthread Foo: [“Ext1”,“Ext2”,“Ext3”,“Ext4”]
———————————————————

Is it ok to add this to the compiler? The generation scheme is trivial :)

Cheers,

Submitted on 3 February 2006 at 00:29

Log in to post comments