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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3d6ef988ec3a5ef7 X-Google-Attributes: gid103376,public From: mheaney@ni.net (Matthew Heaney) Subject: Re: renaming Interfaces.Java.Ada_To_Java_String to the + operator Date: 1998/01/10 Message-ID: #1/1 X-Deja-AN: 314875769 Content-Transfer-Encoding: 8bit References: <01bd1e34$1632c2c0$24326489@Westley-PC.calspan.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Organization: Estormza Software Newsgroups: comp.lang.ada Date: 1998-01-10T00:00:00+00:00 List-Id: In article , dewar@merv.cs.nyu.edu (Robert Dewar) wrote: >Also in a typical situation there is no real reason to think of conversion >in one direction being in any way non-symmetrical with conversion in the >other direction. The normal technique (for those who like the unary plus >technique, be aware that there are some people who *really* dislike this >usage) is to simply use "+" for both directions. The overloading resolution >figures out which one you are talking about. I like this use of "+" as a conversion operation too. I often use it bounded strings: subtype VString_Length_Range is Natural range 0 .. 80; type VSTring (Length : VSTring_Length_Range := 0) is record S : String (1 .. Length); end record; function "+" (S : String) return VString is begin return VString'(S'Length, S); end; function "+" (VS : String) return String is begin return VS.S; end; This way you can simulate something close to what you can do in C: declare Table : constant VString_Array := (+"this is a first element", +"second", +"yet another", +"this is the very last string I promise"); begin ... If you meet someone who dislikes this use of "+", then tell them how it's refered to in the RM: as the "identity" operator. It has just the sort of benign semantics Robert was refering to, which makes it ideal for this kind of thing. It's a more or less definitionless operator that the programmer can define herself, to have the semantics she wants. Perhaps the RM should have made this more clear. I think I read somewhere how Stroustrup thought that the identity operator was basically useless, as it has no useful semantics. That may be true in C++, because the programmer can define conversion operators that get invoked automatically. But in Ada, what you see is what you get (except for Controlled types), and so some constructor has to be called explicitly. The identity operator has just the syntactic lightness we're looking for here. -------------------------------------------------------------------- Matthew Heaney Software Development Consultant (818) 985-1271