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=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1cf653444208df72 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-10-09 09:18:11 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!enst!enst.fr!not-for-mail From: "Steven Deller" Newsgroups: comp.lang.ada Subject: RE: ada vs. cpp Date: Tue, 9 Oct 2001 12:14:53 -0400 Organization: ENST, France Sender: comp.lang.ada-admin@ada.eu.org Message-ID: Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: avanie.enst.fr 1002644289 8126 137.194.161.2 (9 Oct 2001 16:18:09 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Tue, 9 Oct 2001 16:18:09 +0000 (UTC) To: Return-Path: X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 In-Reply-To: Importance: Normal Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org X-Mailman-Version: 2.0.4 Precedence: bulk X-Reply-To: List-Help: List-Post: List-Subscribe: , List-Id: comp.lang.ada mail<->news gateway List-Unsubscribe: , List-Archive: Errors-To: comp.lang.ada-admin@ada.eu.org X-BeenThere: comp.lang.ada@ada.eu.org Xref: archiver1.google.com comp.lang.ada:14051 Date: 2001-10-09T12:14:53-04:00 > -----Original Message----- > From: comp.lang.ada-admin@ada.eu.org > [mailto:comp.lang.ada-admin@ada.eu.org]On Behalf Of Mike Mohr > ... > By all accounts I am a new Ada programmer, so I am a little confused > by the syntax. It isn't clear to me how Code, and Arg function in the > expression. > > Do strings effectively have a ( ) operator which takes a range as an > argument? > > I read V1 (Arg) as V1.substring(Arg) in pseudo code. > > Arg seems to be a value rather than a type. > Is range effectively a parameterized type? The range constraints of Arg have values. Arg is a subtype. When referring to an array: The form Array_Name(X) -- where X is an object whose type matches the array's index type means element X of Array_Name. The form Array_Name(X..Y) ; -- where X and Y are objects and -- their types match that of the array's index type means the elements of Array_Name starting with X and ending with Y. This is called array slicing. The form Array_Name(Subtype) ; -- where Subtype is a subtype of the array's index type means the elements of the array bounded by the Subtype range. Another way to express array slicing. >>From the Ada Reference Manual 3.6.1 Index Constraints and Discrete Ranges (2) index_constraint ::= (discrete_range {, discrete_range}) (3) discrete_range ::= discrete_subtype_indication | range The way I look at it is that when indexing an array, subtype_name is a shorthand for subtype_name'range Not everyone would agree with how I look at it :-). > Perhaps this is wrong, if so please show me what is > really happening. If my guess is accurate please show > me how static/dynamic checking would be done in the > first (Ada) case. What I want is a description or > examples of those cases which would raise an error. > > You also point out that > > "There is nothing equivalent in C++ to declaring a new > type integer with restricted range" > > I understand your point, yet it isn't clear to me in the > original example, what specifically is an integer. The integer comes in by the definition within Standard of a "string": -- Declarations from "Standard" -- always "part" of a unit subtype Positive is Integer range 1 .. Integer'Last; type String is array(Positive range <>) of Character; An example that will raise a constraint_error is: -- Application code V1 : constant string := "abcdefghij" ; -- Has range 1..10 per ARM subtype Code is Positive range 1 .. 4 ; subtype Arg is Positive range 6 .. 8 ; V2 : constant String := V1 (Arg) & '-' & V1 (Code); -- No problem, ranges are within 1..10 subtype Bad is Positive range 4 .. 11 ; V3 : constant String := V1(Bad) ; -- Raises constraint error because 11 is outside 1..10 This is contrived and will always raise a constraint_error. But if V1 were read in at run-time, then its length would vary, with the possibility that if the entry was too short, then the creation of V3 would raise a constraint_error, but not if it was long enough (run-time checking). Regards, Steve "Then, after a second or so, nothing continued to happen." Steven Deller Smooth Sailing LLC 410 757 6924 deller@smsail.com