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.204.141.4 with SMTP id k4mr1828289bku.6.1338797696547; Mon, 04 Jun 2012 01:14:56 -0700 (PDT) Path: e27ni11699bkw.0!nntp.google.com!news1.google.com!volia.net!news2.volia.net!feed-A.news.volia.net!news.musoftware.de!wum.musoftware.de!news.mixmin.net!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 10:14:55 +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-04T10:14:55+02:00 List-Id: Le Mon, 04 Jun 2012 10:03:12 +0200, Dmitry A. Kazakov = a =C3=A9crit: > On Mon, 04 Jun 2012 09:48:07 +0200, Yannick Duch=C3=AAne (Hibou57) wro= te: > >> Le Mon, 04 Jun 2012 08:30:14 +0200, J-P. Rosen a = >> =C3=A9crit: >> >>> Le 04/06/2012 07:58, Yannick Duch=C3=AAne (Hibou57) a =C3=A9crit : >>>> 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 fai= l. >>> Why not: >>> type Path_Type is array (Index_Type range <>) of Character; >>> >>> ? >>> Reminder: There is nothing special to type String, you'll still have= >>> literals etc. >> >> Good idea. I did not consider this one, may be due to the natural = >> tendency >> of deriving from an already existing type with similar meaning. > > It is not natural, it is sloppy. You (1) derive when the result type = > shall > be in the same class [with class-wide objects]. You (2) clone or use = > other > means to create an independent type when there shall be no class [no > class-wide objects]. It is a conscious design choice between 1 and 2. > >> While I'm OK with this idea and feel it good, I would not apply it, >> because I would prefer to derive from String. Ada lacks a way to narr= ow >> the allowed range of a derived array type. > > subtype Punch_Card is String (1..80); -- ? A path is intently a string is all platform I know, and that's not just = a = representation trick. A punch card is not the same, and that would indee= d = be an error to derive it from a string. You may find a file path in a te= xt = file, you may not find a punch card in a text file. A string and a file'= s = path belongs to the same class. -- = =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