ERights Home elang / kernel 
Back to: Match-Bind Expression On to: Hide Expression

Define Expression

Has a generalization of the conventional meaning -- evaluate the right hand expression and match it against the pattern on the left. We refer to the value of the right hand expression as the specimen. Should the match fail, the define expression throws a to-be-specified problem explaining the match failure.

"def" pattern ":=" eExpr
<!ELEMENT defineExpr (%pattern;, %eExpr;)>
When the pattern might fail, it is expanded to throw an exception rather than produce a boolean.
def c := a + b
in Kernel-E:
def c := a.add(b)
in XML:
in Java:

If "c" is simple:

    Object c =, "add", b)

If "c" is boxed:

    Object[] c_Box = {, "add", b) }

The throw must be happen as soon as match failure is detected, without any further pattern matching activity. Therefore, the define expression can avoid the double-definition issue which plagues the match-bind expression. Succeeding scopes only see successful bound variables. If the match succeeds, the value of the define expression is the specimen.

Technically, the right hand expression is also in scope of the left hand pattern. However, this raises the possibility of circular definitions. While the User-E language does allow such circular definitions, Kernel-E does not. In the Kernel-E define expression, the expression may not use any varibles by the pattern, and the patterns may not use any variable defined by the expression. Though this second restriction may now seem well motivated, the two together allows code which processes Kernel-E trees to treat the parts of a define expression as if they occur in the reverse order, ie, in their execution order.

Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
ERights Home elang / kernel 
Back to: Match-Bind Expression On to: Hide Expression
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign