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,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!proxad.net!news.cs.univ-paris8.fr!informatik.uni-bremen.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: ADA Popularity Discussion Request Date: Tue, 31 Aug 2004 16:02:07 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> <1198227.gWQ0keDDOY@linux1.krischik.com> <1093956169.632925@master.nyc.kbcfp.com> <1093958534.425645@master.nyc.kbcfp.com> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1093968127 24306 134.91.1.34 (31 Aug 2004 16:02:07 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Tue, 31 Aug 2004 16:02:07 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:3214 Date: 2004-08-31T16:02:07+00:00 List-Id: Hyman Rosen wrote: : Hyman Rosen wrote: :> restorer(int &var, int newval) : sg(var), oldval(var) { } : : Oops. That should be { var = newval; } of course. I think there is still an interesting difference. If, for the sake of an example, I write void some_func(int some_para) { extern int some_global_a, some_global_b; struct restorer { int &sg, oldval, def; restorer(int &var, int newval) : sg(var), oldval(var) { var = newval; def = some_para; // <-- } ~restorer() { sg = oldval; } }; the compiler tells me I can't do this, because I am using a parameter from the containing function. In Ada, this works: procedure nc is type Int_Ref is access all Integer; some_global_a, some_global_b: aliased Integer; -- global to `some_func` anyway procedure some_func(some_para: Integer) is type Restorer is record -- "new Controlled with" for the real thing ... sg: Int_Ref; oldval: Integer; def: Integer; -- only for this example end record; function make_restorer(var: Int_Ref; newval: Integer) return restorer is result: constant restorer := (sg => var, oldval => var.all, def => some_para); begin var.all := newval; return result; end make_restorer; begin declare rsga: restorer := make_restorer(some_global_a'access, 53); rsgb: restorer := make_restorer(some_global_b'access, -1); begin null; -- ... end; end some_func; begin -- nc some_func(5); end nc;