From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9f99a33281d5072c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!x24g2000pro.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: When a conditional expression is static, where can it be used? Date: Wed, 30 Jun 2010 13:16:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <4c2b1ecb$0$7670$9b4e6d93@newsspool1.arcor-online.net> <555e3a37-c709-4b9b-995a-907da862d4b7@m40g2000prc.googlegroups.com> <12ok8wnj6k4sw$.ravumwbhfb1h$.dlg@40tude.net> <1nwqh57og805t.1tih31ltv91dp$.dlg@40tude.net> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1277928961 28703 127.0.0.1 (30 Jun 2010 20:16:01 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 30 Jun 2010 20:16:01 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: x24g2000pro.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:13027 Date: 2010-06-30T13:16:00-07:00 List-Id: On Jun 30, 1:00=A0pm, "Dmitry A. Kazakov" wrote: > On Wed, 30 Jun 2010 12:12:17 -0700 (PDT), Adam Beneschan wrote: > > On Jun 30, 10:35 am, "Dmitry A. Kazakov" > > wrote: > >> On Wed, 30 Jun 2010 07:39:24 -0700 (PDT), Adam Beneschan wrote: > >>> On Jun 30, 3:39 am, Georg Bauhaus > >>> 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 yo= u > >>> had included a "when others =3D>" 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 =3D Mo then Tu else Mo) =3D> P; > >> when (if D =3D Tu then Tu else Mo) =3D> Q; > >> when We..So =3D> R; > >> end case; > > >> The above is equivalent to: > > >> case D is > >> when Tu =3D> P; > >> when Mo =3D> Q; > >> when We..So =3D> 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. =A0In your example, you're right that it shouldn't compile > > because D is not static, but that's a different issue. =A0(Well, I > > *assume* D isn't static. =A0Since your example doesn't include a > > declaration of D, I can't tell.) > > So, if D is static, then all choices are defined and do not overlap, henc= e > it must compile. Right? No; it depends on what D is. On looking over your post more carefully, I'm beginning to think you accidentally left out some key information, or made some other error. You said earlier: > >> case D is > >> when (if D =3D Mo then Tu else Mo) =3D> P; > >> when (if D =3D Tu then Tu else Mo) =3D> Q; > >> when We..So =3D> R; > >> end case; > > >> The above is equivalent to: > > >> case D is > >> when Tu =3D> P; > >> when Mo =3D> Q; > >> when We..So =3D> R; > >> end case; Those are equivalent only if D is static and is equal to Mo. If D=3DTu, then it's equivalent to case D is when Mo =3D> P; when Tu =3D> Q; when We..So =3D> R; end case; If D is anything else, then it's equivalent to case D is when Mo =3D> P; when Mo =3D> Q; when We..So =3D> R; end case; which of course will not compile. > >> As for the problem Georg had in mid. Maybe it is this. Let you have so= me > >> function, say Gamma function. Now, > > >> x : constant :=3D 0.1; > >> Gx : constant :=3D 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 y= ou > >> wanted to evaluate Gamma at compile time. Is it legal? > > > Gamma cannot be a static function (4.9(18-22)). =A0You cannot write a > > static function (other than an enumeration literal, which is > > technically a static function). > > Now I do not understand you. The expression I gave is an if-operator with > only constants in it. No, the expression you gave was an if-operator with a bunch of ellipses in it. I had no idea what you meant by it, and you were talking about a function named Gamma. Please excuse me if I had trouble figuring out what you were trying to say. > I presume it is static. E.g., simplified: > > =A0 x : constant :=3D 2.0; > =A0 Gx : constant :=3D (if x <=3D 1.0 then 1.0 elsif x <=3D 2.0 then 2.0 = elsif x > <=3D 6.0 then 9.0 else 24.0); > > We could even add linear or quadratic interpolation between the points. OK, that expression is legal, and Gx is a static constant that can be used anywhere. I don't see any relationship to Georg's question, nor what point anybody is trying to make. -- Adam