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,5430b81ad265fc75 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-14 11:43:09 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer2.atl.newshosting.com!140.99.99.194.MISMATCH!newsfeed1.easynews.com!easynews.com!easynews!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3E4D46B9.6060805@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Array Of Constant Strings? References: <19guh-2f4.ln1@beastie.ix.netcom.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 14 Feb 2003 19:41:36 GMT NNTP-Posting-Host: 63.184.32.226 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1045251696 63.184.32.226 (Fri, 14 Feb 2003 11:41:36 PST) NNTP-Posting-Date: Fri, 14 Feb 2003 11:41:36 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:34105 Date: 2003-02-14T19:41:36+00:00 List-Id: Dennis Lee Bieber wrote: > Ah, but perusal of the reference manual appendix A indicates that > bounded string is a private type, which means no direct assignment to > it. This is not right. Assignment is defined for private types; assignment is not defined for limited types. Maybe that's not what was meant, but it's what it looks like to me. >>I can throw in explicit conversion functions: >> >> function To_Name_String(Source: String; >> Drop: Truncation := Right) >> return Name_String renames >> Name_Package.To_Bounded_String; >> >>and then make the Name_List this way: >> >> Name_List : constant array(1..26) of Name_String := >> (To_Name_String("Anthony"), >> To_Name_String("Barbara"), >> To_Name_String("Claudia"), >> ... and so on. Name_Package.To_Bounded_String returns Name_Package.Bounded_String, not Name_String, which is a different type. This renaming is not accepted by GNAT 3.15p (assuming appropriate visibility of Truncation and Right). In any event, the derived type Name_String inherits the function To_Bounded_String which is directly visible, so no renaming is necessary. Some people like to use a unary operator such as "+" for common conversions. There was a proposal for the Ada 95 revision to allow a special unary operator with no predefined meaning for this purpose. It wasn't accepted, and that turns out to be good, since the character for the operator symbol that would have been used has now been changed to the Euro symbol. Personally I think "\" would be a good operator for this simply to give C people fits :) So, if you rename To_Bounded_String to "+", you could write Name_List : constant array (1 .. 26) of Name_String := (+"Anthony", +"Barbara", +"Claudia", ... and so on. I don't like this, though. One of Ada's explicit design goals is to emphasize ease of reading over ease of writing, and "To_Bounded_String" is clearer than "+" to the reader. This is the opposite of C's philosophy, in which ease of writing is everything and ease of reading is unimportant. Ada.Strings.Bounded.Generic_Bounded_Length is intended to be mentioned in a use clause; it's written in such a way that things are still easy to understand in that case. So I would recommend: package Package_Name_Is_An_Elephant is new Generic_Bounded_Length (7); use Package_Name_Is_An_Elephant; Name_List : constant array (1 .. 26) of Bounded_String := (To_Bounded_String ("Anthony"), ...); If all the strings are always the same length, then using fixed length strings is even simpler. However, I would tend to be suspicious of such a requirement; things like that are almost always changed later. > with Ada.Strings.Fixed; use Ada.Strings.Fixed; > procedure aoc is > type Name_String is new String(1..7); > > Name_List : constant array(1..5) of Name_String := > ("Anthony", > "Barbara", > "Claudia", > "Deborah", > "Elliott" ); > begin > Null; > end aoc; Why is Ada.Strings.Fixed mentioned here? It's not used anywhere. -- Jeff Carter "Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!" Monty Python's Flying Circus