Thank you for providing the examples!
> (%i1) matchdeclare (xx, foop, yy, barp);
> (%o1) done
> (%i2) foop (e) := e = 'foo;
> (%o2) foop(e) := e = 'foo
> (%i3) barp (e) := atom (e) and not foop (e) and e # 1;
> (%o3) barp(e) := atom(e) and not foop(e) and e # 1
> (%i4) defrule (r1, xx*yy, HEY_LOOK (xx, yy));
> yy xx partitions `product'
> (%o4) r1 : xx yy -> HEY_LOOK(xx, yy)
> (%i5) r1 (2*foo);
> (%o5) HEY_LOOK(foo, 2)
> (%i6) r1 (x*foo);
> (%o6) HEY_LOOK(foo, x)
> (%i7) r1 (x*y*z*foo);
> (%o7) HEY_LOOK(foo, x y z)
Doesn't the rule, or the predicate, or the pattern make a mistake here?
The pattern yy of type barp was constructed to match an atom, which is
not fulfilled here? Shouldn't the last bit return something like
x*y*HEY_LOOK(foo, z), or with any permutation of the {x,y,z}?
defrule (r1, xx*yy, HEY_LOOK (xx, yy, barp(yy)))$
r1 (x*y*z*foo);
(%o14) HEY_LOOK(foo,x*y*z,false)
shows that the predicate on the "matched" part does not apply.
I'll try to understand the code provided by Richard Fateman and see
whether I can advance a round.
Regards,
Martin