Content deleted Content added
m Clarified the grammar a little (there was no "one hand" to imply an "other hand") |
→Patterns: SyntaxHighlight |
||
Line 42:
</source>
In BETA, the same class could be represented by the pattern
<!-- This isn't Pascal, but syntax is similar -->
<source lang="pascal">
point: (#
x, y: @integer
#)
</
That is, a class called ''point'' will have two fields, ''x'' and ''y'', of type [[integer]]. The symbols ''(#'' and ''#)'' introduce patterns. The colon is used to declare patterns and variables. The ''@'' sign before the integer type in the field definitions specifies that these are integer fields, and not, by contrast, references, arrays or other patterns.
Line 64 ⟶ 65:
</source>
In BETA, such a function could be written using a pattern
<!-- This isn't Pascal, but syntax is similar -->
<source lang="pascal">
max: (#
x, y, z: @integer
Line 76 ⟶ 78:
exit z
#)
</
The ''x'', ''y'' and ''z'' are local variables. The '''enter''' keyword specifies the input parameters to the pattern, while the '''exit''' keyword specifies the result of the function. Between the two, the '''do''' keyword prefixes the sequence of operations to be made. The conditional block is delimited by ''(if'' and ''if)'', that is the '''if''' keyword becomes part of the opening and closing parenthesis. Truth is checked through ''// True'' within an if block. Finally, the assignment operator ''->'' assigns the value on its left hand side to the variable on its right hand side.
|