Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP Path: utzoo!linus!security!genrad!mit-eddie!barmar From: barmar@mit-eddie.UUCP (Barry Margolin) Newsgroups: net.lang Subject: declarations and nested blocks Message-ID: <1072@mit-eddie.UUCP> Date: Mon, 19-Dec-83 02:08:18 EST Article-I.D.: mit-eddi.1072 Posted: Mon Dec 19 02:08:18 1983 Date-Received: Tue, 20-Dec-83 01:21:10 EST Organization: MIT, Cambridge, MA Lines: 31 There is a feature of PL/I and Algol which is used in most of their descendents which is both useful and painful. I am referring to the fact that the scope of variables includes nested procedures. It allows one to write simpler (though less clear) code, but it also permits one to write incorrect code pretty easily. This problem is exemplified in the following fragment: do index = 1 to 10; call subr (array (index)); end; subr: procedure (thing); ... do index = 1 to 5; ... end; end subr; Since the programmer forgot to declare a local "index" variable in subr he ends up with an infinite loop, since index will never reach 10; it will be set to 5 after each iteration. I'm surprised that Ada(tm) does not require some explicit statement to allow you to inherit from an outer block. Why is this feature propogated to all new languages, with hardly any change? -- Barry Margolin ARPA: barmar@MIT-Multics UUCP: ..!genrad!mit-eddie!barmar