From: "Adam Beneschan" <adam@irvine.com>
Subject: Re: Extended 'Succ attribute?
Date: 22 Nov 2006 18:04:37 -0800
Date: 2006-11-22T18:04:37-08:00 [thread overview]
Message-ID: <1164247477.100738.32670@b28g2000cwb.googlegroups.com> (raw)
In-Reply-To: 1164243308.957573.223990@l39g2000cwd.googlegroups.com
Jérémie Lumbroso wrote:
> Hello,
>
> I just started Ada and was wondering if there is a way to make the Succ
> attribute of discrete types behave in a cyclic manner (akin to the
> modular type):
>
> type T_DAY is (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
>
> ...
>
> day := T_DAY'(Sun);
> day := T_DAY'Succ(day); -- that this returns 'Mon' instead of
> -- a type constraint error
>
> I could of course define my own function to do this, but I wish to know
> if there is a way to get Ada to do it itself.
No.
The best you could do would be to declare a modular type, and then
declare Mon, Tue, etc. as constants of that type:
type T_DAY is mod 7;
Mon : constant T_DAY := 0;
Tue : constant T_DAY := 1;
etc.
Then T_DAY'Succ(X) will wrap around. But I don't see any advantage to
doing things this way. I'd
just make it an enumeration literal and define your own Succ function.
-- Adam
next prev parent reply other threads:[~2006-11-23 2:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-23 0:55 Extended 'Succ attribute? Jérémie Lumbroso
2006-11-23 2:04 ` Adam Beneschan [this message]
2006-11-24 13:02 ` Peter Hermann
2006-11-23 6:38 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox