Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics
From: Robert I. Eachus (rieachus_at_comcast.net)
Date: 06/26/04
- Previous message: Zork: "Considering taking an ADA course at uni"
- In reply to: Robert I. Eachus: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Next in thread: Jeffrey Carter: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Reply: Jeffrey Carter: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Reply: Robert I. Eachus: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: Zork: "Considering taking an ADA course at uni"
- In reply to: Robert I. Eachus: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Next in thread: Jeffrey Carter: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Reply: Jeffrey Carter: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Reply: Robert I. Eachus: "Re: Improving Ada's image - Was: 7E7 Flight Controls Electronics"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|