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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3f8d8581bfd0fa44,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-17 14:20:40 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!bloom-beacon.mit.edu!nycmny1-snh1.gtei.net!news.gtei.net!newsfeed.mathworks.com!fu-berlin.de!uni-berlin.de!pcp01485549pcs.limstn01.de.comcast.NET!not-for-mail From: Ryan Newsgroups: comp.lang.ada Subject: Array-like object indexing Date: Sat, 17 Aug 2002 17:22:33 -0700 Message-ID: <3D5EE8C9.2080601@hotmail.com> NNTP-Posting-Host: pcp01485549pcs.limstn01.de.comcast.net (68.82.51.136) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1029619238 45931980 68.82.51.136 (16 [151722]) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020722 X-Accept-Language: en-us, en, eo Xref: archiver1.google.com comp.lang.ada:28192 Date: 2002-08-17T17:22:33-07:00 List-Id: I've recently been playing with making all the standard data structures in Ada to prepare myself for writing my first major project. Currently I'm writing a resizable-array package. I am trying to make it as similar to built-in arrays as possible, with functions for First, Length and other useful operations and attributes. It is a generic package instantiated with a type for the elements to be stored and a type for indexing. I've run into a small problem with respect to the indexing type. I'm not sure how to represent the boundaries of an empty array without raising a constraint error in some cases. If an array is being indexed by Natural, for example, and the first index should be 0 (as makes sense in many situations), then what should the First and Last functions (intended to work like their analogous attributes) return? I cannot return 0 and -1 because -1 would raise a constraint error. Should the responsibility for this rest on the package or the user? Would it be a better to return 1 and 0, or to force a user of the package to instantiate it with an indexing type that starts at -1 instead even though -1 should never be used to actually look into the array? What are your opinions on this? Thank you, Ryan Tarpine