Pattern matching
One of the things I've "just" started missing in pyRete is an easy way of doing pattern matching. At the moment you've got to test each property in a separate expression, like so:
>>> @pyRete.RuleI'd like to introduce some way of doing those three tests as one pattern match, similar to how it's done in Clips. I've been been thinking about this for some time and I've tried to stay away for as long as I've could because there's no "natural" way of expressing a pattern to match in Python.
... def some_rule(obj = SomeObject):
... if obj.foo == 1 and obj.bar == 2 and obj.baz == 3:
... pass
The only thing that I've been able to come up with is:
>>> @pyRete.Rulewhich seems, sort of, OK. But from a Python syntax point of view it's not so good. It might even be weird. Maybe I should just ignore Python syntax and use { and } to disambiguate:
... def some_rule(obj = SomeObject):
... if obj(foo = 1, bar = 2, baz = 3):
... pass
>>> @pyRete.RuleI don't know. I'll have to think abput this some more I guess.
... def some_rule(obj = SomeObject):
... if obj{foo = 1, bar = 2, baz = 3}:
... pass
Inga kommentarer:
Skicka en kommentar