home bbs files messages ]

Just a sample of the Echomail archive

COMPLANC:

<< oldest | < older | list | newer > | newest >> ]

 Message 242,315 of 243,097 
 bart to Janis Papanagnou 
 Block syntax (was Re: _BitInt(N)) 
 02 Dec 25 14:12:42 
 
From: bc@freeuk.com

On 02/12/2025 13:15, Janis Papanagnou wrote:
> On 2025-12-02 13:21:32, bart wrote:
>> So:
>>
>>    if .. then begin ... end else begin ... end
>>
>> ... represents multiple statements.
>>
>> Even I would see braces in a more favourable light. I wonder why it
>> took some years for language designers to realise you could simply have:
>>
>>    if .. then ... else ... end
>
> You're misrepresenting history, or at least convey the impression
> that this would be something new and previously obscure,

I'm not misrepresenting anything at all. For example Algol60 needed
begin-end if you wanted several statements in a block; Algol68 made that
optional.

There are 'some years' between them.

> or that
> language designers would not know all these syntactical options.
>
> You had the  if .. then ... else ... fi  syntax as paragon in the
> back then by language experts well known Algol 68 language, it's
> been inherited (also in comparable forms), e.g. by the common Unix
> shell, also in "more recent" languages (with "end") in Eiffel, for
> example.

It's everywhere now with 'end'-based languages: Ada, modern Fortran,
Lua, Ruby. Even Wirth adopted it Modula-2.


> The huge impact of the "C" language syntax might have made that
> less visible in the modern, contemporary (used, hyped) languages.
> But there's really nothing to "realize" by language designers, I'm
> sure.

Language designers were hung up on the concept of allowing only a single
statement for each branch of a structured statement like 'if' or the
body of a loop, or of a function. I guess it made their grammars simpler.

This applies to C too. So if someone wanted multiple statements, then
they need to use a special 'compound statement' which needed enclosure:

     {s1; s2; s3;}
     begin s1; s2; s3 end

This now counts as single statement to satisfy the requirement. (Note C
requires a compound statement for a function body, even if it is just
one statement.)

So, what they had to realise was they could simply allow N statements
instead of 1, in such contexts. The only problem then was in delimiting
that sequence.

Some syntaxes could use a token like 'end' on the final block of a
structured statement (previous ones being delimited by then ... else for
example), but that didn't work for braces, so C-like syntaxes are stuck
with the notion of a single statement per branch.

Some others now use significant white space, a more fragile approach.

--- SoupGate-Win32 v1.05
 * Origin: you cannot sedate... all the things you hate (1:229/2)

<< oldest | < older | list | newer > | newest >> ]


(c) 1994,  bbs@darkrealms.ca