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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8623fab5750cd6aa X-Google-Attributes: gid103376,public Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Sat, 19 Jun 2004 15:40:49 -0500 Date: Sat, 19 Jun 2004 16:40:48 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics References: <40b9c99e$0$268$edfadb0f@dread16.news.tele.dk> <1086733411.736049@master.nyc.kbcfp.com> <3Auxc.11998$XY6.1296622@read2.cgocable.net> <40C85035.4020706@noplace.com> <40C9EC3B.60304@noplace.com> <40CD90A4.8030005@noplace.com> <40CEDCB5.9000509@noplace.com> <1087325485.307616@master.nyc.kbcfp.com> <1087488758.881520@master.nyc.kbcfp.com> <40d29d9f$1_1@baen1673807.greenlnk.net> In-Reply-To: <40d29d9f$1_1@baen1673807.greenlnk.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <992dncaC-JpMOUndRVn-ug@comcast.com> NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-MspblIkaUDUc6bg74FE1gw8wA4YXIJCg+JQ5bdtz0xZ35yCfDEOCIrtVuaX/X9G/iVnX3iaRfWp0ROn!eh+URbtkt8sb+ONdwzJ+TTeov1wWEwrJ4OYbtV20Yjz/tD11k1+HH5um2Z0Z+w== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: g2news1.google.com comp.lang.ada:1700 Date: 2004-06-19T16:40:48-04:00 List-Id: Martin Dowie wrote: > No because String is an unconstrained type. You could have > > type Colour_Set is array (Positive) range <>) of String (1 .. 5); > > Red : constant Sgtring := " Red"; > Green : constant String := "Green"; > Blue : constant String := "Blue"; > > Colours : constant Colour_Set (Red, Green, Blue); > > But that's not quite the same thing... (i.e. not a ragged array). Ah, but you could use Ada.Strings.Bounded: with Ada.Strings.Bounded; ... package Color_Strings is new Ada.Strings.Bounded(12); -- or your choice of bound... subtype Color_Name is Color_Strings.Bounded_String; function "+"(Source: in String) return Color_Name is begin return Color_Strings.To_Bounded_String(Source); end "+"; ... Red: constant Color_Name := +"Red"; Green: constant Color_Name := +"Green"; Blue: constant Color_Name := +"Blue"; Aquamarine: constant Color_Name := +"Aquamarine"; ... type Color_Set is array (Positive range <>) of Color_Name; Colors: constant Color_Set := (Red, Blue, Green, Aquamarine); -- Add "u" as appropriate, if you live in Blighty. ;-) You could also use Unbounded_Strings, but this is the perfect application for Bounded_String. A lot of short strings, of size known at compile time. The other case where I use Bounded_String a lot is in binding to databases. If a text field has a specific length, using Bounded_String makes it easy to detect strings too long before starting a database transaction. -- Robert I. Eachus "Reason and experience both forbid us to expect that national morality can prevail in exclusion of religious principles." -- George Washington