home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / ada / 3617 < prev    next >
Encoding:
Internet Message Format  |  1992-12-11  |  1.7 KB

  1. Path: sparky!uunet!news.gtech.com!noc.near.net!hri.com!spool.mu.edu!darwin.sura.net!cs.ucf.edu!crigler
  2. From: crigler@cs.ucf.edu (James Crigler)
  3. Newsgroups: comp.lang.ada
  4. Subject: Re: Suggestion for multivalue boolean case for 9X
  5. Message-ID: <crigler.724102689@eola.cs.ucf.edu>
  6. Date: 11 Dec 92 19:38:09 GMT
  7. References: <dnsurber.724028252@node_26400> <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com>
  8. Sender: news@cs.ucf.edu (News system)
  9. Organization: University of Central Florida
  10. Lines: 43
  11.  
  12. dunbar@saifr00.cfsat.honeywell.com (Mark Dunbar) writes:
  13.  
  14. >In article <dnsurber.724028252@node_26400> dnsurber@lescsse.jsc.nasa.gov (Douglas N. Surber) writes:
  15. >>How many times have you seen code like the following:
  16. >>
  17. >>    if cond_1 then
  18. >>        if cond_2
  19. >>        if cond_3 then
  20. >>[...]
  21. >Using Ada83, instead of the nested if statement, one could do the following:
  22.  
  23. >  if    ( not Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
  24. >    ...
  25. >  elsif ( not Cond_1 ) and ( not Cond_2 ) and (     Cond_3 ) then
  26. >    ...
  27. >  etc.
  28.  
  29. Having done this enough times to try to find a solution, I use
  30. this:  Write a function that takes the conditions shown above as
  31. inputs and returns a value of an enumerated type, then case on the
  32. function return value like this:
  33.  
  34.   type SELECTIONS is (E1, E2, E3);
  35.  
  36.   function SELECTION (C1, C2, C3 : in BOOLEAN) is
  37.   begin
  38.      ...
  39.   end SELECTION;
  40.  
  41.   case SELECTION(COND_1, COND_2, COND_3) is
  42.     when E1 =>
  43.       STMT1;
  44.     when E2 =>
  45.       STMT2;
  46.  
  47.     etc.
  48.  
  49. This allows the condition set to be arbitrarily complex over an
  50. arbitrary value set in execution while retaining elegance in form.
  51. You can apply pragma INLINE to the selection function to obtain
  52. marginally better exection time (over the non-INLINE'd version.
  53.  
  54.   Jim Crigler
  55.