3. Patterns

A pattern is a template that defines the structure of a class of objects. Invocation/execution of a pattern generates an object that has the structure specified by the ObjectDescriptor.

A pattern declaration has the form:

PatternSignature: ObjectDescriptor

where PatternSignature describes the signature of the pattern and ObjecDescriptor as defined in Section 2 on objects section describes the structure of the objects that may be generatede from the pattern.

The signature describes the name, parameters and return values of the pattern.

The signature may have one of 4 forms: unary, functional, binary or keyword.

Unary patterns

A unary pattern, is a pattern that has no arguments and no return value is specified. By default the return value is a reference to this.

Example

display:
  "Print this string\n".print

Functional patterns

A functional pattern, is a pattern that have a list of arguments specified in a functional style within brackets and separated by commas (‘,’). A list of return values may be specified – the default return value is a reference to this.

Example

max(x: var Integer, y: var Integer) -> z: var Integer:
   ...

Binary patterns

A binary pattern, is a pattern with one argument and a name consisting of a sequence of special symbols, like ‘+’, ‘*’, ‘$’, etc

Example

+ V: var Integer -> res: var Integer:
   ...

where '+' is the name of the pattern, V is the name of the parameter and res is the return value.

/&/ Q: ref T -> W: ref S:
   ...

where '/&/' is the name of the pattern, Q is the argument, and W is the return value.

The following reserved special symbols cannot be used in a binary pattern name: ':', ',', '.', '%', …

Keyword patterns

A keyword pattern, is a pattern where the name is a list of keywords separating the arguments of the pattern:

put(V: var integer):at[inx: var integer]:do{S:< Object}:
   ...

The name of the pattern is put:at:do. The parameters are V, inx and S.

Example

put(V: var integer):at[inx: var integer]:do{S:< Object}:
   ...

Grammar

<Pattern-Declaration> ::= <Simple-Pattern-Declaration>
<Simple-Pattern-Declaration> ::= <Signature>: <ObjectDescriptor>
<Signature> ::= <Unary-signature>
             |  <Functional-signature>
             |  <Binary-signature>
             |  <Keyword-signature>
<Unary-signature> ::= <name-decl>
<Functional-signature> ::= 
    <name-decl> '(' <Parameter> { ',' <Parameter> } ')'
<Binary-signature> ::= <symbol-decl> <Parameter>
<Keyword-signature> ::= 
   <name-decl> <LeftB> <Parameter> <RightB> <Keywords>
<Keywords> ::= { <FatComma> <LeftB> <Parameter> <RightB> }+
<LeftB> ::= '(' | '[' | '{'
<RigtB> ::= ')' | ']' | '}'
<name-decl> ::= name
<FatComma> ::= fatComma

<RightB> must match the preceding <LeftB> where '(' and ')' match, '[' and ']' match, and '{' and '}' match.

<Parameter> is described in Section 3.2 Pattern parameters.

name and fatComma are lexical symbols described in Section xxx.

Hello world