[J3] Default values for optional arguments

Van Snyder van.snyder at sbcglobal.net
Thu Jan 21 02:08:40 UTC 2021

On Wed, 2021-01-20 at 14:00 -0800, Van Snyder via J3 wrote:
> On Wed, 2021-01-20 at 12:28 +0000, Bill Long via J3 wrote:
> > There was a proposal for default optional argument values for F202X
> > that failed for the reason given above.   Something like
> > 
> > integer, intent(in), optional, default(42) :: b
> > 
> > might work.If this were to work, then subsequent tests for
> > Present(b) would have to return true to avoid conflicts with
> > existing code. There might be other side effects that are
> > undesirable. 
> It's not obvious how this would work if the optional argument is an
> allocatable array.
> The obvious interpretation of an absent optional argument with a
> default value is that it becomes an automatic local variable, with
> automatic initialization.
> People have been asking for automatic initialization, i.e., that
> doesn't imply SAVE, for decades.

During the development of Fortran 90, back when it was still called
Fortran 8x, there was a proposal for an AUTOMATIC attribute. When
RECURSIVE was added, the argument was that every variable that isn't
SAVE is automatic. The standard's definition of "automatic variable"
was needlessly narrowed to one that used a variable to specify a bound
or length parameter. I no longer have records from that time; I sent
them to the Computer History Museum. Loren Meissner is the curator for

Had the AUTOMATIC attribute been retained, an obvious definition of
AUTOMATIC with initialization would have meant automatic
initialization, not SAVE. Specifying the AUTOMATIC attribute without
initialization would simply confirm what we already say now. Explicitly
specifying AUTOMATIC and SAVE for a particular variable should be
prohibited. Explicitly specified AUTOMATIC would override default SAVE.
AUTOMATIC would naturally be prohibited for storage-associated
Once AUTOMATIC is defined that way, all that is necessary to provide
default values for absent optional arguments is to define an absent
OPTIONAL argument that has initialization to be a local automatic

The PRESENT intrinsic should still be available to inquire whether
there was an associated actual argument. Even if there's a value for a
local variable acting in lieu of the absent dummy argument, it's still
useful to know whether the actual argument was present.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210120/4b042220/attachment-0001.htm>

More information about the J3 mailing list