ERights Home elang / kernel 
Back to: VarPattern x On to: Such-That Pattern

Ignore Pattern


The ignore pattern always successfully matches against anything and does nothing.

BNF:
"_"
XML DTD:
<!ELEMENT ignorePattern EMPTY>
Java:
Pattern match implicitly succeeds without generating any code
Example:
Checks that we have a pair while extracting the first element and ignoring the second element.
def [first, _] := pair
in Kernel-E:
def [first :any, _] := pair
in XML:
<defineExpr>
    <listPattern>
        <finalPattern>
            <Noun>first</Noun>
            <Noun>any</Noun>
        </finalPattern>
        <ignorePattern/>
    </listPattern>
    <Noun>pair</Noun>
</defineExpr>
in Java:
Object specimen = pair;
if (!isList(specimen)) { throw(...); }
Integer len = E.toInteger(E.call(specimen, "size"));
if (len.intValue() != 2) { throw(...); }

final Object first = E.call(specimen, "get", 0);
# we hope to optimize this out this last useless call
E.call(specimen, "get", 1);

 

x
 
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: VarPattern x On to: Such-That Pattern
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign