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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,86c750b8474bf6d5 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!195.114.231.69.MISMATCH!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail From: =?ISO-8859-1?Q?S=E9bastien_Morand?= Newsgroups: comp.lang.ada Subject: Re: About String Date: Mon, 09 Jun 2008 10:42:18 +0000 Organization: A noiseless patient Spider Message-ID: <484D090A.30606@gmail.com> References: <484ABED3.8040909@obry.net> <484b802a$0$23844$4f793bc4@news.tdc.fi> <484cfb49$0$6601$9b4e6d93@newsspool2.arcor-online.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: feeder.motzarella.org U2FsdGVkX18r5Gv+BlTV6aKtTHB+x8JTELuhpHXOqR4+R5l+aYc/pSBnlA73i+d5yexN1E/fG0MpnQ7V/T44q76kkREuFMsuDKVCo15Ec5HBb4bCF8IPU9oq2u597C7tBvHSF+gdx1I4qJ/fUmf8Cw== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Mon, 9 Jun 2008 10:42:20 +0000 (UTC) In-Reply-To: X-Auth-Sender: U2FsdGVkX1/8je37838o/2CFxax/9sGgPw/P58YS+kMpnTC7+D3OBg== Cancel-Lock: sha1:MxSAuu/x+k9Cu8hoP7THV7tevcg= User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) X-Enigmail-Version: 0.95.6 Xref: g2news1.google.com comp.lang.ada:629 Date: 2008-06-09T10:42:18+00:00 List-Id: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dmitry A. Kazakov a �crit : > On Mon, 09 Jun 2008 11:43:36 +0200, Georg Bauhaus wrote: > >> Dmitry A. Kazakov schrieb: > >>> On Sun, 08 Jun 2008 17:19:11 -0400, Robert A Duff wrote: >>> >>>> Maciej Sobczak writes: >>>> >>>>> After all, with the possibility to initialize the new variable with >>>>> arbitrarily complex expression (including function call), this is >>>>> already the case and the whole declare-begin-end block is just >>>>> reflecting some artificial separation. > >>>> I agree. I suppose it comes from Pascal, where declarations and >>>> executable code are completely separated. It makes no sense in >>>> Ada, where declarations are just as executable as statements. > >>> I disagree. I think it does make sense because it clearly defines the scope >>> of the declared variable. > >> Still, a somewhat *new* kind kind of handling exceptions in single >> declarations looks interesting? > >> 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: > > 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; > > 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. You can do that but not in an anonymous way, so what's the point? I think it not a good practive to use anonymous function or procedure, it makes hard to read code (and it's one of the feature of ada: easy to read) I prefer this kind of writing: procedure P is function Init_T return T; function Init_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 := Init_T; -- Here anonymous function literal begins X2: D := New_D (X1, ...); -- safely refer to X1 begin ... end P; -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Cygwin) iD8DBQFITQkK+zV9xm4PlDQRAnhxAJ9FKGI7aVenIlDrrnsl3LHJE42FJQCfV9lc Vvl0CozDP7p/Ah44Ivnz4G8= =bdGO -----END PGP SIGNATURE-----