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.8 required=5.0 tests=BAYES_00,INVALID_MSGID, SUBJ_ALL_CAPS autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2e03bc978c29ea47 X-Google-Attributes: gid103376,public X-Google-Thread: 1089ad,2e03bc978c29ea47 X-Google-Attributes: gid1089ad,public From: Jean-Marc Bourguet Subject: Re: ADA - VHDL Date: 1996/07/12 Message-ID: #1/1 X-Deja-AN: 167941032 sender: bourguet@su2 references: <31E2391F.A16BEBD@sh.bel.alcatel.be> organization: Faculte Polytechnique de Mons, Service d'Electronique x-access: 16 727 newsgroups: comp.lang.ada,comp.lang.vhdl Date: 1996-07-12T00:00:00+00:00 List-Id: mfeldman@seas.gwu.edu (Michael Feldman) writes > > In article , Robert Dewar > wrote: > > >Paul says > >"VHDL has ascending and descending ranges. Ada has only > >ascending ranges. > > >Unconvincing -- sure you will always find someone who finds X more > >"convenient and understandable" than Y (and of course someone else > >who finds Y more "convenient and understandable" than X). I do not > >find this a good basis for a gratuitous change like the above (I > >would find a change in either direction gratuitious), and indeed > >it seems that some of the differences between VHDL and Ada are > >not justified, they seem to be cases where personal taste has > >intruded unnecessarily. > > An important point here is that the ascending range syntax allows > a named range to be used for counting either up or down: > > type Days is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); > > (or any integer range as well; I just like enumerations:-)) > > Going forward in the week, one can just write > > for Day in Days loop... > > going backward, one can just write > > for Day in reverse Days loop... In VHDL a range include a direction. So you can write for Day in Days'High downto Days'Low loop to go backward (Days may be declared as an ascending or descending range). You may use for Day in Days'Right downto Days'Left loop if you know that the Days range is ascending. If you want to go in the reversed direction of Days but do not know apriori if Days is an ascending or descending range, you may have to use a test if Days'Ascending then for Day in Days'Right downto Days'Left loop ... end loop; else for Day in Days'Right to Days'Left loop .. end loop; end if; but more probably the Day variable is use to index an array (Weekly_Pay). Then you can be independent of the type of the index of Weekly_Pay and write for Day in Weekly_Pay'Range loop for the declared direction, and for Day in Weekly_Pay'Reverse_Range loop for the reversed direction. (VHDL miss a Reversed attribute that may be applied to range type...) > The real advantage here is that you can avoid "magic numbers" in > your code, so that if - to carry my stupid Days example further - > we changed the enumeration values to French ones - > > type Days is > (lundi, mardi, mercredi, jeudi, vendredi, samedi, dimanche); > > the rest of your code is unchanged. > > We could even declare an array type > > type Weekly_Pay is array (Days) of Float; (say) > > and an object > > ThisWeek: Weekly_Pay; > > and the array index, the forward loop, and the backward loop, are all > consistent and immune from inconsistent code changes. > > This is a real improvement over the Pascal loop syntax, which VHDL > borrowed and which has no way to use the named range. This is what confuse you: VHDL didn't borrow the Pascal loop syntax, but extented the notion of range in Ada to add a direction to the range characteristic. You can define subtype of Days subtype Forward_Days is Days range lundi to dimanche; subtype Backward_Days is Days range dimanche downto lundi; and use these subtype as index to an array. > Ada syntax is remarkably regular in this regard. VHDL syntax also (but miss the reversed attribute on a range but I wonder if it has practical effect. I don't see any application where you don't know the direction of a range, exept when used to constrain the index of an unconstrained index.) > (Yes, I know - there's no "by" field in an Ada for statement. > No free lunch.:-)) > Mike Feldman -- Jean-Marc Bourguet Service d'Electronique Faculte polytechnique de Mons Email : bourguet@muelec.fpms.ac.be Mons, Belgique