Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcvax!steven From: steven@mcvax.uucp (Steven Pemberton) Newsgroups: net.lang Subject: Re: nested procedures. Message-ID: <7030@boring.mcvax.UUCP> Date: Mon, 4-Aug-86 11:57:41 EDT Article-I.D.: boring.7030 Posted: Mon Aug 4 11:57:41 1986 Date-Received: Tue, 5-Aug-86 03:51:18 EDT References: <335@graffiti.UUCP> <149@opus.UUCP> <7026@boring.mcvax.UUCP> <337@ubc-cs.UUCP> Reply-To: steven@boring.uucp (Steven Pemberton) Organization: CWI, Amsterdam Lines: 34 Apparently-To: rnews@mcvax In article <337@ubc-cs.UUCP> ludemann@ubc-cs.UUCP (Peter Ludemann) writes: [ Example program from original posting ] > This is a good example of why nested procedures should NOT exist. > The procedure writeElement has a side-effect: modifying the variable > "first". Because this example is small, it is easily comprehended, > but a larger example could be quite incomprehensible. I'm unclear about this point. Procedures by definition have side-effects. Maybe you mean that it modifies a non-local variable, but that is another question altogether. Anyway, if the example is comprehensible, it stands. Any use of procedures could become incomprehensible, but that's no argument against procedures. > I've written lots of these kinds of systems using a language with no > nested procedures. There is a straightforward way of handling such > cases: pass the control information explicitely to the "action" > procedure. This requires an extra initialisation procedure: > > procedure forEach(seq: value; > procedure actionInit(var control: bool); > procedure action(var control: bool; elem: value)); > begin > var control: bool; > actionInit(control); > { For each element e of sequence seq, call action(control, e) } > end; It also requires a new version of forEach for every different type of action procedure you need to call. Even the example program requires two: one for writeElement which has a boolean parameter, and another for loop which has a 'location' parameter. Steven Pemberton, CWI, Amsterdam; steven@mcvax.uucp Lrf, vg'f ebg guvegrrarq!