Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
ALGOL 68
(section)
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!
===mode: Declarations=== The basic [[data type]]s (called <code>mode</code>s in Algol 68 parlance) are <code>real</code>, <code>int</code>, <code>compl</code> ([[complex number]]), <code>bool</code>, <code>char</code>, <code>bits</code> and <code>bytes</code>. For example: '''INT''' n = 2; '''CO''' n is fixed as a constant of 2. '''CO''' '''INT''' m := 3; '''CO''' m is a newly created local ''variable'' whose value is initially set to 3. '''CO''' '''CO''' This is short for '''ref''' '''int''' m = '''loc''' '''int''' := 3; '''CO''' '''REAL''' avogadro = 6.0221415β¨23; '''CO''' Avogadro number '''CO''' '''long long real''' long long pi = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510; '''COMPL''' square root of minus one = 0 β₯ 1; However, the declaration <code>'''REAL''' x;</code> is just [[syntactic sugar]] for <code>'''REF''' '''REAL''' x = '''LOC''' '''REAL''';</code>. That is, <code>x</code> is really the ''constant identifier'' for a ''reference to'' a newly generated local '''REAL''' variable. Furthermore, instead of defining both <code>float</code> and <code>double</code>, or <code>int</code> and <code>long</code> and <code>short</code>, etc., ALGOL 68 provides ''modifiers'', so that the presently common <code>double</code> would be written as '''LONG''' '''REAL''' or '''LONG''' '''LONG''' '''REAL''' instead, for example. The ''prelude constants'' <code>max real</code> and <code>min long int</code> are provided to adapt programs to different implementations. All variables need to be declared, but declaration does not have to precede the first use. primitive-declarer: '''INT''', '''REAL''', '''COMPL''', '''COMPLEX'''<sup>G</sup>, '''BOOL''', '''CHAR''', '''STRING''', '''BITS''', '''BYTES''', '''FORMAT''', '''FILE''', '''PIPE'''<sup>G</sup>, '''CHANNEL''', '''SEMA''' * '''BITS''' β a "packed vector" of '''BOOL'''. * '''BYTES''' β a "packed vector" of '''CHAR'''. * '''STRING''' β a '''FLEX'''ible array of '''CHAR'''. * '''SEMA''' β a [[Semaphore (programming)|'''SEMA'''phore]] which can be initialised with the '''OP'''erator '''LEVEL'''. Complex types can be created from simpler ones using various type constructors: * '''REF''' ''mode'' β a reference to a value of type ''mode'', similar to '''&''' in C/C++ and '''REF''' in Pascal * '''STRUCT''' β used to build structures, like '''STRUCT''' in C/C++ and '''RECORD''' in Pascal * '''UNION''' β used to build unions, like in C/C++ and Pascal * '''PROC''' β used to specify procedures, like functions in C/C++ and procedures/functions in Pascal Other declaration symbols include: '''FLEX''', '''HEAP''', '''LOC''', '''REF''', '''LONG''', '''SHORT''', '''EVENT'''<sup>S</sup> * '''FLEX''' β declare the array to be flexible, i.e. it can grow in length on demand. * '''HEAP''' β allocate variable some free space from the global heap. * '''LOC''' β allocate variable some free space of the local stack. * '''LONG''' β declare an '''INT''', '''REAL''' or '''COMPL''' to be of a '''LONG'''er size. * '''SHORT''' β declare an '''INT''', '''REAL''' or '''COMPL''' to be of a '''SHORT'''er size. A name for a mode (type) can be declared using a '''MODE''' declaration, which is similar to '''TYPEDEF''' in C/C++ and '''TYPE''' in Pascal: '''INT''' max=99; '''MODE''' '''NEWMODE''' = [0:9][0:max]'''STRUCT''' ( '''LONG''' '''REAL''' a, b, c, '''SHORT''' '''INT''' i, j, k, '''REF''' '''REAL''' r ); This is similar to the following C code: <syntaxhighlight lang="c"> const int max=99; typedef struct { double a, b, c; short i, j, k; float *r; } newmode[9+1][max+1]; </syntaxhighlight> For ALGOL 68, only the '''NEWMODE''' mode-indication appears to the left of the equals symbol, and most notably the construction is made, and can be read, from left to right without regard to priorities. Also, the '''lower bound''' of Algol 68 arrays is one by default, but can be any integer from -''max int'' to ''max int''. Mode declarations allow types to be [[Recursive data type|recursive]]: defined directly or indirectly in terms of themselves. This is subject to some restrictions β for instance, these declarations are illegal: '''MODE''' '''A''' = '''REF''' '''A''' '''MODE''' '''A''' = '''STRUCT''' ('''A''' a, '''B''' b) '''MODE''' '''A''' = '''PROC''' ('''A''' a) '''A''' while these are valid: '''MODE''' '''A''' = '''STRUCT''' ('''REF''' '''A''' a, '''B''' b) '''MODE''' '''A''' = '''PROC''' ('''REF''' '''A''' a) '''REF''' '''A'''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)