To: J3 J3/14-179 From: David Muxworthy Subject: UK proposal UK-17 Recursion by default Date: 2014 June 09 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 silent wrong answers. All standard-conforming compilers already implement recursion so the new implementation effort required is minimal. The basic form of this proposal only applies to procedures that are permitted to have the RECURSIVE attribute; elemental ones do not at present. The restriction against elemental recursion was intended to make elemental procedures easier to implement and optimise; this has outlived its purpose, so an alternative set of specs and edits is proposed to lift that restriction as well. Specification: All nonelemental subprograms should by default have the RECURSIVE attribute. Syntax: RECURSIVE keyword becomes advisory only. Edits to J3/14-007r1(= N2014): [xviii] Introduction paragraph 2, bullet "Programs and procedures", add as the final sentence: "Nonelemental procedures are allowed to be recursive by default, so the keyword RECURSIVE is advisory." [224:0+9,10] 9.6.4.8.2 Note 9.42, delete the final sentence: "If a defined input/output procedure calls itself indirectly in this manner, it shall be declared RECURSIVE." [307:31-34] 12.6.2.1, delete constraint C1257 and paragraph 3, that is: "C1257 (R1225) If MODULE appears... RECURSIVE shall appear... The RECURSIVE prefix-spec shall appear if any procedure defined by the subprogram directly or indirectly invokes itself or any other procedure defined by the subprogram." [312:19-21] 12.6.2.1 p11, delete the second sentence: "Instead ... the subprogram." [316:19] 12.8.1 Elemental procedure declaration and interface, p4 add as the final sentence: "An elemental procedure shall not invoke itself directly or indirectly." ALTERNATIVE (additionally lifting the elemental recursion prohibition): Specification: [as above with "nonelemental" deleted] Syntax: [as above] Edits: [as above with Revise [xviii] "Nonelemental procedures" -> "Procedures, including elemental procedures,"; New edit [307:21] 12.6.2.1, C1251, delete constraint: "C1251 (R1225) A prefix shall not specify both ELEMENTAL and RECURSIVE."; Delete edit [316:19].]