Content deleted Content added
m changed URL |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 36:
For example, a simple class in C++ would have the form
<
class point {
int x, y;
};
</syntaxhighlight>
In BETA, the same class could be represented by the pattern
<!-- This isn't Pascal, but syntax is similar -->
<
point: (#
x, y: @integer
#)
</syntaxhighlight>
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.
As another comparison, a procedure in C++ could have the form
<
int max(int x, int y)
{
Line 63:
}
}
</syntaxhighlight>
In BETA, such a function could be written using a pattern
<!-- This isn't Pascal, but syntax is similar -->
<
max: (#
x, y, z: @integer
Line 78:
exit z
#)
</syntaxhighlight>
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.
|