comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@TheWorld.com>
Subject: Re: Substrings as argument to procedures/functions
Date: Tue, 12 Apr 2016 14:17:42 -0400
Date: 2016-04-12T14:17:42-04:00	[thread overview]
Message-ID: <wccinzmy9mh.fsf@TheWorld.com> (raw)
In-Reply-To: 2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com

reinkor <reinkor@gmail.com> writes:

> 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?

Yes.

>...And in case, is it "good" ? :-)

No.  It breaks abstraction -- the procedure shouldn't have to know where
the string came from (e.g. a slice).  And it either introduces bugs
(because the code assumes S'First = 1, which is almost always true),
or it complicates the code (because you have to do arithmetic on
the bounds).

But Dmitry makes a good point.

- Bob

  parent reply	other threads:[~2016-04-12 18:17 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-12  8:25 Substrings as argument to procedures/functions reinkor
2016-04-12  9:01 ` Dmitry A. Kazakov
2016-04-12 16:55   ` reinkor
2016-04-12 18:37     ` Dmitry A. Kazakov
2016-04-13  4:44       ` reinkor
2016-04-13  7:19         ` Dmitry A. Kazakov
2016-04-13 10:16         ` Brian Drummond
2016-04-13 11:43           ` reinkor
2016-04-13 11:54             ` Pascal Obry
2016-04-13 12:30               ` Mart van de Wege
2016-04-13 12:47                 ` Egil H H
2016-04-13 13:19                   ` Mart van de Wege
2016-04-13 16:57                 ` Jeffrey R. Carter
2016-04-12 18:17 ` Robert A Duff [this message]
2016-04-12 18:34 ` Jeffrey R. Carter
2016-04-13 21:29   ` Randy Brukardt
2016-04-25 15:33     ` rieachus
2016-04-25 22:07       ` Randy Brukardt
2016-04-26  6:12         ` Georg Bauhaus
2016-04-26 18:41           ` Randy Brukardt
2016-04-13 11:22 ` G.B.
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox