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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c7c302806c75a91b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.66.90.37 with SMTP id bt5mr1165929pab.40.1352253080036; Tue, 06 Nov 2012 17:51:20 -0800 (PST) Path: 6ni66587pbd.1!nntp.google.com!news.glorb.com!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Design by contract and control inversion Date: Wed, 07 Nov 2012 02:51:18 +0100 Organization: Ada @ Home Message-ID: References: NNTP-Posting-Host: aWaWeUaBdaj2Zzc04J1v5A.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.02 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-11-07T02:51:18+01:00 List-Id: Le Fri, 02 Nov 2012 17:45:33 +0100, Shark8 a = = =C3=A9crit: > On Wednesday, October 31, 2012 1:28:33 PM UTC-6, Hibou57 (Yannick = > Duch=C3=AAne) wrote: >> Hi all, >> >> I wondered if there are known idioms to express predicates for = >> callbacks, >> which may be via access to subprogram or interface/tagged types. > > Hm, it seems to me that you could have an intermediate/pass-through = > handler. > (It would be rather limited, unless you make pre-/post-condition = > parameters... and if you do that it could get cumbersome quick.) > [NOTE: Not compiled or checked, just brainstorming/psudocode.] > > Type Obj_Handle is not null access Object'class; > Type Handler is Access Procedure ( A, B : Integer; C : Obj_Handle ); > > -- this version applies the same preconditions to all handlers. > Procedure Intermediate (A, B : Integer; C : Obj_Handle; D : Handler) > with Inline, pre =3D> A > 0 or B in positive'Range; > > Procedure Intermediate (A, B : Integer; C : Obj_Handle; D : Handler) i= s > begin > D( A, B, C ); > end; > > To extend these with pre-/post-conditions we could add another type an= d = > another parameter to the handler. > > Type Condition is access function( P : Parameter ) return Boolean; > Type Conditions is record > Pre, Post : Condition; > end record; > > -- This version applies the psudo-pre/post-conditions, as supplied. > Procedure Intermediate (A, B : Integer; C : Obj_Handle; D : Handler; E= : = > Conditions) with inline, > pre =3D> (if condition'(E.Pre) /=3D Null then E.Pre), > post =3D> (if condition'(E.Post) /=3D Null then E.Post); > Procedure Intermediate (A, B : Integer; C : Obj_Handle; D : Handler; E= : = > Conditions) is > begin > D( A, B, C ); > end; > > > Or something like it, no? Yes, that could do the trick. But this is a bit too much for a = specification, and even could not find a place in a specification, as Ad= a = 2012 does not allow procedures in package specs (just functions), unless= = I'm wrong with it. Your idea made me think how again the interface type is the best: just = give the precondition you gave to `Intermediate`, to the handler method = of = the interface type. The only thing which still make me wish I could have something like this= = with access to sub=E2=80=91program, is that access to sub=E2=80=91progra= m can get an = access to an inner sub=E2=80=91program (as long as it not to be stored, = which is = the case here); you can't do this with an interface type, as a type = defined in a nested scope is not usable (an issue similar to the access = = level with named access type). By the way, I've dropped the initial design which was not safe enough. = Instead of adding preconditions everywhere, I will have an object which = = returns two kind of objects, one for read access and one for write acces= s, = and the relevant preconditions to ensure you can't have both read and = write access at the same time, will be only on the two functions returni= ng = these two views. That's safer and simpler. I will just have to resign to= = not have any=E2=80=91more an object exposing the two views (I initially = wanted too = much). -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity