 | | Interface Manipulation Package v4.0 (2008-06-25) |  | ©copyright |  |
imp.core
Class Functions.Rule
java.lang.Object
imp.core.Function
imp.core.Functions.Rule
- Enclosing class:
- Functions
public static class Functions.Rule
- extends Function
Defines a function defined by a pattern-matching rule.
THIS MECHANISM IS NOT YET VALIDATED IN THE PRESENT VERSION: DO NOT USE !!!
Pattern matching. In this context a pattern to be matched is defined by the following rules:
- the pattern -> result ; .. constructs an conditional expression which result is the 1st for which the pattern matches.
- if the pattern is an atomic value, it matches the expression if and only if they are equal,
- with a construct of the form $name, the variable of the given name takes the expression as value;
if the variable value is already defined both values must be equal for the match to succeed,
- a construct of the form $name : type is a shorthand for $name ; is(name, type)
- a construct of the form $name : pattern matches the pattern and instantiate the variable with the result
- a construct of the form pattern ; condition matches the leftward pattern and then tests if the rightward condition is true;
variables in conditions must be defined before (i.e. on the left-hand side of) the condition in order to have it instantiated,
- otherwise each pattern field/element must match each expression field/element
- a construct of the form { .. name = pattern ..} thus defines the fact that a field of the given match the given pattern.
- with a construct of the form name = pattern := value, the field receives a default value if not yet defined;
- with a construct of the form $$name, the variable of the given name takes the expression element tail sequence as value;
Pattern matching thus allows to test if an expression has a given form and verifies some properties, i.e. belongs to a domain of definition.
Typing variables.Here, the
type of a variable is simply defined by the evaluation of boolean expression,
i.e. a construct of the form
$name:condition Typing is thus not static but verified at execution time.
Instantiation.During pattern matching, the variables are set to values so that the expression to be matched is equal to the given pattern,
providing a
match-list() function.
E.g.: log(f(a, $u:*) ^ $v:*) matches log(f(a, b) ^ (n+1)) with the substitution {u = b, v = n+1}
Constructor Summary |
Functions.Rule(Value pattern)
Constructs a function defined a pattern-matching rule. |
Functions.Rule
public Functions.Rule(Value pattern)
- Constructs a function defined a pattern-matching rule.