The ASSOCIATE
feature is in principle quite useful, as it allows assigning values to names without incurring the syntactical overhead of explicitly defining local variables. However, its utility is limited because the values are bound only after the ASSOCIATE
statement. This quickly leads to the need for nested associate statements, e.g.
PROGRAM toyexample
IMPLICIT NONE
ASSOCIATE(a => 2)
ASSOCIATE(b => [a, 2*a, 3*a])
PRINT *, a
PRINT *, b
END ASSOCIATE
END ASSOCIATE
END PROGRAM toyexample
In Lisp terms, this would be the behavior of let
, while I seek to emulate the behavior of let*
, which would allow me to write
PROGRAM toyexample
IMPLICIT NONE
ASSOCIATE(a => 2, b => [a, 2*a, 3*a])
PRINT *, a
PRINT *, b
END ASSOCIATE
END PROGRAM toyexample
Is there any feature in Fortran that allows me to do this?