[J3] Default values for optional arguments

Van Snyder van.snyder at sbcglobal.net
Thu Jan 21 19:05:40 UTC 2021


On Thu, 2021-01-21 at 10:47 -0600, Kurt W Hirchert via J3 wrote:

>     
> 
>     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.
>     
> 
>     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,
>     
>   
> 

I proposed to kill two birds with one stone, by uniting optional
argument defaulting and automatic variable reinitialization:

Allow an expression, having the same syntax as initialization, but not
requiring a constant expression, in the declaration of an optional
dummy argument, or in the declaration of a local variable that
explicitly has the AUTOMATIC attribute.

Such initialization would not imply the SAVE attribute, and AUTOMATIC
would override default SAVE.

In the case of an optional argument, it would only apply in the absent
actual argument case. The absent dummy argument would effectively
become an automatic local variable, accessed by way of the dummy
argument's local descriptor in the same way the actual argument would
have been accessed. Of course, this cannot be used with an optional
argument that has assumed shape or length parameters, unless it's
allocatable. If it is allocatable (or if an automatically-initialized
local variable is allocatable), it springs into existence allocated,
with the specified value, as if by intrinsic assignment.

There isn't much syntax.

The semantics could be realized within processors by tree
transformations done long before type checking, deeper semantic
analysis, or code generation.

This doesn't achieve all of Kurt's goals, but it does satisfy two
requests that the community has requested for decades.

@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}@font-face
	{font-family:游ゴシック;
	panose-1:2 11 4 0 0 0 0 0 0 0;}@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}@font-face
	{font-family:"\@游ゴシック";
	panose-1:2 11 4 0 0 0 0 0 0 0;}p.MsoNormal, li.MsoNormal,
div.MsoNormal
	{margin:0cm;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}div.WordSection1
	{page:WordSection1;}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20210121/c1e736f0/attachment.htm>


More information about the J3 mailing list