To: J3 J3/14-179r2 From: Van Snyder & Malcolm Cohen Subject: UK proposal UK-17 Recursion by default Date: 2014 June 25 Reference: 14-007r1 Status: For Consideration Basic Functionality: Make RECURSIVE the default for procedures. Rationale: It is annoying for the user to have to specify RECURSIVE for a procedure that can call itself recursively. Other high level languages have had recursion as a default for many years; this is a stumbling block for new users. The trouble with the current situation is that if the compiler produces non-recursion-capable code for a procedure that is not declared to be RECURSIVE (e.g. by storing one or more local variables statically instead of dynamically), and does not detect invalid recursion, the result is silently wrong answers. All standard-conforming compilers already implement recursion so the new implementation effort required is minimal. The restriction against elemental recursion was intended to make elemental procedures easier to implement and optimise; this has outlived its purpose, so edits are proposed to lift that restriction as well. Specification: All subprograms should by default have the RECURSIVE attribute. A NON_RECURSIVE prefix is provided to specify that a procedure is not recursive. Syntax: RECURSIVE keyword becomes advisory only. A NON_RECURSIVE keyword is provided to specify that a procedure is not recursive. Edits to J3/14-007r1(= N2014): [xviii] Introduction paragraph 2, bullet "Programs and procedures", add as the final sentence: "Procedures, including elemental procedures, can be invoked recursively by default. The RECURSIVE keyword is advisory only. The NON_RECURSIVE keyword specifies that a procedure is not recursive." [224:0+9,10 9.6.4.8.2 Note 9.42] replace the final sentence "If ... RECURSIVE" with: "If a defined input/output procedure calls itself indirectly in this manner, it cannot be declared NON_RECURSIVE." [229:0+7 Note 9.49] Delete "RECURSIVE". [307:15 R1226] After "<> MODULE", insert an alternative: " <> NON_RECURSIVE" [307:21 C1251 12.6.2.1] Within constraint C1251, replace "ELEMENTAL" with "NON_RECURSIVE". [307:31-32 C1257 12.6.2.1] Within constraint C1257 replace "RECURSIVE" with "NON_RECURSIVE" twice. [307:33-34 12.6.2.1p3] Replace "RECURSIVE" with "NON_RECURSIVE" and insert "not" after "shall". [309:11+7-11+20 Note 12.45] Delete Note 12.45. [312:19 16.9.2.6p11] Replace "keyword RECURSIVE is" with "NON_RECURSIVE and RECURSIVE keywords are" Replace second "RECURSIVE" with "NON_RECURSIVE". [527:34 C.9.3] Delete "RECURSIVE".