[J3] Syntax of conditional expressions

Gary Klimowicz gak at pobox.com
Tue Jun 29 19:08:30 UTC 2021

On Jun 29, 2021, at 10:21, Robert Corbett via J3 <j3 at mailman.j3-fortran.org> wrote:

> The choice between the verbose and concise
> forms of conditional expressions was very
> close. I would not object to including both
> forms in the language.  There is a precedent.
> Algol 68 had both verbose and concise forms
> of conditional expressions.

I realize we're not competing in "expression golf" here,
but let's remember how concise Algol-68 was in both forms.

The verbose form in Algol-68 was much more concise to begin with:
    if a then b elif c then d else e fi      # 35 chars #

Compare to (21-157r1 line 28)
    if (a) then (b) elseif (c) then (d) else (e) endif ! 50 chars, 43% more

That's just with 5 characters of data in the expression.

If you're stuck in fixed format, that's 75% of the available characters,

So, I'm not a fan of the verbose form; I think it's just too verbose.

The concise forms fair much better.

In Algol-68, the above can also be expressed as
    (a | b |: c | d | e)          # 21 chars; with 8 blanks for readability #

Fortran concise 1 (21-157r1 line 33)
    (? a ? b :? c ? d : e ?)      ! 24; not bad
                                  ! But then we live in Question Mark City!

Fortran concise 2 (21-157r1 line 38)
    ( a -> b : c -> d : e )       ! 23 chars

As an aside, Algol 68 also had the notion of a sort of void computation,
"skip", that seems to mean something like "I know you want a value here,
so let's pretend I gave you one of the appropriate type". I'm not sure
of the semantics in an expression, but it's mentioned in the book I have
for handling the "else" with no value.

So, my vote would be: one form, concise. I'll admit I'm not a fan of all
the question marks, but I lost track of the concise proposals (had to
make a phone call at a bad time).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210629/9c747780/attachment-0003.htm>

More information about the J3 mailing list