-
Notifications
You must be signed in to change notification settings - Fork 16
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
LET statement concept #279
Comments
I'm adding a comment to link this to #221. @klausler @everythingfunctional feel free to remove this comment if the two are unrelated. |
This is a very nice solution to the concerns mentioned above. It also allows for variables to be declared where they are used, which is a style many people prefer. Some syntax alternatives:
|
I think this is a good idea overall. I've been going back and forth on this, because I actually do not like the "auto" feature in C++. However, for interactive usage (say in LFortran) having "let" actually would be very handy. What I had in mind was to introduce an
Regarding my own objections to Conclusion: I think this proposal might work. |
A nice feature of this proposal is that you can provide an explicit type if you want to. You still get all of the benefits apart from type inference: initialized variables without SAVE, immutable objects that don't have to be initialized with compile-time constants, declarations close to use. |
The LET statement is proposed as a single solution for several needs identified in other issues: fixing implicit SAVE on initialized variables, adding immutable objects, "auto" type and shape inference, and fixing the scope and semantics of ASSOCIATE. LET statements could replace many local variable and pointer declarations, and all instances of ASSOCIATE. It might have particularly useful applications in interactive environments.
The doubled colons are not optional.
The LET statement would be an executable statement (namely a new "action-stmt"), not a specification statement. It introduces one or more new names into the enclosing block or execution-part. The scope of each name extends to the end of the enclosing block or execution-part, but does not include any inner subprograms -- i.e., LET names cannot be host-associated into subprograms. By "block" here, I do indeed mean the term as it is defined by the standard, and intentionally imply that LET names, unlike anything else in Fortran, are scoped by IF and DO and other constructs, not just BLOCK constructs. An initialization expression may contain a reference to a previous LET name from earlier in the same LET statement.
The names declared in a LET statement may not already be in use in the enclosing block or executable-part. The names may not appear in DATA or NAMELIST or EQUIVALENCE. The names do not have the SAVE or TARGET attributes, and cannot be coarrays. When LET names are referenced in DO CONCURRENT, they implicitly have LOCAL_INIT locality.
Each name in a LET statement declares and initializes a variable or pointer. The type can be explicit (
LET,INTEGER::N=666
), in which case conversions apply, or is inferred from the dynamic type of the initializer (LET::A=FOO()
). The shape is inferred from the initialization; no explicit or assumed or deferred bounds may appear. The interface of a procedure pointer can be explicit, or it can be inferred when the proc-target has an explicit interface.The attribute MUTABLE allows the names to appear in a variable definition context, which would otherwise be prohibited.
There will be constraints and/or requirements on control flow in the containing scope; it is not conforming to jump "over" a LET statement and then reference one of its names later if it remains uninitialized.
(Obvious constraints on incompatible attributes and the semantics of finalization are left as exercises.)
(EDITS: removed PARAMETER attribute and null-init initialization -- they are not essential to the idea.)
The text was updated successfully, but these errors were encountered: