Path: utzoo!attcan!uunet!mcvax!ukc!mucs!r1!chl From: chl@r1.uucp (Charles Lindsey) Newsgroups: comp.lang.misc Subject: Re: first class functions (opps) Message-ID: <6105@ux.cs.man.ac.uk> Date: 11 May 89 11:36:14 GMT References: <10253@orstcs.CS.ORST.EDU> <2400023@otter.hpl.hp.com> <2824@garth.UUCP> Sender: news@ux.cs.man.ac.uk Reply-To: chl@r1.UUCP (Charles Lindsey) Organization: University of Manchester, UK Lines: 37 In article <2824@garth.UUCP> smryan@garth.UUCP (s m ryan) writes: >>Algol68 doesn't quite have first-class functions. You are not allowed to >>export a function out of the extent of the block that declared it, >>*especially* if it references locals of the outer block, i.e., the >>interesting and useful case. > >I've heard this claim but I don't see where the language (and not some >compiler) prohibits > > begin > heap int i; > int: i+:=1 > end ALGOL 68 Report 5.4.1.2 The yield of a routine-text T {e.g. INT: i+:=1}, in an environ E, is composed of T and the environ "necessary for" T in E. ALGOL 68 Report 7.2.2.c The environ necessary for T {INT: i+:=1} in this case is that corresponding to the BEGIN ... END, because T contains an identifier {i} that does not identify a defining-identifier contained in T, but does identify one contained in the BEGIN ... END {I paraphrase the Report considerably here}. ALGOL 68 Report 2.1.3.5.c The scope {or extent} of a routine is the scope of its environ. ALGOL 68 Report 3.2.2.a The yield of a serial-clause {the ... inside the BEGIN ... END} in an environ E {some outer block where the result of the BEGIN ... END was needed} ..... . It is required that that yield be not newer in scope than E. The effect of all this, in plain terms, is that you may export a routine out of as many blocks as you like until you reach its "necessary environ", which is one where some identifier used in the routine is declared. There you must stop.