Fully Bracketed Syntax
Harry G. George
hgg9140 at skewer.ca.boeing.com
Fri Feb 11 09:44:16 EST 2000
Python was inspired in part by Modula-3, and a crucial aspect of
Modula-3 is the notion of statement-sequences. I think that's what
you mean by fully bracketed.
The problem with C, Java, Pascal, and a host of other languages is
that their grammars have things like
if expr then statement
where statement may be compound (a series of statements), thus
requiring markers for the beginning and end of the sequence. C et al
use "{ }", Pascal et al use "begin end". Such languages are
subject to the classic bug:
if (expr)
stmt1
stmt2
where stmt2 is not controlled by the if condition.
In contrast, languages whose grammars use statement sequences have
fewer syntactic markers and no such bug:
if expr then statement-seq
allows:
if expr then
stmt1
end
and
if expr then
stmt1
stmt2
end
Personally, I'm generally impressed with python, but I have had
screwed up indentation where an end marker a la Modula-3 would have
been a lifesaver. Maybe I'll start using "#end". It would even be
less verbose than my std Modula-3 idiom:
....
#end if x > y
vs
....
END; (*if x > y*)
"Eaglestone, Robert [NGC:B918:EXCH]" <eaglesto at americasm01.nt.com> writes:
>
> Hello all,
>
> In general, it seems to me that all good programmers
> indent their code. However, mandating it as part of
> the form of a language sounds ... strange.
>
> However, I don't like the BEGIN...END bracketing done
> by Pascaline languages; neither do I love the {...}
> of C and its descendants.
>
> Has the creator of Python looked into fully bracketed
> syntax? That might not be the actual term, so here's
> an example of what I'm thinking about:
>
> if ( foo > bar )
> do_something();
> do_something_else();
> done();
> endif
>
> This bracketing gets the best [ or worst ] of both
> worlds, with a bit of syntactic sugar added for free.
> The lead bracket is the keyword itself, and the end
> bracket is tailored for that keyword alone. Only
> one 'line' is 'wasted' by the end bracket (Python
> doesn't like wasting lines). And indentation is no
> longer a language issue.
>
> I only know of one language which uses this syntax,
> and it's not in common use. However, lots of us may
> have seen this kind of syntax in college (hey! is it
> part of ML?).
>
> I guess what I'd like is some clear reasoning about
> bracketing and indenting that warrants such a feature
> of a language.
>
> Thanks,
> Rob
--
Harry George E-mail: harry.g.george at boeing.com
The Boeing Company Renton: (425) 237-6915
P. O. Box 3707 OY-89 Everett: (425) 266-3149
Seattle, WA 98124-2207 Page: (425) 631-8803
More information about the Python-list
mailing list