From: "Yannick Duchêne (Hibou57)" <yannick_duchene@yahoo.fr>
Subject: Re: Imagine Ada with Fewer Attributes
Date: Sat, 15 May 2010 22:46:10 +0200
Date: 2010-05-15T22:46:10+02:00 [thread overview]
Message-ID: <op.vcrla8yrule2fv@garhos> (raw)
In-Reply-To: hsn07m$acs$1@news.albasani.net
Le Sat, 15 May 2010 22:29:37 +0200, Frank J. Lhota
<FrankLho.NOSPAM@rcn.com> a écrit:
> The recent discussion of the 'Image attribute got me thinking of the
> issue of the whether Ada uses attributes too frequently. I feel that the
> language would be simpler and easier to use if most of the Ada
> attributes were replaced with operations. For example, rather than
> having an 'Image, 'Value, 'Succ, etc. attribute for the scalar types,
> why not simply have Image, Value, Succ, etc. functions for the scalar
> types, that the user can override?
The way is was with Pascal (at least, Borland Pascal).
> For example, Warren desired to create an integer type with a
> user-defined 'Image attribute. I frequently want to do that for
> enumeration types, where the Ada default (all capitals with underscores)
> is almost never what is wanted. As noted in the other thread, we cannot
> change this in Ada 2005.
And Ada does not nor prevent you from created such an Image function.
> But what if Image were a function instead of an attribute?
Interesting question :)
> Imagine an Ada variant where an enumeration type is treated as though it
> was derived from a base class that defines the functions Image, Value,
> Pred, Succ etc. Then we could
> write something like this:
>
> type Work_Type is (Tote_That_Barge, Lift_That_Bail);
>
> overriding
> function Image (Item : in Work_Type) return String is
> -- Base image with underscores replaced with spaces.
> Spaced : constant String := Ada.Strings.Fixed.Translate(
> Image (Work_Type'Base (Item)),
> Underscore_To_Space
> );
> begin
> return Internationalize (Spaced);
> end Image;
This supposes to have tagged enumeration types and thus to have the “all
data types can be seen as classes”. That's the Eiffel way, which allows
you to derive a new class from Integer and to have dispatching on
Integer's operation (if my mind is right).
> Granted, representation characteristics such as 'Address, 'Size, and
> 'Position can only be represented by some special construct such as an
> attribute.
Agree with you
> Also, many attributes are applied to types and subtypes; to turn these
> attributes into functions would require that types and subtypes be
> objects, as they are languages such as Smalltalk.
Indeed
> So out of curiosity, which Ada attributes do you think should be turned
> into functions, and which should stay as attributes?
Well, I don't know, as one can always create a function for Pred, Succ,
Image and so on as he/she want.
Very difficult question...
> Is there a way to move Ada in the direction of more functions and fewer
> attributes?
With all basic types as tagged types ? Is that a joke ?
If this is without basic types as tagged types, you will not have
overriding available, and what would you like with functions which you
could not override ?
--
There is even better than a pragma Assert: an --# assert (or a --#
check... question pending)
next prev parent reply other threads:[~2010-05-15 20:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-15 20:29 Imagine Ada with Fewer Attributes Frank J. Lhota
2010-05-15 20:46 ` Yannick Duchêne (Hibou57) [this message]
2010-05-16 7:11 ` Dmitry A. Kazakov
2010-05-16 15:31 ` Robert A Duff
2010-05-17 13:27 ` Colin Paul Gloster
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox