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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ac4955b8006bd13c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,UTF8 Received: by 10.68.241.7 with SMTP id we7mr9604985pbc.4.1338789487298; Sun, 03 Jun 2012 22:58:07 -0700 (PDT) Path: l9ni17774pbj.0!nntp.google.com!news1.google.com!goblin3!goblin.stu.neva.ru!usenet.pasdenom.info!aioe.org!.POSTED!not-for-mail From: =?utf-8?Q?Yannick_Duch=C3=AAne_=28Hibou57?= =?utf-8?Q?=29?= Newsgroups: comp.lang.ada Subject: Re: Q: type ... is new String Date: Mon, 04 Jun 2012 07:58:06 +0200 Organization: Ada @ Home Message-ID: References: <336f4e4b-16da-4fa8-9b7a-7e2dd3a48018@w24g2000vby.googlegroups.com> NNTP-Posting-Host: Dd9R6puHiTvzf2FllTJGfQ.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.00 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: Quoted-Printable Date: 2012-06-04T07:58:06+02:00 List-Id: Le Thu, 31 May 2012 09:37:22 +0200, Maciej Sobczak = a =C3=A9crit: > On 30 Maj, 18:33, tmo...@acm.org wrote: >> Any comments on the effectiveness of using multiple types for differe= nt >> categories of strings, rather than "String" all the time? > > Interestingly, this is a bit different from defining multiple number > types instead of using standard types all the time. > The difference is that number types carry bounds as additional > information and that can be comfortably used to later define arrays, > loop ranges, etc. > Strings don't have this capability (unless, of course, you define > constrained String (A .. B) types) There is nothing like a range with text type, but there is still provisi= on = for contracts (pre/post in Ada 2012). An invariant for a Path_Type would= = be as much useful as a range for a numeric type would be. Talking about range and this particular case, prior to Ada 2012, there w= as = no way to narrow the range for a derive type of an array type, without = freezing its bounds. It's now possible with Ada 2012. Prior to Ada 2012: Minimum_Length : constant :=3D ; Maximum_Length : constant :=3D ; subtype Index_Type is Natural range Minimum_Length .. Maximum_Length= ; type Path_Type is new String (Index_Type); -- Unfortunately, this freeze the lower and upper bound, and the -- declaration below fails. XYZ_Location : Path_Type :=3D "..................."; -- Will fail. Since Ada 2012: Minimum_Length : constant :=3D ; Maximum_Length : constant :=3D ; subtype Index_Type is Natural range Minimum_Length .. Maximum_Length= ; subtype Path_Type is String with Static_Predicate =3D> Path_Type'Length in Index_Type; -- You may add additional contracts, specific to file paths, -- like conformance with a format. XYZ_Location : Path_Type :=3D "..................."; -- OK. -- = =E2=80=9CSyntactic sugar causes cancer of the semi-colons.=E2=80=9D [1] =E2=80=9CStructured Programming supports the law of the excluded muddle.= =E2=80=9D [1] [1]: Epigrams on Programming =E2=80=94 Alan J. =E2=80=94 P. Yale Univers= ity