comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Enumeration representation enhancement proposal
Date: 20 Oct 2004 10:58:46 +0200
Date: 2004-10-20T07:35:51+00:00	[thread overview]
Message-ID: <rlssm89daux.fsf@jacob.crs4.it> (raw)
In-Reply-To: pan.2004.10.20.08.41.45.702628@power.com.pl

Wojtek Narczynski wrote:

> >   for Colours use (Red => 1, Green => 2, Blue => 4, Muddy => others);
> > 
> >   if Muddy < Blue then
> >      --  Do we ever get here?  Both 3 and 5 represents Muddy.  The one
> >      --  is smaller than 4 (which represents Blue), the other one
> >      --  isn't.  end if;
> >   end if;
> 
> Clearly, representation has no impact on comparison.

Wrong.

> So we do not get there, granted that such is the order of
> declaration in Ada.
> 
> The above code is not harder to compile than:

procedure Enumeration_Representation is
   type Colours is (Red, Green, Blue, Muddy);
> for Colours use (Red => 1, Green => 3, Blue => 2, Muddy => 4);
> 
> A, B : Colors;
begin
> if A < B then null; end if;
end Enumeration_Representation;

Is not correct Ada.  The LRM clearly states (can't remember where,
though) that the order of the representation should be the same as
that of the original declaration of the enumeration.

> Here the result is also rather unrelated to the underlying rep
> values order.

Except that your code isn't valid Ada.

> Also, a simple "cannonicalization" {take the least possible 'others'
> value to the register (not memory)} makes the case with 'others'
> identical to current situation.

But computationally slower. - Which I suspect is the whole reason for
the order rule for enumeration representations.

Jacob
-- 
"[...] *transfer* a bit of salary from the person who writes
 a bug to the person that finds a bug..." -- Keith Ray



  reply	other threads:[~2004-10-20  8:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-14  9:31 Enumeration representation enhancement proposal Wojtek Narczynski
2004-10-14 17:47 ` Nick Roberts
2004-10-15 11:06   ` Wojtek Narczynski
2004-10-19 14:55     ` Jacob Sparre Andersen
2004-10-20  8:41       ` Wojtek Narczynski
2004-10-20  8:58         ` Jacob Sparre Andersen [this message]
2004-10-20 11:04           ` Wojtek Narczynski
replies disabled

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