Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax to initialize variables in declarations without SAVE #234

Open
Beliavsky opened this issue Oct 12, 2021 · 2 comments
Open

Syntax to initialize variables in declarations without SAVE #234

Beliavsky opened this issue Oct 12, 2021 · 2 comments
Labels
Clause 8 Standard Clause 8: Attribute declarations and specifications

Comments

@Beliavsky
Copy link

Beliavsky commented Oct 12, 2021

It is convenient to give a variable a value at the time it is declared, but in a procedure

integer :: i=0

has the implicit save attribute, which may not be wanted, and which many new Fortran programmers stumble over. I suggest adding an init attribute so that

integer, init :: i=0, j=1

has the same meaning as

integer :: i,j
i = 0
j = 1

Then the programmer can set the value of a variable in a declaration with the init, save, or parameter attribute, depending on the desired behavior.

@certik
Copy link
Member

certik commented Oct 12, 2021

This is a duplicate of #40 (comment), but keep it here as a top level issue, so that it is not buried in comments. However, every body please do read all the comments there, so that we do not repeat the discussion.

Other relevant issues:

@certik certik added the Clause 8 Standard Clause 8: Attribute declarations and specifications label Apr 23, 2022
@klausler
Copy link

klausler commented Jul 12, 2022

What I took away from all of that discussion is that something like this, as an executable part statement, would answer all of the needs that were expressed:

let-stmt ::= LET [, let-attr-list ] :: let-init-list
let-attr ::= IMMUTABLE | TYPE(type-spec) | POINTER
let-init ::= object-name [ ( array-spec ) } initialization

Note that initialization is required. The type would be inferred from the initializer if not explicit. There is no SAVE attribute possible, explicit or implicit. It's not a construct, so no end let is needed. Later object-names could refer to earlier ones in the same statement in their initializations. If IMMUTABLE, the object-name could not appear in a variable definition context.

This subsumes auto, init, immutability, and other proposals, and more or less replaces associate.

UPDATE: see #279 for more detail on this idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clause 8 Standard Clause 8: Attribute declarations and specifications
Projects
None yet
Development

No branches or pull requests

3 participants