comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert I. Eachus" <rieachus@comcast.net>
Subject: Re: Why I like Ada
Date: Mon, 31 May 2004 23:57:45 -0400
Date: 2004-05-31T23:57:45-04:00	[thread overview]
Message-ID: <X7qdnb2vs_InYybdRVn-ig@comcast.com> (raw)
In-Reply-To: <2hj035Fde12lU1@uni-berlin.de>

Peter Amey wrote:

>> ...and the difficulty of the instantiation for Unchecked_Conversion 
>> might give you a clue.  (The formal result type of 
>> Unchecked_Conversion is Target.  So if you want to convert to a 
>> (local) type Target, you have to use selected notation... ;-)
>>
> 
> What, as in: "My.Foot"?   Yes, that would concentrate the mind a bit.

No, you could "get away" with

function To_Target is new Ada.Unchecked_Conversion
                 (Source => Body_Part_Type, Target => Gun.Target)

I was commenting that you need to use selected notation for the type 
Target.  Some Ada terminology is titillating, but in this case it is 
just scary.  Hmmm.  In fact...

with Ada.Unchecked_Conversion;
procedure Shoot_Foot is

   type Target is new Character; -- just so this test will compile.
   type Weapon is (M15A3, AK47, M1911A1);

   type Condition is (Healthy, Damaged, Missing);

   type Body_Part is record
     State: Condition := Healthy;
     -- ...
   end record;

   type Person_Body is record
         Head, Neck, Left_Shoulder, Right_Shoulder, Chest, Torso,
         Left_Arm, Right_Arm, Left_Hand, Right_Hand, Left_Leg,
         Right_Leg, Left_Knee, Right_Knee, Left_Foot, Right_Foot:
       Body_Part;
   end record;

   procedure Shoot(What: in Target; Gun: in Weapon)
               is begin null; end; --TBD.

   function To_Target is new Ada.Unchecked_Conversion
         (Source => Body_Part, Target => Target);

   Me: Person_Body;

begin

  Shoot(To_Target(Me.Left_Foot), AK47);

end Shoot_Foot;

I'll be darned! GNAT took that Target => Target. I was expecting it to 
require the second Target to use selected notation.  Its midnight, so 
I'll wait 'til tomorrow to figure out if that is really a bug.

Of course, in reality, Target would be an in out parameter to Shoot, or 
an access value denoting the actual Target.  (Same for gun, that's why 
Shoot is TBD. ;-)

-- 

                                           Robert I. Eachus

"The terrorists rejoice in the killing of the innocent, and have 
promised similar violence against Americans, against all free peoples, 
and against any Muslims who reject their ideology of murder. Their 
barbarism cannot be appeased, and their hatred cannot be satisfied. 
There's only one way to deal with terror: We must confront the enemy and 
stay on the offensive until these killers are defeated." -- George W. Bush




  parent reply	other threads:[~2004-06-01  3:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-22  0:39 Why I like Ada Fionn mac Cuimhaill
2004-05-22 14:11 ` Per Dalgas Jakobsen
2004-05-22 15:23   ` Preben Randhol
2004-05-22 16:27     ` Björn Persson
2004-05-25 21:29       ` Robert I. Eachus
2004-05-26  7:44         ` Peter Amey
2004-05-26  8:18           ` Ludovic Brenta
2004-05-26 16:15             ` Martin Krischik
2004-05-26 19:33               ` David Starner
2004-05-30 18:06                 ` Richard  Riehle
2004-05-30 18:17                   ` Randy Brukardt
2004-05-30 19:09                     ` Adrian Knoth
2004-05-31 13:27                     ` Björn Persson
     [not found]                   ` <inpkb0d57uiaf6970hk0ctj09orni4piea@4ax.com>
2004-05-31  2:07                     ` Richard  Riehle
2004-05-26 15:30           ` Wes Groleau
2004-06-01  3:57           ` Robert I. Eachus [this message]
2004-06-02  1:48             ` Jeffrey Carter
2004-06-02  5:13               ` Robert I. Eachus
2004-05-22 22:01   ` Wes Groleau
  -- strict thread matches above, loose matches on Subject: below --
1994-12-02  9:44 Richard A. O'Keefe
replies disabled

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