From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:aed:3441:: with SMTP id w59mr944387qtd.153.1610484685191; Tue, 12 Jan 2021 12:51:25 -0800 (PST) X-Received: by 2002:a5b:107:: with SMTP id 7mr1784038ybx.253.1610484685003; Tue, 12 Jan 2021 12:51:25 -0800 (PST) Path: eternal-september.org!reader02.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 12 Jan 2021 12:51:24 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=146.5.2.231; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC NNTP-Posting-Host: 146.5.2.231 References: <1cc09f04-98f2-4ef3-ac84-9a9ca5aa3fd5n@googlegroups.com> <37ada5ff-eee7-4082-ad20-3bd65b5a2778n@googlegroups.com> <26cac901-b901-4c4f-aba9-eab6cbd2a525n@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <50f68100-8909-4fdb-ad26-14bcbc010775n@googlegroups.com> Subject: Re: Lower bounds of Strings From: Shark8 Injection-Date: Tue, 12 Jan 2021 20:51:25 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:61111 List-Id: On Tuesday, January 12, 2021 at 1:12:35 AM UTC-7, Randy Brukardt wrote: > "Shark8" wrote in message > news:26cac901-b901-4c4f > On Friday, January 8, 2021 at 7:31:40 PM UTC-7, Randy Brukardt wrote: > ... > > >Can you give some examples here? > > All of the super-null nonsense occurs because of slices, which slows down > > any code that uses them. > What do you mean "super-null" nonsense? > Any range that is null is treated as the same by Ada. Any null range where > the bounds are more than 1 apart is known as a "super-null" range. For > instance, one typically writes: > > N : String(1..0) > > to define a null string object. But you can write *any* null range here: > > N2 : String(314 .. 25); > > And it takes code to figure this out at runtime if either bound is nonstatic > (which is usually the case with slices). And you still have to store the > bounds (you can still ask for the bounds of N2, and one better get 314 and > 25, but the length is still zero). And N = N2, so compares are complicated > (one has to check the length, but that's more expensive to figure out than > just a subtract). You end up generating a lot of code to deal with a rather > unlikely case. I understand now. You mention the case where the difference in the indices is 1 as being separate; why? Also, would the sometimes talked about idea of a "null range" have helped the situation out? (I don't think so, since the one is the required implementation, and the other is a syntax- and partially semantic-issue.) > One of the reasons for suggesting using the bounded vector as a model is all > of this sort of stuff vanishes, as the lower bound never changes in the > vector packages. Only the upper bound moves, which is what is needed the > vast majority of the time. True. I always thought the C model of strings/arrays was stupid; even accepting array=address/ equating 'offset' and 'index' is just asking for trouble, and it forces you to discard half your possible length, given a signed "int". Having an unsigned "int" and indexing off 1 gets rid of the idiocy of having a single negative value of importance (-1) for signalling "not here" to string handling functions... > > Both the early Pascal compilers we used in the very early days of Janus/Ada, > and Janus/Ada itself, used a form of bounded strings rather than the more > complex Ada model. (The CS 701 language that we originally were tasked to > implement used bounded strings, and we kept it on our early commercial > compilers so we could concentrate on other functionality like packages and > private types.) That was a lot easier to use than the Ada model, it was a > huge adjustment to switch to the Ada form and it bloated the code as well. Interesting information. I was thinking of implementing the thick-pointer as something like a private type simply being defined as -- Object: some 'tagged' type representing the bounds of an array. Type Object is tagged with private; [...] Function Length( Item : Object ) return Natural is (if Object.High > Object.Low then 0 else (Object.High-Object.Low)+1)