Table of Contents
Parametrized
Parametrized pattern enables to bound query variables to parameters of the node pattern. E.g. Sphere(5) Sphere(r) both 5 and r are declared query variables, yet they are used differently:
- Sphere(5) matches Sphere where the value of the parameter is exactly 5.
- Sphere(r) matches all Spheres and bound the parameter to the query variable
r, making it available to use.
In the case of RGG, most 3d objects, turtle commands, and user defined modules the parametrized pattern is built around the fields of the objects.
For instance:
module Organ(float size, int age); // the pattern: Organ(float, int) is available void run() [ Organ(5,2) // bind 5 to the field size, and 2 to the field age F(3) // bind 3 to the field length ==>; ]
Custom pattern
Patterns are declared from a class that extends UserDefinedPattern. Each concrete subclass of UserDefinedPattern declares a user-defined pattern, where the term “user-defined” distinguishes such a pattern from built-in patterns of the XL programming language. The signature (number and types of parameters) of a user-defined pattern is given by a special method named signature which has no further purpose. The @In and @Out annotations in the signature are needed when textually neighboring patterns are connected.
Thus, to declare a parametrized pattern, an Object X must declare a nested class that extends UserDefinedPattern.
For example:
class X extends Node { float attr; static class Pattern extends UserDefinedPattern { private static void signature(@In @Out X node, float attr) {} public int getParameterKind (int index){ return 0; } public Matcher createMatcher(de.grogra.xl.query.Graph graph, XBitSet bound, IntList requiredAsBound) { if (!bound.get (0)) { requiredAsBound.add (0); } return NULL_MATCHER; // matcher used by the type pattern // define you own matcher here } } }
make the pattern X(a) whose node type is X and which has a parameter of type float.
