comp.lang.ada
 help / color / mirror / Atom feed
From: Matt Borchers <mattborchers@gmail.com>
Subject: Overloading attributes
Date: Sat, 26 Nov 2011 15:13:17 -0800 (PST)
Date: 2011-11-26T15:13:17-08:00	[thread overview]
Message-ID: <8ed87fee-166a-4be9-ae6c-4d0fbeb4788c@s6g2000vbc.googlegroups.com> (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?



             reply	other threads:[~2011-11-26 23:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-26 23:13 Matt Borchers [this message]
2011-11-26 23:24 ` Overloading attributes 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
replies disabled

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