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-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.80.34 with SMTP id o2mr1713262pax.9.1359750130266; Fri, 01 Feb 2013 12:22:10 -0800 (PST) Path: 6ni29948pbd.1!nntp.google.com!news.glorb.com!xmission!newsswitch.lcs.mit.edu!nntp.TheWorld.com!.POSTED!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Ada and string literals Date: Fri, 01 Feb 2013 15:22:09 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <4978d638-a04b-4561-85e9-cf6620265af2@googlegroups.com> <85wqus1887.fsf@stephe-leake.org> <1l8gd32wspyy5$.1u81easl2psqm$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 X-Trace: pcls6.std.com 1359750129 7270 192.74.137.71 (1 Feb 2013 20:22:09 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 1 Feb 2013 20:22:09 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:SgaqOch6SDdUUbT793mY62Z5BAs= Content-Type: text/plain; charset=us-ascii Date: 2013-02-01T15:22:09-05:00 List-Id: "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. 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. - Bob