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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a20ed8b5fc3cad81 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!b28g2000cwb.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: Extended 'Succ attribute? Date: 22 Nov 2006 18:04:37 -0800 Organization: http://groups.google.com Message-ID: <1164247477.100738.32670@b28g2000cwb.googlegroups.com> References: <1164243308.957573.223990@l39g2000cwd.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1164247482 15569 127.0.0.1 (23 Nov 2006 02:04:42 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 23 Nov 2006 02:04:42 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: b28g2000cwb.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:7654 Date: 2006-11-22T18:04:37-08:00 List-Id: J=E9r=E9mie 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 :=3D T_DAY'(Sun); > day :=3D 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 :=3D 0; Tue : constant T_DAY :=3D 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