Some more thoughts on pattern matching

I've just checked in the code for a PatternMatchingNode and a SingleNotMatchNode. I'm still not sure the implementation I've done is a good idea (rulecompiler.py is coming close to 1000 lines of not-so-simple-code). I went with:

>>> @pyRete.Rule
... def some_rule(obj = SomeObject):
... if obj(foo == 1, bar == 2, baz == 3):
... pass
Which, at least, won't raise a SyntaxError outside of pyRete context. In Clips, pattern matching looks more "natural":
(defrule some-rule
(SomeObject (foo 1) (bar 2) (baz 3))
=> )
Unfortunately, there's no way to *not* bind an object to a variable in pyRete so a more correct Clips translation is:
(defrule some-rule
?obj <- (SomeObject (foo 1) (bar 2) (baz 3)) => )
Which still looks a lot better than what I've done :-)

However, looking at the big picture. I really *love* the fact that many of my rules now are shorter and simpler and I guess that's what it's all about.

Inga kommentarer: