comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@ni.net (Matthew Heaney)
Subject: Re: renaming Interfaces.Java.Ada_To_Java_String to the + operator
Date: 1998/01/10
Date: 1998-01-10T00:00:00+00:00	[thread overview]
Message-ID: <mheaney-ya023680001001982248520001@news.ni.net> (raw)
In-Reply-To: dewar.884489205@merv


In article <dewar.884489205@merv>, 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
<mailto:matthew_heaney@acm.org>
(818) 985-1271




  reply	other threads:[~1998-01-10  0:00 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-11  0:00 renaming Interfaces.Java.Ada_To_Java_String to the + operator Terry J. Westley
1998-01-10  0:00 ` Robert Dewar
1998-01-10  0:00   ` Matthew Heaney [this message]
1998-01-13  0:00     ` Tom Moran
1998-01-13  0:00       ` Stephen Leake
1998-01-13  0:00         ` Nick Roberts
1998-01-13  0:00       ` Stephen Leake
1998-01-13  0:00       ` Robert Dewar
     [not found]       ` <En3Cxz.7HD@world.std.com>
1998-01-20  0:00         ` Robert Dewar
1998-01-21  0:00           ` Stephen Leake
1998-01-22  0:00           ` Robert Dewar
1998-01-22  0:00             ` Anonymous
     [not found]               ` <dewar.885498969@merv>
1998-01-23  0:00                 ` Geert Bosch
1998-01-23  0:00                 ` Tom Moran
1998-01-23  0:00             ` Anonymous
1998-01-24  0:00             ` Tucker Taft
1998-01-11  0:00   ` Chris Morgan
1998-01-11  0:00     ` Robert Dewar
1998-01-11  0:00       ` Chris Morgan
1998-01-11  0:00         ` Robert Dewar
1998-01-11  0:00           ` Chris Morgan
1998-01-11  0:00             ` Robert Dewar
1998-01-11  0:00 ` Nick Roberts
1998-01-11  0:00   ` Brian Rogoff
1998-01-13  0:00     ` Terry J. Westley
1998-01-14  0:00       ` Robert Dewar
1998-01-15  0:00         ` Nick Roberts
1998-01-15  0:00           ` Robert Dewar
1998-01-16  0:00           ` Michael F Brenner
1998-01-16  0:00             ` Nick Roberts
1998-01-16  0:00               ` Robert Dewar
1998-01-17  0:00                 ` miniscences Nick Roberts
1998-01-17  0:00                   ` miniscences Robert Dewar
1998-01-19  0:00                 ` renaming Interfaces.Java.Ada_To_Java_String to the + operator Anonymous
1998-01-25  0:00                   ` Matthew Heaney
1998-01-16  0:00             ` Robert Dewar
1998-01-11  0:00   ` Robert Dewar
1998-01-14  0:00     ` Anonymous
1998-01-14  0:00       ` Robert Dewar
1998-01-12  0:00 ` Tucker Taft
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox