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,86c750b8474bf6d5 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 09 Jun 2008 13:43:21 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: About String References: <484ABED3.8040909@obry.net> <484b802a$0$23844$4f793bc4@news.tdc.fi> <484cfb49$0$6601$9b4e6d93@newsspool2.arcor-online.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <484d1759$0$6620$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 09 Jun 2008 13:43:21 CEST NNTP-Posting-Host: 89c095f0.newsspool2.arcor-online.net X-Trace: DXC=SZmFiW^FBSC0YVY]kmLTlDA9EHlD;3YcB4Fo<]lROoRA8kFJLh>_cHTX3jM\bWmBQgd\HK X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:631 Date: 2008-06-09T13:43:21+02:00 List-Id: Dmitry A. Kazakov schrieb: >> Given linear order of elaboration in declarative parts, >> and thus the possibility of sequencing initialization >> of local variables: >> >> procedure P is >> declare >> X1: constant T; -- like Java final >> begin >> X1 := New_T(...); -- may raise CE >> exception >> when Constraint_Error => >> X1 := Fallback_T; -- better than Java final >> end; >> X2: D := New_D(X1, ...); -- safely refer to X1 >> begin >> ... >> end P; > > Huh, if you want closures, just say so. There is no need to break proven > language concepts in order to have desired effect: I should have said that the scope of X1 extends beyond the declare block (which I had stupidly chosen as key words). > procedure P is > X1: constant T := -- Here anonymous function literal begins > function return T is > begin > return New_T (...); -- may raise CE > exception > when Constraint_Error => > return Fallback_T; -- better than Java final > end; > X2: D := New_D (X1, ...); -- safely refer to X1 > begin > ... > end P; Why closures? I was about to mention nesting, which solves this issue in Ada 95 and Ada: procedure P is function Safe_T return T is begin return New_T (...); -- may raise CE exception when Constraint_Error => return Fallback_T; -- better than Java final end; X1: constant T := Safe_T; X2: D := New_D (X1, ...); -- safely refer to X1 begin ... end P; In a sense, Safe_T works just like constructors that don't raise. > Note, no magic stuff, no exception handlers in declarations, just a simple > thing, which Ada should have had from the day one: functional types and > literals of. With the function's full environment?