From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,21960280f1d61e84 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.194.251.MISMATCH!news-out.readnews.com!transit4.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: in defense of GC Date: Sun, 04 Feb 2007 19:23:02 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1169531612.200010.153120@38g2000cwa.googlegroups.com> <1mahvxskejxe1$.tx7bjdqyo2oj$.dlg@40tude.net> <2tfy9vgph3.fsf@hod.lan.m-e-leypold.de> <1g7m33bys8v4p.6p9cpsh3k031$.dlg@40tude.net> <14hm72xd3b0bq$.axktv523vay8$.dlg@40tude.net> <4zwt33xm4b.fsf@hod.lan.m-e-leypold.de> <1j7neot6h1udi$.14vp2aos6z9l8.dlg@40tude.net> <1pzx3y7d2pide.y744copm0ejb$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1170634982 3977 192.74.137.71 (5 Feb 2007 00:23:02 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Mon, 5 Feb 2007 00:23:02 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:TO3ID3yKxYPtKzeKVbKvQXS9ong= Xref: g2news2.google.com comp.lang.ada:8945 Date: 2007-02-04T19:23:02-05:00 List-Id: Markus E Leypold writes: > I do need that > > function Make_a_Stepper (K:Integer) return ... is > > N : Integer := Complicated_Function(K); > > function Stepper(F:Foo) return Foo is > > begin > > return Foo + N; > > end; > > begin > return Stepper; > end; > > would work. And no nitpicking, please, if I made syntax error here: The > intention should be clear. I don't think this is nitpicking: I'm not sure what you mean by the above example. Is N intended to be constant or variable (in Ada terms -- that's immutable/immutable in FP terms)? Do you mean this: function Make_a_Stepper (K:Integer) return ... is N : constant Integer := Complicated_Function(K); -- I added "constant" here! **************** function Stepper(F:Foo) return Foo is begin return Foo + N; end; begin return Stepper; end; Or this: function Make_a_Stepper (K:Integer) return ... is N : Integer := Complicated_Function(K); function Stepper(F:Foo) return Foo is begin N := N + 1; -- I added a modification of N here! **************** return Foo + N; end; begin return Stepper; end; ? These two cases of so-called "upward closure" seem very different to me. (Both are of course illegal in Ada, but we're discussing what "ought" to be.) In the former case, we're returning a function that looks at some local value (the value of N). In this case, you comment about returning integer values is quite correct: >> Closure don't "make things global". They do it as much as returning an >> Integer, makes, GOD FORBID!, a value global (don't return Integers >> people, that makes a value global and we all know, global is bad -- >> how nonsensical is that?). Right. What's the big deal? Returning a function that looks at integer values is no worse than returning integer values. Integer values live forever, and the value of N is certainly not tied to the lifetime of N. But in the latter, case, the return of Stepper is causing the lifetime of an integer VARIABLE (i.e. mutable) to be longer than one might suspect for a local variable of Make_A_Stepper. That seems like a problem to me. You (Markus) seem to be an advocate of (possibly-upward) closures. And also an advocate of function programming. So how would you like a rule that says the former example is OK, but the latter is illegal? (That is, upward closures are allowed only when you're doing functional (no side-effects) programming). Note that the latter is not functional -- a call to the function that Make_A_Stepper returns modifies N, which is the key difference! - Bob