[J3] Default values for optional arguments
Kurt W Hirchert
kurthirchert at gmail.com
Thu Jan 21 16:47:40 UTC 2021
On 1/21/2021 1:58 AM, Malcolm Cohen via J3 wrote:
>
> Bill Long writes:
>
> > Can’t we already do this?
>
> Yes.
>
> This suggested feature seems to either be simple syntactic sugar for
> what we can already do fairly easily, or complicated syntactic cyanide
> for what we can already do with a little effort. I’m not seeing any
> actually new functionality.
>
> Cheers,
>
> --
>
> ..............Malcolm Cohen, NAG Oxford/Tokyo.
>
I hadn't realized I was being that unclear. As I said at the beginning
of my post, most of that post is history -- an example of why the
Fortran 90 version of J3 decided that the features they were already
putting in the language were sufficient and that an additional feature
just for defaulting arguments was not needed. The only new stuff was
tacked on at the end:
1. I noted that conditional expression evaluation might make the example
approach more syntactically palatable.
2. If the current committee is inclined to do an additional feature
specifically for argument defaulting, I suggested a variant from what
was being proposed that would be as concise but not as limited in how it
could be used.
If everything is now clear to you or you're just tired of this
discussion, you can stop reading now. Otherwise, I will attempt to
recap what I thought the salient points were:
A. Although there are many other ways the omission of optional arguments
can affect a procedure, perhaps the most common is that the procedure
behaves as though a default argument had been supplied (most commonly, a
default value).
B. Thomas offered an example of implementing such defaulting using
assignment and pointed out some pitfalls/inconveniences to that
approach. He suggested a separate defaulting feature to avoid those
pitfalls.
C. My post was intended to offer a different approach, using argument
association, that avoids those pitfalls using existing features and
additionally provides a mechanism suitable for defaults that need to be
procedures or definable variables. [In that post, I presented the
approach the F90 committee considered, using internal procedures. A
variant would be to make foo recursive and invoke itself supplying
default arguments when arguments have been omitted.]
D. The suggested feature at the end of my post is relevant only if the
committee decides it wants/needs a separate defaulting feature. If you
ignore my silly syntax, there are two relevant aspects to this suggestion:
a. It is based on allowing the procedure to change an optional dummy
argument from being bound to nothing to being bound to an identified
default argument without increasing the call stack depth. This is not
something one can do now, so it would certainly be more than syntactic
sugar or syntactic cyanide. [An alternative might be a more general
feature allowing one procedure to invoke another to replace it on the
call stack, so the invoked procedure returns directly to the caller of
the original procedure rather than returning to the original procedure
just for the original procedure to immediately return to its caller.
Such a feature would add no new semantic power; it would merely optimize
the performance of things like tail recursion.]
b. I strongly encouraged at least the option of specifying the
default in the executable part of the procedure rather than the
declarations. Specifying the default in the declaration of the optional
argument is more concise. Specifying in the executable portion is more
flexible. My silly syntax was chosen to be usable both places so this
tradeoff could be the programmer's decision rather than the committee's.
In short, I am not convinced that a feature just for defaulting is
needed, but if you choose to do one, I encourage you to make it useful
in as many cases as possible,
-Kurt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210121/d9cc779f/attachment.htm>
More information about the J3
mailing list