From: Georg Bauhaus on
A totally meaningless example just to illustrate
the question: What is it that a compiler must report
for the case statement below, if anything?

procedure CE is

type DOW is (Mo, Tu, We, Th, Fr, Sa, So);

procedure P is begin null; end P;

D: constant DOW := We;
begin
case D is
when Mo | We | Fr => P;
when (if D = We or D = Fr then So else Sa) => P;
when Tu | Th => P;
end case;
end CE;



Georg
From: Pascal Obry on
Le 30/06/2010 12:39, Georg Bauhaus a �crit :
> procedure CE is
>
> type DOW is (Mo, Tu, We, Th, Fr, Sa, So);
>
> procedure P is begin null; end P;
>
> D: constant DOW := We;
> begin
> case D is
> when Mo | We | Fr => P;
> when (if D = We or D = Fr then So else Sa) => P;
> when Tu | Th => P;
> end case;
> end CE;

This should not compile I would say.

Pascal.
--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.net - http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B

From: Adam Beneschan on
On Jun 30, 3:39 am, Georg Bauhaus <rm.dash-bauh...(a)futureapps.de>
wrote:
> A totally meaningless example just to illustrate
> the question:  What is it that a compiler must report
> for the case statement below, if anything?

The choice "Sa" is not covered by any alternative. Other than that, I
don't think there's anything wrong with the CASE statement, and if you
had included a "when others =>" alternative I think it would be
legal. I'm not sure what potential problem you were trying to
illustrate.

-- Adam

>
> procedure CE is
>
>    type DOW is (Mo, Tu, We, Th, Fr, Sa, So);
>
>    procedure P is begin null; end P;
>
>    D: constant DOW := We;
> begin
>    case D is
>       when Mo | We | Fr => P;
>       when (if D = We or D = Fr then So else Sa) => P;
>       when Tu | Th  => P;
>    end case;
> end CE;
>
> Georg

From: Dmitry A. Kazakov on
On Wed, 30 Jun 2010 07:39:24 -0700 (PDT), Adam Beneschan wrote:

> On Jun 30, 3:39�am, Georg Bauhaus <rm.dash-bauh...(a)futureapps.de>
> wrote:
>> A totally meaningless example just to illustrate
>> the question: �What is it that a compiler must report
>> for the case statement below, if anything?
>
> The choice "Sa" is not covered by any alternative. Other than that, I
> don't think there's anything wrong with the CASE statement, and if you
> had included a "when others =>" alternative I think it would be
> legal. I'm not sure what potential problem you were trying to
> illustrate.

Let me propose this one instead:

� �type DOW is (Mo, Tu, We, Th, Fr, Sa, So);

� �case D is
� � � when (if D = Mo then Tu else Mo) => P;
� � � when (if D = Tu then Tu else Mo) => Q;
� � � when We..So => R;
� �end case;

The above is equivalent to:

� �case D is
� � � when Tu => P;
� � � when Mo => Q;
� � � when We..So => R;
� �end case;

But as Pascal suggested, it should not compile because D is not static.

As for the problem Georg had in mid. Maybe it is this. Let you have some
function, say Gamma function. Now,

x : constant := 0.1;
Gx : constant := Gamma (1.1); -- Illegal, what a pity

Let us open the table of Gamma, scan it, and write something like:

(if x < 0.0 then ... elsif x < 0.01 then ... )

This wonderful static function can then copied and pasted everywhere you
wanted to evaluate Gamma at compile time. Is it legal?

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Adam Beneschan on
On Jun 30, 10:35 am, "Dmitry A. Kazakov" <mail...(a)dmitry-kazakov.de>
wrote:
> On Wed, 30 Jun 2010 07:39:24 -0700 (PDT), Adam Beneschan wrote:
> > On Jun 30, 3:39 am, Georg Bauhaus <rm.dash-bauh...(a)futureapps.de>
> > wrote:
> >> A totally meaningless example just to illustrate
> >> the question: What is it that a compiler must report
> >> for the case statement below, if anything?
>
> > The choice "Sa" is not covered by any alternative.  Other than that, I
> > don't think there's anything wrong with the CASE statement, and if you
> > had included a "when others =>" alternative I think it would be
> > legal.  I'm not sure what potential problem you were trying to
> > illustrate.
>
> Let me propose this one instead:
>
>   type DOW is (Mo, Tu, We, Th, Fr, Sa, So);
>
>   case D is
>   when (if D = Mo then Tu else Mo) => P;
>   when (if D = Tu then Tu else Mo) => Q;
>   when We..So => R;
>   end case;
>
> The above is equivalent to:
>
>   case D is
>   when Tu => P;
>   when Mo => Q;
>   when We..So => R;
>   end case;
>
> But as Pascal suggested, it should not compile because D is not static.

Ummm, not quite, because (1) Pascal didn't say anything about *why* he
thought it shouldn't compile (his entire statement was "This should
not compile I would say"), and (2) in the OP's original example, D
*is* static. In your example, you're right that it shouldn't compile
because D is not static, but that's a different issue. (Well, I
*assume* D isn't static. Since your example doesn't include a
declaration of D, I can't tell.)


> As for the problem Georg had in mid. Maybe it is this. Let you have some
> function, say Gamma function. Now,
>
>    x : constant := 0.1;
>    Gx : constant := Gamma (1.1); -- Illegal, what a pity
>
> Let us open the table of Gamma, scan it, and write something like:
>
>    (if x < 0.0 then ... elsif x < 0.01 then ... )
>
> This wonderful static function can then copied and pasted everywhere you
> wanted to evaluate Gamma at compile time. Is it legal?

Gamma cannot be a static function (4.9(18-22)). You cannot write a
static function (other than an enumeration literal, which is
technically a static function).

-- Adam