From: Dmitry A. Kazakov on
On Wed, 28 Apr 2010 16:10:46 +0200, Georg Bauhaus wrote:

> On 28.04.10 15:41, Dmitry A. Kazakov wrote:
>
>> Well, the proposal might be to fix rather the issue of the superfluous
>> subtype specification. Obviously Max (and many other attributes) are
>> primitive operations and need no subtype to specify. So:
>>
>> X'Succ, X'Pred, X'Image
>
> That'll be fun:
>
> C'Succ'Succ
>
> 'C'&'&''Succ
>
> ''''Succ
>
> (M + N)'Succ

This is a slightly different design flaw. Things like "abc"'Length,
"abc"'First are illegal in Ada. No fun!

BTW, if you prefer dotted notation it could be

X.Succ

as well.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Randy Brukardt on
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote in message
news:1t4extnm6iluj.r4x652cntogc$.dlg(a)40tude.net...
> On Wed, 28 Apr 2010 16:10:46 +0200, Georg Bauhaus wrote:
>
>> On 28.04.10 15:41, Dmitry A. Kazakov wrote:
>>
>>> Well, the proposal might be to fix rather the issue of the superfluous
>>> subtype specification. Obviously Max (and many other attributes) are
>>> primitive operations and need no subtype to specify. So:
>>>
>>> X'Succ, X'Pred, X'Image
>>
>> That'll be fun:
>>
>> C'Succ'Succ
>>
>> 'C'&'&''Succ
>>
>> ''''Succ
>>
>> (M + N)'Succ
>
> This is a slightly different design flaw. Things like "abc"'Length,
> "abc"'First are illegal in Ada. No fun!

That's not a real problem. Ada 2012 will allow

String'("abc")'Length

As a qualified expression can be used as a name (it's considered constant).

If you think this is weird, Tucker points out that you can already write:

String(String'("abc"))'Length

in Ada 95, as a type conversion is a name. We did wonder if any compilers
could actually handle it, but given that this long-winded locution is
already legal, the shorter one might was well be legal as well.

As for the initial concern about giving a subtype name, in the case of
literals you have to give one somewhere (since a literal can be of many
different types, and the results can vary depending on the type used -- not
for 'Length, but for 'Last and most other properties).

We did talk a bit about object attributes like suggested back a few messages
for Ada 2012. We didn't get much consensus, mainly because I think people
were looking at the wrong questions.

Randy.


From: Dmitry A. Kazakov on
On Wed, 28 Apr 2010 16:07:24 -0500, Randy Brukardt wrote:

> As for the initial concern about giving a subtype name, in the case of
> literals you have to give one somewhere (since a literal can be of many
> different types, and the results can vary depending on the type used -- not
> for 'Length, but for 'Last and most other properties).

No problem, Ada supports overloading in the result type. E.g. abs (-1) is
OK.

(I have an impression that many weird Ada rules rooted in an attempt to
express them at the grammar level.)

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: AdaMagica on
On 28 Apr., 23:07, "Randy Brukardt" <ra...(a)rrsoftware.com> wrote:
> That's not a real problem. Ada 2012 will allow
>
>     String'("abc")'Length
>
> As a qualified expression can be used as a name (it's considered constant).

This whole discussion begs the question "What is an attribute?". I
think the Ada 83 design idea was that the basic scalar types only have
operators as functions. (See package Standard, there you find only
operators (except for the fact that enumeration literals are also
functions).) Everything else (like 'Image) was defined as an
attribute.

Thus Min, if it had existed in Ada 83 as an operator (it hadn't even
as an attribute), would have had to be a reserved word like abs, not,
rem, mod.

I think Ada 95 kept this design issue and thus had to define it as an
attribute.
From: Randy Brukardt on
"Dmitry A. Kazakov" <mailbox(a)dmitry-kazakov.de> wrote in message
news:1p28brlj9yc3k$.1nv0ey1aadvoi$.dlg(a)40tude.net...
> On Wed, 28 Apr 2010 16:07:24 -0500, Randy Brukardt wrote:
>
>> As for the initial concern about giving a subtype name, in the case of
>> literals you have to give one somewhere (since a literal can be of many
>> different types, and the results can vary depending on the type used --
>> not
>> for 'Length, but for 'Last and most other properties).
>
> No problem, Ada supports overloading in the result type. E.g. abs (-1) is
> OK.

That doesn't help. Consider:

type My_String is array (Natural range <>) of Character;

Now, if you wrote:

"ABC"'First

The answer depends on whether the type of the prefix is String or My_String,
but the type is Integer'Base in both cases. No amount of overloading will
help.

The language does not want the compiler to have to list out all of the
possible types for a string literal, figure out the appropriate bounds for
all of them, take all of the ones with the appropriate index type, and then
allow the attribute if the answer is the same. (Recall that *every* Ada
program has at least three string types available.)

Similar rules are used for aggregates, the operand of a type conversion, and
other places. No context can be used as figuring out an answer if it could
is just too difficult. (There are a couple of exceptions for attribute
prefixes, particularly 'Access, as we found that the typical rule is too
limiting, but those are tightly bounded.)

Randy.