comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Imagine Ada with Fewer Attributes
Date: Sun, 16 May 2010 11:31:06 -0400
Date: 2010-05-16T11:31:06-04:00	[thread overview]
Message-ID: <wccaarzsw1x.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: hsn07m$acs$1@news.albasani.net

"Frank J. Lhota" <FrankLho.NOSPAM@rcn.com> writes:

> The recent discussion of the 'Image attribute got me thinking of the
> issue of the whether Ada uses attributes too frequently.

Probably so.

>...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?

It would indeed be nicer to say Image(X) instead of Some_Type'Image(X).
We don't mention the type name when we do "+", so why should we
have to mention the type name for Image?

But I don't see any point in overriding 'Image.  You can already
declare an Image function, and it can call "To_Lower(Blah'Image(X))"
if you like.

If record types had 'Image, which automatically called 'Image on the
components (similar to the way 'Write works), then it would be useful to
override 'Image on the component types.  But since there are no
automatic calls to 'Image, I don't think it would buy you anything.

By the way, we already have a way of overriding attributes:

    for T'Write use ....;

That's not allowed for 'Image.

> 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. But what if Image were a function instead of an
> attribute? Imagine an Ada variant where an enumeration type is treated
> as though it was derived from a base class that defines the functions
                                  ^^^^^^^^^^

There's no such thing as a "base class" in Ada.  The "base subtype"
of a subtype is that subtype with its constraint removed.

I'm not sure what you mean.  A single _root_enumeration_ type,
similar to _root_integer_?  Or a new root type for every
enumeration type, with the same enumeration literals?

> 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)),

Work_Type'Base is the same as Work_Type, because it has no constraint.
So this is a recursive call to Image.  Infinitely recursive.

>             Underscore_To_Space
>             );
>     begin
>         return Internationalize (Spaced);
>     end Image;
>
> Granted, representation characteristics such as 'Address, 'Size, and
> 'Position can only be represented by some special construct such as an
> attribute. 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.
>
> So out of curiosity, which Ada attributes do you think should be turned
> into functions, and which should stay as attributes?

If I were designing the language from scratch, I'd probably say
"all of them should be functions".

But I don't think Ada is broken in this regard -- at least
not sufficiently broken to warrant such a big change.
It would probably require massive changes to compilers,
in order to keep overload resolution reasonably efficient.

>...Is there a way to
> move Ada in the direction of more functions and fewer attributes?

Dubitably.  ;-)

- Bob



  parent reply	other threads:[~2010-05-16 15:31 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)
2010-05-16  7:11 ` Dmitry A. Kazakov
2010-05-16 15:31 ` Robert A Duff [this message]
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