comp.lang.ada
 help / color / mirror / Atom feed
* Overloading attributes
@ 2011-11-26 23:13 Matt Borchers
  2011-11-26 23:24 ` Shark8
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: Matt Borchers @ 2011-11-26 23:13 UTC (permalink / raw)


Why is it that one cannot overload the 'Image and 'Value attribute
similar to how we can overload 'Input, 'Output, 'Read, and 'Write?  I
think it would be nice to be able to do the following:

type FOO is ...;

function Image( f : FOO ) return String;
for FOO'Image use Image;

function To_Foo( s : String ) return FOO;
for FOO'Value use To_Foo;

Is there a reason that this is not allowed?  Why limit 'Image and
'Value to only scalar types.
Why expose a routine to "stringify" an object through the package
specification when a language construct already exists that could do
this?

I can also imagine how overloading 'Pred and 'Succ would be kinda nice
for link list traversals (and possibly other linked structures):

type A_FOO is access FOO;  --FOO has a field that points to next
record via pointer

function Succ( f : A_FOO ) return A_FOO;
for A_FOO'Succ use Succ;
--similar for 'Pred if it is a doubly linked list

x : A_FOO;
x := x'Succ;

Why expose a Next routine through the package specification when a
language construct already exists that can do this?

How about other Attributes like 'Pos, 'Val, 'First, 'Last, etc?  Could
they be overloaded on user-defined types?



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

end of thread, other threads:[~2011-12-03  1:41 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-26 23:13 Overloading attributes Matt Borchers
2011-11-26 23:24 ` Shark8
2011-11-27  7:38   ` Yannick Duchêne (Hibou57)
2011-11-27  3:36 ` anon
2011-11-27  7:04   ` J-P. Rosen
2011-11-27 20:00     ` anon
2011-11-27 20:34       ` Yannick Duchêne (Hibou57)
2011-11-27 20:50         ` Yannick Duchêne (Hibou57)
2011-11-27 23:10       ` J-P. Rosen
2011-11-28  9:11         ` anon
2011-11-28 10:53           ` Peter C. Chapin
2011-11-29 11:58             ` anon
2011-11-29 12:50               ` Mark Lorenzen
2011-11-30 11:05                 ` anon
2011-11-29 16:16               ` AdaMagica
2011-11-29 17:43                 ` Jeffrey Carter
2011-11-29 23:26                 ` J-P. Rosen
2011-11-30 11:06                   ` anon
2011-11-30 15:52                     ` J-P. Rosen
2011-11-30 17:27                       ` Yannick Duchêne (Hibou57)
2011-11-30 20:45                       ` Pascal Obry
2011-12-01 11:01                       ` Simon Wright
2011-12-02 18:55                       ` anon
2011-12-02 19:34                         ` Ludovic Brenta
2011-12-02 20:02                           ` Yannick Duchêne (Hibou57)
2011-12-03  1:41                           ` Randy Brukardt
2011-11-28 12:06           ` Ludovic Brenta
2011-11-27  5:11 ` Yannick Duchêne (Hibou57)
2011-11-27 12:57 ` Dmitry A. Kazakov

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