comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: SPARK: missing case value
Date: Fri, 9 Oct 2015 17:10:18 +0200
Date: 2015-10-09T17:10:18+02:00	[thread overview]
Message-ID: <owu3jtbtdvce.14rqd6apnvnwi.dlg@40tude.net> (raw)
In-Reply-To: 87twq09ke2.fsf@theworld.com

On Fri, 09 Oct 2015 10:39:01 -0400, Bob Duff wrote:

> But this works:
> 
>    type Enum is (A, B, C);
>    subtype A_C is Enum with Predicate => A_C /= B;
> 
>    procedure Test (E : in A_C) is
>    begin
>       case E is
>          when A => null;
>          -- "when B" is not needed.
>          when C => null;
>       end case;
>    end Test;
> 
> And that has the advantage that A_C need not be a subrange;
> it can have holes.
> 
> I find that predicates are often better than preconditions,
> because the same precondition often applies to many parameters,
> and also to local variables.  The predicate allows you to avoid
> repetition.

Because the above is a proper contract, while precondition is a land mine.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  reply	other threads:[~2015-10-09 15:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09 11:38 SPARK: missing case value Maciej Sobczak
2015-10-09 12:28 ` Stefan.Lucks
2015-10-09 12:35 ` Mark Lorenzen
2015-10-09 14:53   ` Bob Duff
2015-10-09 14:39 ` Bob Duff
2015-10-09 15:10   ` Dmitry A. Kazakov [this message]
2015-10-09 15:22     ` Bob Duff
2015-10-09 15:34       ` Dmitry A. Kazakov
2015-10-09 16:20     ` G.B.
2015-10-09 16:35       ` Dmitry A. Kazakov
2015-10-09 20:29         ` Georg Bauhaus
2015-10-09 21:01           ` Dmitry A. Kazakov
2015-10-10  6:44             ` Randy Brukardt
2015-10-10  9:10             ` Georg Bauhaus
2015-10-10 10:00               ` Dmitry A. Kazakov
2015-10-10 14:19                 ` Georg Bauhaus
2015-10-11  9:49                   ` Dmitry A. Kazakov
replies disabled

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