comp.lang.ada
 help / color / mirror / Atom feed
* Imagine Ada with Fewer Attributes
@ 2010-05-15 20:29 Frank J. Lhota
  2010-05-15 20:46 ` Yannick Duchêne (Hibou57)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Frank J. Lhota @ 2010-05-15 20:29 UTC (permalink / raw)


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?

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 
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;

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? Is there a way to 
move Ada in the direction of more functions and fewer attributes?

-- 
"All things extant in this world,
Gods of Heaven, gods of Earth,
Let everything be as it should be;
Thus shall it be!"
- Magical chant from "Magical Shopping Arcade Abenobashi"

"Drizzle, Drazzle, Drozzle, Drome,
Time for this one to come home!"
- Mr. Wizard from "Tooter Turtle"



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

* Re: Imagine Ada with Fewer Attributes
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2010-05-15 20:46 UTC (permalink / raw)


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)



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

* Re: Imagine Ada with Fewer Attributes
  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
  2010-05-17 13:27 ` Colin Paul Gloster
  3 siblings, 0 replies; 5+ messages in thread
From: Dmitry A. Kazakov @ 2010-05-16  7:11 UTC (permalink / raw)


On Sat, 15 May 2010 16:29:37 -0400, Frank J. Lhota wrote:

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

Primitive operations, you mean. That would require al types to have
classes. This is what I wanted to have since Ada 95. If there were done Ada
would become a much nicer language.

BTW, the notation of attributes can be preserved, e.g. you could be allowed
to declare operations with the syntax X'Y.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



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

* Re: Imagine Ada with Fewer Attributes
  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
  2010-05-17 13:27 ` Colin Paul Gloster
  3 siblings, 0 replies; 5+ messages in thread
From: Robert A Duff @ 2010-05-16 15:31 UTC (permalink / raw)


"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



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

* Re: Imagine Ada with Fewer Attributes
  2010-05-15 20:29 Imagine Ada with Fewer Attributes Frank J. Lhota
                   ` (2 preceding siblings ...)
  2010-05-16 15:31 ` Robert A Duff
@ 2010-05-17 13:27 ` Colin Paul Gloster
  3 siblings, 0 replies; 5+ messages in thread
From: Colin Paul Gloster @ 2010-05-17 13:27 UTC (permalink / raw)


On Sat, 15 May 2010, Frank J. Lhota sent:

|----------------------------------------------------------------------------|
|"[..]                                                                       |
|[..] 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?                 |
|                                                                            |
|[..]"                                                                       |
|----------------------------------------------------------------------------|

Functions are not needed for this. VHDL (a family of dialects of Ada
83) has user-defined attributes.



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

end of thread, other threads:[~2010-05-17 13:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2010-05-17 13:27 ` Colin Paul Gloster

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