comp.lang.ada
 help / color / mirror / Atom feed
* How to write TYPECASE in Ada 95?
@ 1999-02-05  0:00 Norman Ramsey
  1999-02-05  0:00 ` Brian Rogoff
                   ` (2 more replies)
  0 siblings, 3 replies; 34+ messages in thread
From: Norman Ramsey @ 1999-02-05  0:00 UTC (permalink / raw)



I'm trying to figure out from the reference manual how to identify
which type extension of a type I have.  For example, if I have

   type Point is tagged
         record
           X, Y : Real := 0.0;
         end record;

   type Painted_Point is new Point with
         record
           Paint : Color := White;
         end record;


   type Tall_Point is new Point with
         record
           Height : Real := 0.0;
         end record;

I'd like to be able to discriminate at run time:

   p : Point;

     ...

   if p in Painted_Point then
      ... do something with Painted_Point'(p)
   else if p in Tall_Point then
      ... do something with Tall_Point'(p)

Even better would be something like Modula-3 TYPECASE:

  (* modula-3 *)
  TYPECASE p OF
  Painted_Point (painted) => ... do something with painted
  Tall_Point    (tail)    => ... do something with tall
    ...
  END

What's the idiomatic way to express this in Ada?


Norman

-- 
Norman Ramsey
http://www.cs.virginia.edu/~nr




^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~1999-02-26  0:00 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-05  0:00 How to write TYPECASE in Ada 95? Norman Ramsey
1999-02-05  0:00 ` Brian Rogoff
1999-02-05  0:00   ` David C. Hoos, Sr.
1999-02-05  0:00     ` Brian Rogoff
1999-02-06  0:00   ` Ed Falis
1999-02-06  0:00     ` Nick Roberts
1999-02-06  0:00       ` Nick Roberts
1999-02-17  0:00     ` Tom Moran
1999-02-18  0:00       ` Matthew Heaney
1999-02-18  0:00         ` Tom Moran
1999-02-18  0:00         ` robert_dewar
1999-02-19  0:00           ` Nick Roberts
1999-02-19  0:00           ` Tom Moran
1999-02-18  0:00         ` Tom Moran
1999-02-18  0:00           ` Matthew Heaney
1999-02-19  0:00     ` Tom Moran
1999-02-19  0:00       ` Tom Moran
1999-02-23  0:00       ` Samuel Mize
1999-02-23  0:00         ` Question (was Re: How to write TYPECASE in Ada 95?) Mike Silva
1999-02-24  0:00           ` Samuel T. Harris
1999-02-24  0:00             ` Matthew Heaney
1999-02-24  0:00               ` Tucker Taft
1999-02-24  0:00           ` Nick Roberts
1999-02-24  0:00           ` (long) programming by extension (was: " Samuel Mize
1999-02-24  0:00             ` (long) programming by extension Samuel Mize
1999-02-25  0:00               ` (shorter and new) " Samuel Mize
1999-02-25  0:00                 ` Mike Silva
1999-02-26  0:00                   ` Samuel Mize
1999-02-06  0:00 ` How to write TYPECASE in Ada 95? David C. Hoos, Sr.
1999-02-06  0:00   ` Matthew Heaney
1999-02-06  0:00     ` Matthew Heaney
1999-02-06  0:00     ` Matthew Heaney
1999-02-09  0:00     ` David C. Hoos, Sr.
1999-02-06  0:00 ` Matthew Heaney

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