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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,d00514eb0749375b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!feeder.erje.net!border3.nntp.ams.giganews.com!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Sun, 31 Oct 2010 16:17:04 -0500 From: Brian Drummond Newsgroups: comp.lang.ada Subject: Re: initialize an array (1-D) at elaboration using an expression based on the index? Date: Sun, 31 Oct 2010 21:26:21 +0000 Reply-To: brian@shapes.demon.co.uk Message-ID: References: <1f6bad81-e3d2-428b-a1a0-45acc7f96f68@m7g2000yqm.googlegroups.com> <9df4e5eb-fba7-4e8c-ba44-cd1ad4081d3b@26g2000yqv.googlegroups.com> <985a178c-8dfc-48af-9871-76a64750a571@l14g2000yqb.googlegroups.com> <2penc6lgsop1583vmg9i0m429ri4ajaf9n@4ax.com> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-OCg/Prp9D/dPzIrEYDrotaOVQk8PHZ7Pbkz/3A5KFnqXoijKS+sOZwPrfN6QCZTLa/Z+xxjOAUdsubX!ZB5ESUKVA5wP/23xcvsB2Bi8bHAVQAZlCUDvRYwz38MnJjfa6B5Mt8/GydC9XxIFerhFAwAIy8Lv!mOE= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 5529 Xref: g2news2.google.com comp.lang.ada:16043 Date: 2010-10-31T21:26:21+00:00 List-Id: On Sun, 31 Oct 2010 12:00:20 -0700 (PDT), Shark8 wrote: >> ... having been raised on Algol-W I am delighted to see them come back. >> >> Is it their unfamiliarity that disturbs you? > >No, not so much. >I don't see how they are [strictly-speaking] necessary, given that we >have declare-blocks (which can be arbitrarily-nested). >Granted, they would make it a lot less verbose in many cases. {BTW, if >we're going to allow if/then statements inside expressions & >assignments/initializations then what's keeping us from using case- >statements too?} Nothing, as long as we can escape from expecting that all languages should look like C... >> They don't appear to have the same possibility for disaster as your C example, >> and have been around in some form in VHDL for decades. > >That's quite true. However, I've learned to be careful around C/C++; >they are full of little inconsistencies that the compiler will happily >consume, Absolutely ... aaah, perhaps you have C's :? syntax in mind... That makes me uncomfortable too, and it took me a long time to figure out why. It's psychological; given the additional circumstances that booleans are integers in C, I am strongly conditioned to expect the choices to be in ascending order ( i.e. 0, 1, ... yet they are in descending order). Given that, I have always regarded C's ?: conditional operator as a poor relation to if-expressions. (I can still never read it correctly without stopping and thinking.) Algol-W allows if- and case-expressions; as you suggest, there is no reason to allow one and prohibit the other. (approximate Ada syntax - untested!) days := case month is feb => if leap(year) then 29 else 28; apr, jun, sept, nov =>30; others => 31; > >> (In the combinatorial/parallel part of the language. VHDL2008 reintroduces them >> to the sequential part, inside processes) > >Interesting; what is the VHDL syntax for them, if I might ask? A 2-way multiplexer can be written as S <= A when SEL_A else B; (A, B, SEL_A, S are signals, SEL_A is of type Boolean) For this example I am using capitals for labels, lower case for keywords, but VHDL is case-insensitive like Ada. A 4-way multiplexer can be written as with SEL select S <= A when 0, B when 1, C when 2, D when 3, 'Z' when others; In this example, SEL is an integer signal. S and A..D are signals of a type (std_logic) which allows a value 'Z' which means tristate or high impedance. This means that S is undriven in the "others" case, and may be driven by some other entity (not shown). Otherwise the example could have ended at " D when others; " or even " D when 3;" for which SEL should be an appropriately ranged integer type! Signals in VHDL are (slightly) similar to Occam channels, or rendezvous between Ada tasks, which are likewise similar to VHDL processes. Thus the 2-way mux above is shorthand for process (A,B,SEL_A); begin if SEL_A then S <= A; else S <= B; end if; end process; This process wakes up on any event on any signal in its sensitivity list (A,B,SEL_A, entries in Ada terms) and executes its sequential code until either completion or a "wait" statement. In this case, the sequential code is merely a conditional statement and one of two possible signal assignments. However it could use almost any sequential code construct familiar from Ada. <= here denotes signal assignment, which can wake up other processes sensitive to S. Processes can also have variables with the familiar := assignment; these are only visible within the process, while signals connect between processes. VHDL2008 allows the "when" and "select" forms in expressions within the sequential code in processes. Why "when" and "select" when it uses "if" and "case" to denote the equivalent statements, is a mystery to me... - Brian