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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,602b7f606b0d64e2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-12 11:24:18 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!ra.nrl.navy.mil!dca6-feed2.news.algx.net!dca1-feed1.news.algx.net!allegiance!dca1-nnrp1.news.algx.net.POSTED!not-for-mail Sender: kst@king.cts.com Newsgroups: comp.lang.ada Subject: Re: Private discrete type as index References: From: Keith Thompson Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sun, 12 Jan 2003 19:23:38 GMT NNTP-Posting-Host: 209.68.192.180 X-Complaints-To: abuse@algx.net X-Trace: dca1-nnrp1.news.algx.net 1042399418 209.68.192.180 (Sun, 12 Jan 2003 14:23:38 EST) NNTP-Posting-Date: Sun, 12 Jan 2003 14:23:38 EST Organization: Allegiance Internet - Greenbelt, MD Xref: archiver1.google.com comp.lang.ada:32942 Date: 2003-01-12T19:23:38+00:00 List-Id: "AG" writes: > Guess I have a question that I'm a bit puzzled about. > Consider the boiled-down code snippet: > > package test is > type x is limited private; > type test is array(x) of boolean; > private > type x is new boolean; > end test; > > Trying to compile that fails on GNAT with "Discrete type required" > error. Can't blame it, of course, since it's correct according to > LRM. But... > > the obvious intention was to provide a set of "+/-" operations etc > on the limited type (which are not trivial) and prevent the > out-of-package clients from messing with the index. > > Since the compiler obviously knows the implementation details, why > not? > > Of course, it can be implemented as an iterator, but what's wrong > with the example as written? After all, the client modules can't use > that index other than through the type and operation provided by the > package. Compiler/linker sure knows what the type is. So, why not? I think you really want to overload the array indexing operation. Ada doesn't let you do that. If you want your index type to be limited private, you'll have to provide the indexing operations (setting and retrieving elements) as explicit functions. If you want to use actual array indexing, you'll need to use a visibly discrete index type. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> Schroedinger does Shakespeare: "To be *and* not to be"