comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: Substrings as argument to procedures/functions
Date: Wed, 13 Apr 2016 13:22:38 +0200
Date: 2016-04-13T13:22:38+02:00	[thread overview]
Message-ID: <nel9vn$j50$1@dont-email.me> (raw)
In-Reply-To: <2055a188-fb5f-496a-ab37-b25d81cebe1b@googlegroups.com>

On 12.04.16 10:25, reinkor wrote:
> Dear All,
>
> 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.

> Is this correct? And in case, is it "good" ? :-)

It is a good idea, I think, not to be mislead by programming
languages that don't have expressions for iteration at all,
nor "sequence types", only emulations. That these are prone to
errors has been mentioned in this thread.  Consider

    for K in A'Range loop
       ... A(K) ...
    end loop;

or, more recently found in Ada,

    for El of A loop
       ... El ...
    end loop;

This most frequently used loop that does sequence processing
does not refer to any specific bound on A. No assumptions, or
checks are being programmed. It is safe and efficient.

Similarly, if I were using a recursive LISP style approach,
positions, or index values, do not matter either:

    function Count (A : String; X : Character) return Integer is

       function Count_Loop (K : Positive) return Natural is
       begin
          if K <= A'Last then
             return "+" (Boolean'Pos ("=" (A(K), X)),
                         Count_Loop (Positive'Succ (K)));
          else
             return 0;
          end if;
       end Count_Loop;

    begin
       return Count_Loop (A'First);
    end Count;


      parent reply	other threads:[~2016-04-13 11:22 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
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. [this message]
replies disabled

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