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 autolearn=ham
autolearn_force=no version=3.4.4
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 103376,1cf653444208df72
X-Google-Attributes: gid103376,public
X-Google-ArrivalTime: 2001-10-09 10:05:16 PST
Path:
archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!134.222.94.5!npeer.kpnqwest.net!news.edf.fr!not-for-mail
From: Pascal Obry
Newsgroups: comp.lang.ada
Subject: Re: ada vs. cpp
Date: 09 Oct 2001 18:55:29 +0200
Organization: Home - http://perso.wanadoo.fr/pascal.obry
Sender: obry@PASCAL
Message-ID:
References:
<9pgr68$7pu1@news.cis.okstate.edu>
<9phnic$9g5$1@nh.pace.co.uk>
<5fkv7.134136$w7.19988807@news02.optonline.net>
<9pski60j31@drn.newsguy.com>
<9psrqv016j9@drn.newsguy.com>
NNTP-Posting-Host: 163.107.131.13
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: clnews.edf.fr 1002646632 29242 163.107.131.13 (9 Oct 2001 16:57:12
GMT)
X-Complaints-To: newsadm@news.edf.fr
NNTP-Posting-Date: 9 Oct 2001 16:57:12 GMT
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.106
Xref: archiver1.google.com comp.lang.ada:14058
Date: 2001-10-09T16:57:12+00:00
List-Id:
"Mike Mohr" writes:
> subtype Code is Positive range 1 .. 4;
> subtype Arg is Positive range 6 .. 8;
>
> V2 : constant String := V1 (Arg) & '-' & V1 (Code);
>
> By all accounts I am a new Ada programmer, so I am a little confused
> by the syntax. It isn't clear to me how Code, and Arg function in the
> expression.
>
> Do strings effectively have a ( ) operator which takes a range as an
> argument?
Not an operator. For every string you can take a slice with a range,
for example with:
S : constant String := "1234567890";
This
S (2 .. 4)
will get the slice starting a position 2 and ending at position 1. In the case
above S'First (first index) is 1 and S'Last (last index) is 10.
S (2 .. 4) is the string "234".
The same can be achieve with a subtype having a specific range. The same slice
can be coded:
subtype Card_ID is Positive range 2 .. 4;
S (Card_ID)
This case is more readable in many cases because you have named the range.
What is nice when using subtype is that the range checks can be removed by the
compiler in some cases. For example, with the definitions:
subtype Ref_Range is Positive range 1 .. 10;
type Ref is new String (Ref_Range);
subtype Ref_Code is Ref_Range range 2 .. 5;
No need to check for constraint error here:
R (Ref_Code)
as Ref_Code is known to be in the range of Ref_Range!
> I read V1 (Arg) as V1.substring(Arg) in pseudo code.
>
> Arg seems to be a value rather than a type.
Arg is a type (subtype). In this example the range of this subtype is used.
Hope this is clear.
Pascal.
--
--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://perso.wanadoo.fr/pascal.obry
--|
--| "The best way to travel is by means of imagination"