[J3] [EXTERNAL] Re: Syntax of conditional expressions

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Tue Jun 29 19:28:40 UTC 2021

Devils argument.

I agree for the fixed source files where this feature would be used with single character conditions and flags that there is a point to be made here.   But I don’t think many people will be using this feature in fixed format with single character conditions and flags.

I chose some random variables and conditions from my own code  in a nested block,  and grant me that we’re doing the nontrivial case where there is at least one else:

myVariable = ( has_ungrid -> AttributeGet(‘UNGRIDDED_DIMS’:  default_provided -> default : gridded_default )

This is 108 characters.   The verbose form is 127 characters.   And this is hardly an unrealistic example IMO for well-named variables.

The very nature of this feature is that it will generally be used in long and messy statements that would be undesirable save for the fact that they eliminate a much longer (though probably less messy) combination of statements.    Worrying about the extra 20 characters for things that will be much much longer than that seems to be a distant concern.

  *   Tom

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Tuesday, June 29, 2021 at 3:08 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: Gary Klimowicz <gak at pobox.com>, J3 List <j3 at j3-fortran.org>
Subject: [EXTERNAL] Re: [J3] Syntax of conditional expressions

On Jun 29, 2021, at 10:21, Robert Corbett via J3 <j3 at mailman.j3-fortran.org<mailto: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/5bad4c2c/attachment-0003.htm>

More information about the J3 mailing list