comp.lang.ada
 help / color / mirror / Atom feed
From: agate!spool.mu.edu!darwin.sura.net!cs.ucf.edu!crigler@ucbvax.Berkeley.EDU (James Crigler)
Subject: Re: Suggestion for multivalue boolean case for 9X
Date: 11 Dec 92 19:38:09 GMT	[thread overview]
Message-ID: <crigler.724102689@eola.cs.ucf.edu> (raw)

dunbar@saifr00.cfsat.honeywell.com (Mark Dunbar) writes:

>In article <dnsurber.724028252@node_26400> dnsurber@lescsse.jsc.nasa.gov (Doug
las N. Surber) writes:
>>How many times have you seen code like the following:
>>
>>    if cond_1 then
>>        if cond_2
>>	    if cond_3 then
>>[...]
>Using Ada83, instead of the nested if statement, one could do the following:

>  if    ( not Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
>    ...
>  elsif ( not Cond_1 ) and ( not Cond_2 ) and (     Cond_3 ) then
>    ...
>  etc.

Having done this enough times to try to find a solution, I use
this:  Write a function that takes the conditions shown above as
inputs and returns a value of an enumerated type, then case on the
function return value like this:

  type SELECTIONS is (E1, E2, E3);

  function SELECTION (C1, C2, C3 : in BOOLEAN) is
  begin
     ...
  end SELECTION;

  case SELECTION(COND_1, COND_2, COND_3) is
    when E1 =>
      STMT1;
    when E2 =>
      STMT2;

    etc.

This allows the condition set to be arbitrarily complex over an
arbitrary value set in execution while retaining elegance in form.
You can apply pragma INLINE to the selection function to obtain
marginally better exection time (over the non-INLINE'd version.

  Jim Crigler

             reply	other threads:[~1992-12-11 19:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-12-11 19:38 James Crigler [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-12-14 21:07 Suggestion for multivalue boolean case for 9X John Bollenbacher
1992-12-13 15:24 agate!spool.mu.edu!yale.edu!jvnc.net!gmd.de!Germany.EU.net!mcsun!sunic!se
1992-12-11 20:08 Alex Blakemore
1992-12-11  1:15 Mark Dunbar
1992-12-10 22:57 Douglas N. Surber
replies disabled

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