comp.lang.ada
 help / color / mirror / Atom feed
From: aio!dnsurber@eos.arc.nasa.gov  (Douglas N. Surber)
Subject: Suggestion for multivalue boolean case for 9X
Date: 10 Dec 92 22:57:32 GMT	[thread overview]
Message-ID: <dnsurber.724028252@node_26400> (raw)

How many times have you seen code like the following:

    if cond_1 then
        if cond_2
	    if cond_3 then
		s_t_t_t;
	    else
		s_t_t_f;
	    end if;
	else
	    if cond_3 then
		s_t_f_t;
	    else
		s_t_f_f;
	    end if;
	end if;
    else
        if cond_2
	    if cond_3 then
		s_f_t_t;
	    else
		s_f_t_f;
	    end if;
	else
	    if cond_3 then
		s_f_f_t;
	    else
		s_f_f_f;
	    end if;
	end if;
    end if;

I find this hard to read and even harder to maintain.  Cond_3 appears
four times.  That's a maintenance nightmare.  A case statement that
worked on arrays of booleans would be a big improvement.  Something like
the following:

    case (cond_1, cond_2, cond_3) is
	when (true,  true,  true ) =>
	    s_t_t_t;
	when (true,  true,  false) =>
	    s_t_t_f;
	when (true,  false, true ) =>
	    s_t_f_t;
	when (true,  false, false) =>
	    s_t_f_f;
	when (false, true,  true ) =>
	    s_f_t_t;
	when (false, true,  false) =>
	    s_f_t_f;
	when (false, false, true ) =>
	    s_f_f_t;
	when (false, false, false) =>
	    s_f_f_f;
    end case;

I don't know if it's too late to consider this for 9X, but I think it
would be neat.  The compiler could verify that you had covered all of the
cases and not listed any case twice, etc.  I suppose it could be generalized
to work on arrays and records of discrete types.  That might be even better.

Yes I know you could implement a function to turn an array of bools into
an enumeration type or an integer, but that is less clear. Anyway, just
an idea.

Douglas Surber
Lockheed
Houston, TX

             reply	other threads:[~1992-12-10 22:57 UTC|newest]

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

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