Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics

From: Robert I. Eachus (rieachus_at_comcast.net)
Date: 06/26/04

  • Next message: Andrew Carroll: "Advantages"
    Date: Sat, 26 Jun 2004 01:11:20 -0400
    
    

    Robert I. Eachus wrote:

    > I do think it is a shame though that Ada returns the upper case version
    > of the name, not the spelling used to declare the type...

    This comment of mine seems to have touched a nerve. So let's see if we
    can save the good parts of the discussion and turn them into something
    useful.

    As I see it there are three approaches to solving the problem: Explicit
    user code, compiler implemented langage extensions, and changes to the
    language. I think we should agree that it is too late to chage the
    language this time around--although if there is an approach that is
    universally accepted, it could happen. But first let's look at the
    candidates and see which fly and which get shot down.

    I'll discuss user code first, then tomorrow sum up the other alternatives.

    This is almost a "why didn't I think of that?" category. It is certainly
    no big deal to write:

    function Image(S: Suit) return String is
    begin return Suit'Image(S); end Image;

    Then later when it is time to make the output look pretty change the
    body to:

    function Image(S: Suit) return String is
    begin
       case S is
           when Spades => return "Spades";
           when Hearts => return "Hearts";
           when Clubs => return "Clubs";
           when Diamonds => return "Diamonds";
       end case;
    end Image;

    or you can write:

    with Ada.Characters.Handling;
       function Mixed (S: in String) return String is
         use Ada.Characters.Handling;
         Capitalize: Boolean := True;
         Result: String := S;
       begin
         for I in Result'Range loop
           if Capitalize
           then Result(I) := To_Upper(Result(I));
           else Result(I) := To_Lower(Result(I));
           end if;
           Capitalize := Result(I) = '_';
         end loop;
         return Result;
       end Mixed;

    and:

    type Direction is (North, NNE, NE, ENE, East, ESE, SE, SSE,
                        South, SSW, SW, WSW, West, WNW, NW, NNW);

    function Image(D: Direction) return String is
        Result: String := D'Image;
    begin
       if Result'Length < 4
       then return Result;
       else return Mixed(Result);
       end if;
    end Image;

    or:

    type Color is (Red, Orange, Yellow, Blue, Green, Violet,
                    White, Gray, Black, Brown, Pink);

    function Image (C: Color) return String is
    begin return Mixed(C); end Image;

    It might be nice to add Mixed above to Ada.Characters.Handling as
    To_Mixed, but that is getting into other options. ;-)

    -- 
                                               Robert I. Eachus
    "Reason and experience both forbid us to expect that national morality 
    can prevail in exclusion of religious principles." -- George Washington
    

  • Next message: Andrew Carroll: "Advantages"

    Relevant Pages

    • Re: _ecvt, _gcvt and _fcvt problem
      ... The question is...Do you understand what Robert ... >>>But I have problem about conversion double to string. ... >> problem I strongly recommend taking some time to learn about UNICODE. ... >> please indicate which newsgroup and message). ...
      (microsoft.public.windowsce.embedded.vc)
    • Re: User Define Array Data Type - Subscript out of range
      ... Works just DANDY, Robert! ... strDataType As String ... ' Load Array ...
      (microsoft.public.access.modulesdaovba)
    • Re: String.each
      ... On 3/3/07, Robert Klemme wrote: ... >>> each character of a string and then processes it using a block. ... String's enumeration is a bit weird and inconsistent. ... String as array of lines does have it's uses at times but I wonder ...
      (comp.lang.ruby)
    • Re: send problems linux
      ... On 2003-10-29, Robert wrote: ... do 'send' your buffer is copied into system buffer. ... 'send' then your new string is appended to the previous string. ... *stream* you read merged line. ...
      (comp.unix.programmer)
    • Re: Color
      ... John Timney (MVP) ... How can I convert a variable of type color to a String where the color ...
      (microsoft.public.dotnet.framework.aspnet)