comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Design by contract and control inversion
Date: Fri, 2 Nov 2012 09:45:33 -0700 (PDT)
Date: 2012-11-02T09:45:33-07:00	[thread overview]
Message-ID: <a7bf1c8f-7efe-4f61-a722-b9083102368b@googlegroups.com> (raw)
In-Reply-To: <op.wm15ps0cule2fv@cardamome>

On Wednesday, October 31, 2012 1:28:33 PM UTC-6, Hibou57 (Yannick Duchêne) 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 => A > 0 or B in positive'Range;

Procedure Intermediate (A, B : Integer; C : Obj_Handle; D : Handler) is
begin
   D( A, B, C );
end;

To extend these with pre-/post-conditions we could add another type and 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  => (if condition'(E.Pre)  /= Null then E.Pre),
 post => (if condition'(E.Post) /= 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?



  parent reply	other threads:[~2012-11-02 16:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-31 19:28 Design by contract and control inversion Yannick Duchêne (Hibou57)
2012-11-01 17:13 ` Yannick Duchêne (Hibou57)
2012-11-01 20:29 ` Adam Beneschan
2012-11-02  3:40   ` Yannick Duchêne (Hibou57)
2012-11-02  8:59     ` Yannick Duchêne (Hibou57)
2012-11-02 12:32       ` Yannick Duchêne (Hibou57)
2012-11-07  1:34       ` Yannick Duchêne (Hibou57)
2012-11-02 16:45 ` Shark8 [this message]
2012-11-07  1:51   ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox