Metatheory.jl icon indicating copy to clipboard operation
Metatheory.jl copied to clipboard

is this the best way to `reverse(r::Rule)`?

Open anandijain opened this issue 3 years ago • 1 comments

I haven't really read through this repo, but I didn't see an easy way to take @rule ~x => exp(~x) to @rule exp(~x) => ~x. This was the hack I came up with

myreverse(r::Metatheory.Rules.AbstractRule) = myreverse(r.expr)

function myreverse(rex)
    args = rex.args
    newex = Expr(:call, args[[1, 3, 2]]...)
    eval(:(@rule $newex))
end

it seems to work fine but it might be a bad way of doing it

anandijain avatar May 31 '22 17:05 anandijain

Hi anand. This is possible and fairly easy. I can add a function overloading Base.inv, but you have to know that inverting a rule that has more variables on the lhs. than the rhs will result in an error. (e.g., @rule f(~x, ~y, ~z) => g(~x) is not invertible)

0x0f0f0f avatar Jul 02 '22 11:07 0x0f0f0f