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=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Lower bounds of Strings Date: Tue, 5 Jan 2021 21:08:55 -0600 Organization: JSA Research & Innovation Message-ID: References: <1cc09f04-98f2-4ef3-ac84-9a9ca5aa3fd5n@googlegroups.com> Injection-Date: Wed, 6 Jan 2021 03:08:56 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="19733"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:61049 List-Id: IMHO, "String" shouldn't be an array at all. In a UTF-8 world, it makes little sense to index into a string - it would be expensive to do it based on characters (since they vary in size), and dangerous to do it based on octets (since you could get part of a character). The only real solution is to never use String in the first place. A number of people are building UTF-8 abstractions to replace String, and I expect those to become common in the coming years. Indeed, (as I've mentioned before) I would go further and abandon arrays altogether -- containers cover the same ground (or could easily) -- the vast complication of operators popping up much after type declarations, assignable slices, and supernull arrays all waste resources and cause oddities and dangers. It's a waste of time to fix arrays in Ada -- just don't use them. Randy. "Stephen Davies" wrote in message news:1cc09f04-98f2-4ef3-ac84-9a9ca5aa3fd5n@googlegroups.com... > > I'm sure this must have been discussed before, but the issue doesn't > seem to have been resolved and I think it makes Ada code look ugly and > frankly reflects poorly on the language. > > I'm referring to the fact that any subprogram with a String > parameter, e.g. Expiration_Date, has to use something like > Expiration_Date (Expiration_Date'First .. Expiration_Date'First + 1) > to refer to the first two characters rather than simply saying > Expiration_Date (1..2). > > Not only is it ugly, but it's potentially dangerous if code uses the > latter and works for ages until one day somebody passes a slice instead > of a string starting at 1 (yes, compilers might generate warnings, > but that doesn't negate the issue, imho). > > There must be many possible solutions, without breaking compatibility > for those very rare occasions where code actually makes use of the > lower bound of a string. > > e.g. Perhaps the following could be made legal and added to Standard: > > subtype Mono_String is String (1 .. <>); > > One question with this would be whether or not to allow procedure bodies > to specify parameters as Mono_String when the corresponding procedure > declaration uses String.