2007-01-30

source_code =~ s\TestNode\ExprNode\g;

Silly me!

I realized yesterday that what I've been talking about as a TestNode is actually just part of what the TestNode can do in CLIPS. I also think I've implemented it a bit differently because I saw other things that I wanted to use it for.

Therefore, I've gone through the source code and renamed TestNode to ExprNode (I'll explain why in a little bit). I've also implemented what I believe to be a better match to a CLIPS TestNode and added it to pyRete.

The new TestNode does actually perform a Test. It takes a single Python expression and evaluates it with the variable bindings given in the Token passed to it. If the expression evaluates to True the Token is passed on to the successors. The TestNode does not have any restrictions. You can do things like call functions or evaluate lambda expressions (none of which is normally allowed).

The reason I kept the old "TestNode" but renamed it as ExprNode is because what it does is that it creates a new local variable which end up in the Rete Network (as an AlphaMemory) and if you perform tests on it; the tests become AlphaNodes.

Initially I had hoped that this type of test was all that was needed (and anyway, all that I was going to support) but the first tests I started to write using this type of Node quickly showed that full-fledged TestNodes are actually quite a good thing.

Inga kommentarer: