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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news1.google.com!news.maxwell.syr.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsinpeer00.lnd.ops.eu.uu.net!bnewsinpeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: in defense of GC Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH 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> Date: Sun, 4 Feb 2007 19:38:18 +0100 Message-ID: NNTP-Posting-Date: 04 Feb 2007 19:38:18 CET NNTP-Posting-Host: 26af451b.newsspool4.arcor-online.net X-Trace: DXC=`l@E[FJiK[RV0Pe9PRnbJ\4IUKWT\7JYDNcfSJ;bb[UIRnRBaCd On Sat, 03 Feb 2007 15:28:53 +0100, Markus E Leypold wrote: > "Dmitry A. Kazakov" writes: > >> On Fri, 02 Feb 2007 13:44:42 +0100, Markus E Leypold wrote: >> >>> 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?). >> >> You return a value of the type (Integer) which scope encloses the >> subprogram returning that value. > > Same applies to closures when they are returned. Where is the problem? The problem is this: function Foo return ?What? is type Bar is ...; X : Bar; begin return X; end Foo; >> I am a long proponent of procedural types for Ada. Now consider. A >> procedure is a limited object. Limited objects can be returned in Ada 2005. >> What else you need? [Note, this is still not an upward closure, I am >> opposing.] > > 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 suppose it is. Here I propose a closure-free solution: package Something_Very_Functional is type function Stepper (F : Foo) return Foo; -- The type of a function we want to pass somewhere procedure Step_It (Visitor : Stepper'Class); ... end Something_Very_Functional; package Stepper_Factory is function Create (K : Integer) return Stepper'Class; -- This is a constructor for the stepper provided here. We -- don't want to expose any details about it, so the -- Stepper type is made private. private type Stepper_With_A_Parameter (N : Integer) is new Stepper; -- This is a derived type to have a discriminant, which could serve -- as a carrier for the locally computed value. end Stepper_Factory; package body Stepper_Factory is function Create (K : Integer) return Stepper'Class is begin return Stepper_With_A_Parameter' ( N => Complicated_Function (K), with begin return F + N; end; ); end Stepper_Factory; Some notes. Within the "procedural record extension" the visibility rules are such that local variables of Create are invisible. The package data are visible and accessibility checks are made to ensure that the scope of Stepper_With_A_Parameter is not statically deeper than one of Stepper. ----------------- BTW, I prefer an OO design with Stepper being an abstract primitive operation of some object: type Data is abstract ...; function Stepper (State : in out Data; F : Foo) return Foo is abstract; procedure Step_It (Data : in out Data'Class); ------------------- > If it works, we have closures. If it doesn't I fail to see what you > mean by 'returning procedures'. Hmm, it must be obvious. How could it be so that we have access-to-procedure types, but no procedure types? >>> I can't believe I even have to spell it out. On the other side -- why >>> do I argue? You're even opposing generics. >> >> Yes I do! (:-)) > > Yes I notice. That does make you avantgarde, certainly. Even the Java > people learned that there is no live without generics / functors. As if Java weren't bad enough for them... (:-)) >>>> This is A) mess, B) sloppy programming, C) impossible model in our >>>> networking distributed relativist world. >>> >>> There are BTW, even distributed garbage collection algorithms. This >>> probably will enrage you no end? :-). >> >> Yes I know, they are usually called trojans... (:-)) > > ?. They arrive at your computer and collect garbage while you don't notice that... (:-)) -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de