Algol 68 allows using ( and ) instead of begin and
end to delimit closed clauses. In fact, parenthesized
expression in other programming languages are realized in Algol 68
with closed clauses, in a very orthogonal way. Both forms are useful
and can generally be used according to the programmer’s taste.
However, this section contains a few guidelines and recommendations on
this regard.
Use parentheses for closed clauses that span a single line, regardless
of the context. Having begin and end symbols in the
same line looks weird and confusing.
As a general rule, always use parentheses in closed clauses that are
operands in a formula. Exceptionally, using begin and
end in formula operands may be preferable if the operand
contains many declarations and units, and only if it spans for more
than one line. In this case, however, please consider factoring the
code in the operand into a routine and replace it with a procedure
call.
The preferred indentation for a closed clause whose contents span more
than one line, and that uses begin and end symbols as
delimiters, is to indent the contents right at the right of the
begin symbol. The end symbol shall then be placed in
its own line, with the same indentation level than the opening symbol.
If the closed clause contains empty lines, or if the line preceding
the closed clause is so long that it would "hide" the first line in
the closed clause, then it is ok to put the first unit or declaration
in the line after begin. This usually happens when the closed
clause is the body of a long routine text.
The preferred indentation for a closed clause whose contents span more
than one line, and that uses ( and ) symbols as
delimiters, is to indent the contents right at the right of the
( symbol. The ) symbol finishing the closed clause
shall not be placed in its own line.
{ No `begin' and `end' in the same line }
int i = 2 + (3+4);
int i = 2 + (int i = random(); i % 10 );
bool test = case v in (string): (puts (s); true) out false esac;
{ Closed clauses as formula operands }
int i = 2 + (int cnt := 0;
to UPB data[@1] do cnt +:= 1 od;
cnt)
int j = 2 + begin int cnt := 0;
to UPB data[@1] do cnt +:= 1 od;
cnt
end
{ Closed clause with no empty lines }
begin int fd = fopen ("data', file_o_rdonly")
puts ("first line: " + fgets (fd, 0));
fclose (fd)
end;
{ Closed clause with no empty lines but with preceding
line of similar length }
proc parse_number = int:
begin
int num := 0;
while num := num * 10 + ABS ch - ABS "0";
isdigi(getachar)
do ~ od;
ungeachar(ch);
num
end;
{ Closed clause with empty lines }
proc main_proc = int:
begin
{ Auxiliary procs }
proc aux1 = int: ...;
proc aux2 = int: ...;
{ Computation }
aux1;
aux2;
{ Result }
aux1 + aux2
end
{ Indentation of closed clauses using `(' and `)' delimiters }
proc parse_number = int:
(int num := 0;
while num := num * 10 + ABS ch - ABS "0";
isdigi(getachar)
do ~ od;
ungeachar(ch);
num)