Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
BETA (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Patterns=== A major and peculiar feature of the language is the concept of patterns. In another programming language, such as [[C++]], one would have several classes and procedures. BETA expresses both of these concepts using patterns. For example, a simple class in C++ would have the form <syntaxhighlight lang="cpp"> 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 --> <syntaxhighlight lang="pascal"> point: (# x, y: @integer #) </syntaxhighlight> That is, a class called ''point'' will have two fields, ''x'' and ''y'', of type [[integer (computer science)|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 <syntaxhighlight lang="cpp"> int max(int x, int y) { if (x >= y) { return x; } else { return y; } } </syntaxhighlight> In BETA, such a function could be written using a pattern <!-- This isn't Pascal, but syntax is similar --> <syntaxhighlight lang="pascal"> max: (# x, y, z: @integer enter (x, y) do (if x >= y // True then x -> z else y -> z if) 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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
BETA (programming language)
(section)
Add topic