comp.lang.ada
 help / color / mirror / Atom feed
From: Jean-Marc Bourguet <bourguet@muelec.fpms.ac.be>
Subject: Re: ADA - VHDL
Date: 1996/07/12
Date: 1996-07-12T00:00:00+00:00	[thread overview]
Message-ID: <sgvifuq6ot.fsf@su2> (raw)
In-Reply-To: 31E2391F.A16BEBD@sh.bel.alcatel.be


mfeldman@seas.gwu.edu (Michael Feldman) writes
> 
> In article <dewar.837036283@schonberg>, Robert Dewar
> <dewar@cs.nyu.edu> 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




  parent reply	other threads:[~1996-07-12  0:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-09  0:00 ADA - VHDL P. Cnudde VH14 (8218)
1996-07-09  0:00 ` Jacques Rouillard
1996-07-10  0:00 ` Paul B. Graham
1996-07-10  0:00   ` Laurent Gasser
1996-07-11  0:00     ` P. Cnudde VH14 (8218)
1996-07-12  0:00       ` Paul B. Graham
1996-07-10  0:00   ` Robert Dewar
1996-07-11  0:00     ` Michael Feldman
1996-07-11  0:00 ` Jean-Marc Bourguet
1996-07-11  0:00 ` Jens Hansson
1996-07-11  0:00 ` Robert Dewar
1996-07-15  0:00   ` Brian "Cheebie" Merchant
1996-07-16  0:00     ` Stephen A. Bailey
1996-07-16  0:00     ` jos de laender vh14 7461
1996-07-16  0:00     ` P. Cnudde VH14 (8218)
1996-07-22  0:00     ` Nick Weavers
1996-07-12  0:00 ` Jean-Marc Bourguet [this message]
1996-07-13  0:00   ` Michael Feldman
1996-07-17  0:00 ` Chris Papademetrious
replies disabled

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