Open Beliavsky opened 3 years ago
Why not use well-named keyword arguments?
Why not use well-named keyword arguments?
Calling library code. This would be really great for calling LAPACK for example, where most routines return results by overwriting inputs.
Some languages, such as Python and Matlab/Octave, let you return multiple entities from a function, for example
mean, sd = stats(x)
In Fortran you can use a subroutine to do this,
call stats(x,mean,sd)
but it is not clear from the calling code what the inputs and outputs are. I suggest that Fortran be extended to allow procedure calls to be annotated by the INTENTs of the procedure. Then you could write
call stats(in: x, out: mean, out: sd)
to call
You could only annotate with
in:
inout:
orout:
if the corresponding procedure argument had the same declaration. For subroutines with many arguments, I often write a comment saying what the outputs are, but assertions checked by the compiler would be better. Maybe annotating procedure calls could help the compiler better optimize the code, since it would know what variables are not changed by the procedure call.