[J3] [EXTERNAL] Re: Why is += missing?

Van Snyder van.snyder at sbcglobal.net
Thu Sep 2 22:55:45 UTC 2021


On Thu, 2021-09-02 at 17:24 -0400, Reuben D. Budiardja via J3 wrote:
> I use ASSOCIATE construct quite a bit in my applications, and it's 
> usefulness is exactly because it's a block scope.

I like Kurt's idea for a statement-scope ASSOCIATE, by analogy with IF
statements. This is essentially Vipul's idea, without introducing a new
keyword for the same purpose.

I also like Kurt's idea for omitting the ASSOCIATE keyword for the
statement-scope version. It doesn't introduce a syntax ambiguity. But
without the keyword, a new-to-Fortran user thrust into a maintenance
role might be confused.

In earlier discussion, I proposed that something other than @ might be
used to introduce an associate name. As obvious as => would be, it
introduces a syntax ambiguity if declarations of associate names are
embedded in the statement rather than being collected at the beginning.

    a => x ( s => ( 3 * i + j ) ) = a + b ( s )

might be parsable by a human or processor, but what does

    a => b => c

mean?

Is this "a is an associate name for b, a pointer to become associated
with c" or "b is an associate name for c, to become the target of a?"

It turns out the result is the same, but how is the parser or human
reader expected to make sense of it?

If "a => b" were prohibited at parenthesis level zero, it wouldn't be
necessary to collect the associations at the beginning of the
statement. But the syntax explanation would be messy, and usage might
be error prone. For example

    ( a => x ( s => ( 3 * i + j ) ) ) = a + b ( s )

but this has a cognitive conflict with the usual conclusion that
something within parentheses is a value, not a variable.

And there is no harm at parenthesis level zero except on the LHS of
assignment or pointer assignment. Explaining that would be even more
difficult.

So I don't think using => is possible without more syntax. Without a
different special symbol (or digraph), Kurt's and Vipul's approaches
are preferable.

Kurt's alternatives to the above would be

    ASSOCIATE  ( s => 3*i+j, a => x(s) ) a = a + b ( s )
    ( s => 3*i+j, a => x(s) ) a = a + b ( s )

or if <association> were generalized to allow it to be nested, i.e.,
incorporated into expression and designator syntax:

    ASSOCIATE  ( a => x ( s => (3*i+j) ) a = a + b ( s )
    ( a => x ( s => (3*i+j) ) a = a + b ( s )

Vipul's would be

    WITH  ( s => 3*i+j, a => x(s) ) a = a + b ( s )

or

    WITH  ( a => x ( s => (3*i+j) ) a = a + b ( s )

I prefer any of these to <xyz>= with its limited generality, and the
attendant questions about defining assignment. I prefer Kurt's because
Vipul's introduces a new keyword for the same purpose as an existing
keyword.

As an aside, the inspiration of for the ASSOCIATE construct was
Pascal's WITH construct. We considered using WITH and decided on
ASSOCIATE (as a more general concept than Pascal's WITH), because
that's what the construct does.

Statement-scope association is useful beyond assignment statements, for
example in CALL or WRITE statements.

<xyz>= is not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210902/513c9dc4/attachment.htm>


More information about the J3 mailing list