comp.lang.ada
 help / color / mirror / Atom feed
From: "Steven Deller" <deller@smsail.com>
Subject: RE: Trivial Ada question
Date: Fri, 28 Jun 2002 16:38:30 -0500
Date: 2002-06-28T16:38:30-05:00	[thread overview]
Message-ID: <mailman.1025300403.5384.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: <3D1C4BC9.5010504@telepath.com>

I'd prefer
   ...
   function All_Some_Condition (A : Some_Array) return Boolean is
   begin
    for I in A'range loop
       if not some_condition A(I) then
          return False ;
       end if ;
    end loop ;
    return True ;
   end All_Some_Condition ;
 begin
   ...
   if All_Some_Condition(A) then
    N := N+1 ;
   end if ;
   ...

That seems to make the intention clearer and the main-line code is easy
to read as well.

If you have a lot of "conditions" then you could make a generic
"All_Are" and instantiate with a function computing the necessary
condition.  In the case above, you are simply writing an explicit
instance, e.g.
    function All_True ...
      ...
         if not A(I) then ...

or
    function All_Less_Than_100 ...
      ...
         if not ( A() < 100 ) ...

Regards,
Steve




  reply	other threads:[~2002-06-28 21:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-28  9:07 Trivial Ada question Reinert Korsnes
2002-06-28 10:10 ` David C. Hoos, Sr.
2002-06-28 10:54   ` Reinert Korsnes
2002-06-28 10:57     ` Reinert Korsnes
2002-06-28 11:33       ` David C. Hoos, Sr.
2002-06-28 11:44     ` Ted Dennison
2002-06-28 21:38       ` Steven Deller [this message]
2002-06-28 12:29     ` Steve Sangwine
2002-07-03 18:59   ` Robert I. Eachus
2002-07-03 19:41     ` Darren New
2002-07-04  8:28       ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04  8:59 Grein, Christoph
2002-07-04  9:15 ` Lutz Donnerhacke
2002-07-05 22:25 ` Robert I. Eachus
replies disabled

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