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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.244.225 with SMTP id xj1mr2606931pac.7.1460480132979; Tue, 12 Apr 2016 09:55:32 -0700 (PDT) X-Received: by 10.157.14.207 with SMTP id 73mr44337otj.13.1460480132932; Tue, 12 Apr 2016 09:55:32 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!gy3no2873751igb.0!news-out.google.com!u9ni202igk.0!nntp.google.com!nt3no11859364igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 12 Apr 2016 09:55:32 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.166.228.46; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR NNTP-Posting-Host: 85.166.228.46 References: <2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Substrings as argument to procedures/functions From: reinkor Injection-Date: Tue, 12 Apr 2016 16:55:32 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:30083 Date: 2016-04-12T09:55:32-07:00 List-Id: On Tuesday, April 12, 2016 at 11:02:03 AM UTC+2, Dmitry A. Kazakov wrote: > On 12/04/2016 10:25, reinkor wrote: > > > I believed that if a substring is an argument to a subroutine, > > then its "range" would start at 1 (and not inherited from the calling program). > > But this seems not to be the case. > > > > Given the following Ada source code: > > > > with Text_IO; > > use Text_IO; > > procedure t3 is > > package Int_Io is new Text_IO.Integer_Io (Integer); > > use Int_Io; > > procedure string_test1(S : String) is > > begin > > New_Line; > > Put(" In string_test1: "); > > Put(S'First,4); > > Put(S'Last,4); > > end string_test1; > > Str : String := "ABCDEF"; > > begin > > string_test1(Str); > > string_test1(Str(3..5)); > > end t3; > > > > The second call to "string_test1" gives: > > > > In string_test1: 3 5 > > > > (at least on my computer). > > > > Is this correct? And in case, is it "good" ? :-) > > Yes, it is good. > > Consider a program that uses an index to walk through a string/array. > When you pass a substring of the string and an index into it (usually > in-out) down to a subprogram, then the index remains valid. > > -- > Regards, > Dmitry A. Kazakov > http://www.dmitry-kazakov.de But as far as I remember, several other program languages do not bring the initial indexing down to subroutines like this? Anyway, one may for example copy strings in soubroutines if one really want to start indexing at one. Sometimes I want the soubroutines not to "know" too much :-)