Print

Print


On May 16, 2013, at 4:20 AM, Bojan Janisch wrote:

> how do I define which node has to be root? I don't get it from the manual, 
> seems like it were mentioned in the beginning of chapter 5.2.11 but were 
> completely skipped at the examples. 

You're right, I had skipped it because it was the default setting.  I shouldn't have done that, so I've updated the manual.  Here's what I added:


> Next we need to say what kinds of nodes are permitted as the root of the tree.  We do this by specifying the tree's return type.  For a node to be permitted as the root of the tree, it must have a return type compatible with this tree return type.  Let's say that we want our tree to only have root nodes which have a return type of nil (no boolean allowed):
> 
> gp.tc.size = 1
> gp.tc.0 = ec.gp.GPTreeConstraints
> gp.tc.0.name = tc0
> gp.tc.0.fset = f0
> 
> # Here we define the return type of this GPTreeConstraints
> gp.tc.0.returns = nil
> 
> As it so happens, this is what we already have by default, so putting it all here is a bit redundant.

In short: the root is restricted to those GPNodes whose return type is type-compatible with the return type of the GPTree.


> It would be great if someone got an example of a hierarchical GPTree and
> could explain how a GPType is bounded to a GPConstraint and so to a GPNode,
> because this I also didn't understand from the manual. 

Constraints contain GPType names as part of their parameters.  For example, a GPNodeConstraint which returns type foo and accepts a left child of type foo and a right child of type bar would be written as:

gp.nc.0 = ec.gp.GPNodeConstraints
gp.nc.0.name = blah
gp.nc.0.returns = foo
gp.nc.size = 2
gp.nc.child.0 = foo
gp.nc.child.1 = bar

You specify that a given kind of GPNode uses this constraints in your function set:

gp.fs.0.func.4 = ec.app.myapp.MyGPNode
gp.fs.0.func.4.nc = blah

Basically the same thing goes for the trees (GPTree and GPTreeConstraints)

Sean