home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / ada / 3676 < prev    next >
Encoding:
Text File  |  1992-12-14  |  2.9 KB  |  93 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!dog.ee.lbl.gov!news!nosc!dale.cts.com!jhb
  3. From: jhb@dale.cts.com (John Bollenbacher)
  4. Subject: Re: Suggestion for multivalue boolean case for 9X
  5. Message-ID: <Bz9pCA.MA6@dale.cts.com>
  6. Sender: news@dale.cts.com (USENET News Account)
  7. Organization: Titan Linkabit Corporation
  8. X-Newsreader: Tin 1.1 PL5
  9. References: <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com>
  10. Date: Mon, 14 Dec 1992 21:07:21 GMT
  11. Lines: 80
  12.  
  13. Mark Dunbar (dunbar@saifr00.cfsat.honeywell.com) wrote:
  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. : >        s_t_t_t;
  21. : >        else
  22. : >        s_t_t_f;
  23. : >        end if;
  24. : >    else
  25. : >        if cond_3 then
  26. : >        s_t_f_t;
  27. : >        else
  28. : >        s_t_f_f;
  29. : >        end if;
  30. : >    end if;
  31. :       [etc]...
  32. : >I find this hard to read and even harder to maintain.  Cond_3 appears
  33. : >four times.  That's a maintenance nightmare.  A case statement that
  34. : >worked on arrays of booleans would be a big improvement.  Something like
  35. : >the following:
  36. : >
  37. : >    case (cond_1, cond_2, cond_3) is
  38. : >    when (true,  true,  true ) =>
  39. : >        s_t_t_t;
  40. : >    when (true,  true,  false) =>
  41. : >        s_t_t_f;
  42. : >    when (true,  false, true ) =>
  43. : >        s_t_f_t;
  44. : >    when (true,  false, false) =>
  45. : >        s_t_f_f;
  46. :     [etc]...
  47. : >
  48. : >Douglas Surber
  49. : >Lockheed
  50. : >Houston, TX
  51. : >
  52. : Using Ada83, instead of the nested if statement, one could do the following:
  53. :   if    ( not Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
  54. :     ...
  55. :   elsif ( not Cond_1 ) and ( not Cond_2 ) and (     Cond_3 ) then
  56. :     ...
  57. :   elsif ( not Cond_1 ) and (     Cond_2 ) and ( not Cond_3 ) then
  58. :     ...
  59. :   elsif ( not Cond_1 ) and (     Cond_2 ) and (     Cond_3 ) then
  60. :     ...
  61. :   elsif (     Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then
  62. :     ...
  63. :   etc.
  64. : Although I do agree the case statement would be more elegant (sp?) and
  65. : potentially faster if there were enough branches to cancel out the
  66. : overhead of a case.
  67.  
  68. Though I also agree that the original posting has merit, another possibility 
  69. that I have used is something like:
  70.  
  71.   declare
  72.     type BOOLS is array (1..3) of BOOLEAN;
  73.     VAL : constant BOOLS := (COND_1, COND_2, COND_3);
  74.   begin
  75.     if VAL = (TRUE, TRUE, TRUE) then
  76.       ...
  77.     elsif VAL = (TRUE, TRUE, FALSE) then
  78.       ...
  79.     etc.
  80. --
  81. -----------------------------------------------------------------------------
  82. - John Bollenbacher                                        jhb@dale.cts.com -
  83. - Titan Linkabit Corp.                                       (619) 552-9963 -
  84. - 3033 Science Park Rd.                                                     -
  85. - San Diego, Ca. 92121                                                      -
  86. -----------------------------------------------------------------------------
  87.