Skip to content

Allow procedure calls to be annotated with INTENTs?  #203

Open
@Beliavsky

Description

@Beliavsky

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

subroutine stats(x,mean,sd)
real, intent(in) :: x(:)
real, intent(out) :: mean,sd
...
end subroutine stats

You could only annotate with in: inout: or out: 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.

Activity

klausler

klausler commented on Apr 12, 2021

@klausler

Why not use well-named keyword arguments?

nshaffer

nshaffer commented on Apr 13, 2021

@nshaffer

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.

added
Clause 8Standard Clause 8: Attribute declarations and specifications
on Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Clause 8Standard Clause 8: Attribute declarations and specifications

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @certik@nshaffer@klausler@Beliavsky

        Issue actions

          Allow procedure calls to be annotated with INTENTs? · Issue #203 · j3-fortran/fortran_proposals