Language Syntax Suggestion

Jeremy Dunn jeremydunn@ibm.net
Thu, 11 Mar 1999 20:27:28 -0800


Hans Dieter Dreier suggested that I write my collections as [ a b]
rather than [,a,b], no doubt this is a return to familiar LISP syntax.
This would be possible if I was willing to lose the distinction between
ordered and unordered elements. The blank space in front of the first
element would visually get lost in code and easily be mistyped as [a b]
which does not mean the same thing at all. Remember, in LISP syntax the
blank spaces are there only to visually separate the elements of the
expression, the elements are ALWAYS assumed to be in the order that they
appear. My notation was based upon a philosophy of indicating every
operation that is being performed, explicitly, some people don't like
this because they want to make simplifying assumptions. An analogy I
might use would be the wide usage of calculators that use reverse-Polish
notation, my wife hates them! We're used to using +, - and so on because
we were taught it that way in grade school and we're going to cling to
it to the very end. I suppose this is like the battle between English
units and metric, I am outnumbered by the people who want to use the
English system (at least partially) versus the approach of rigidly
applying a syntax rule to each and every case.

I wanted to say something about IF-THEN and LOOP structures. I have
often felt that if/then structures in most languages carry more verbiage
than is necessary. Here is how I would write various expressions:

If A Then B			[If,A,B]
If A Then B Else C		[If,A,B,C]
If A Then B ElseIf C Then D	[If,A,B,C,D]

Very simple, no need for all those elses and thens. A SELECT CASE
structure could be written as [If,X,[,a,b,c][,A,B,C]] where X is the
expression or item that is to be compared with a,b,c to return one of
the results A,B,C. No need to have another function.

Looping structures have a multiplicity of functions that could be
simplified into a single function which I call LOOP. The Loop function
has this basic form:

[Loop,<test condition>,[<program body>]]

The program body would be a series of steps [,a,b,c,...,n]. If the test
condition is an integer then we have a simple REPEAT loop i.e.
[Loop,5,[<body>]] would repeat the body 5 times. We also have these
forms:

[Loop,[,<test>,],[<body>]] - While-Do
[Loop,[,,<test>],[<body>]] - Do-While

We notice that the test condition is now a two element collection that
consists of a blank argument and the actual test. The blank argument
indicates the order in which the body of the loop is to be executed. If
the first argument is blank then the body is executed first then the
test condition and vice-versa. No need for separate DoWhile and WhileDo
functions. A FOREACH loop would be written as

[Loop,[,X,[,a,b,c]],[<body>]]

This would be the same as 

Foreach X in [,a,b,c] Do <body>

A FOR loop then becomes simply a Loop structure with a test condition
that is a set with 3 elements that contain the initialization,
conditional test and increment as

[Loop,[,init,cond,incr],[<body>]]

We now have a simple way to indicate what can take up to 5 (or more)
loop functions in a conventional language, with only one Loop function.

I am of the opinion that if-structures and loop-structures should be
handled in single commands rather than a proliferation of special cases
that are really only representing one general concept.

jeremydunn@ibm.net