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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,dc1fff2721602dfa X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.66.72.227 with SMTP id g3mr1709518pav.31.1359756235126; Fri, 01 Feb 2013 14:03:55 -0800 (PST) Path: s9ni30153pbb.0!nntp.google.com!news.glorb.com!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Ada and string literals Date: Fri, 1 Feb 2013 23:03:43 +0100 Organization: cbb software GmbH Message-ID: <13em3fndyae4q$.6whp93hn6pnq$.dlg@40tude.net> References: <4978d638-a04b-4561-85e9-cf6620265af2@googlegroups.com> <85wqus1887.fsf@stephe-leake.org> <1l8gd32wspyy5$.1u81easl2psqm$.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: cDN0fd8KlIeJLyErIrSf0A.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2013-02-01T23:03:43+01:00 List-Id: On Fri, 01 Feb 2013 15:22:09 -0500, Robert A Duff wrote: > "Dmitry A. Kazakov" writes: > >> On Fri, 01 Feb 2013 08:20:24 -0500, Stephen Leake wrote: >> >>> That's what "+" is for: >>> >>> function "+" (Item : in String) return access constant String >>> is begin >>> return new String'(Item); >>> end "+"; >>> >>> Colors : constant String_Sequence := >>> (+"red", -- This _is_ Ada! >>> +"orange", >>> +"dark green", >>> ...); >> >> What about: >> >> function "&" (Left, Right : String) return String_Sequence is >> begin >> return (new String'(Left), new String'(Right)); >> end "&"; >> >> function "&" (Left : String; Right : String_Sequence) >> return String_Sequence is >> begin >> return String_Sequence'(1 => new String'(Left)) & Right; >> end "&"; >> >> Colors : constant String_Sequence := "red" & "orange" & "dark green"; > > Looks dangerous to me. If I'm not mistaken, you have a bug: ;-) > the above sets Colors to a 2-element array containing a pointer > to "redorange" and a pointer to "dark green". The first "&" in Colors > calls the predefined String one, and the second "&" calls the first > "&" body shown above. The second body is never called. We could use "/" or "+" instead of "&". Colors : constant String_Sequence := "red" / "orange" / "dark green"; (still better than ugly prefix "+") > I suppose that could be fixed, but we're getting further and > further from something where the compiler is likely to generate > a statically-allocated table of pointers to statically-allocated > strings. Which is not likely the proper way for the problem at hand, anyway. I guess that the solution for what OP is supposedly doing would be an initialized map or table with string keys. Such things are initialized in the package body using "begin ... end" construct. It would be very helpful if Ada allowed that through user-defined static operations, but that is a story for another day. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de