From: Warren on
Niklas Holsti expounded in news:88ec2vF3uqU1(a)mid.individual.net:
> Dmitry A. Kazakov wrote:
>> On Wed, 23 Jun 2010 00:30:23 -0700 (PDT), Maciej Sobczak wrote:
...
>>> 2. Is it possible to declare the index variable without hardcoding
>>> the index type (that is, to infer it from the array object)?
>>
>> No, without improving the type system. E.g. introducing abstract
>> index types, and abstract range types (or more general sets of index
>> types), and abstract composite types like arrays.
>
> I don't think such large language changes would be necessary. The
> expression S'Range gives the compiler all the information about the
> type and its constraints, so I see no reason why Ada could not be
> extended simply to allow S'Range in a variable declaration, as in the
> above quoted "I : S'Range". The declared variable "I" would have the
> same (sub)type as the loop counter in "for I in S'Range loop ...".

I think most would agree that this is a "convenience" feature.
I think the language (and its compiler) is probably complicated
enough for these types of additions. Don't forget each new feature
requires a "test suite" and validation, in addition to the
compiler itself.

Warren
From: Robert A Duff on
"J-P. Rosen" <rosen(a)adalog.fr> writes:

> Not yet, although it would be a very simple addition. The hardest part
> would be to find an acceptable name for the rule. The current one is:
>
> check declarations (anonymous_subtype_for);
>
> and I wouldn't like:
> check declarations (anonymous_subtype_except_range_for);
> ;-)

I'd suggest something like "default_integer_range". It's not just
for 'for' loops -- the same language malfeature occurs for array
type decls, for example.

- Bob
From: Dmitry A. Kazakov on
On Wed, 23 Jun 2010 16:33:43 +0000 (UTC), Warren wrote:

> Niklas Holsti expounded in news:88ec2vF3uqU1(a)mid.individual.net:
>> Dmitry A. Kazakov wrote:
>>> On Wed, 23 Jun 2010 00:30:23 -0700 (PDT), Maciej Sobczak wrote:
> ..
>>>> 2. Is it possible to declare the index variable without hardcoding
>>>> the index type (that is, to infer it from the array object)?
>>>
>>> No, without improving the type system. E.g. introducing abstract
>>> index types, and abstract range types (or more general sets of index
>>> types), and abstract composite types like arrays.
>>
>> I don't think such large language changes would be necessary. The
>> expression S'Range gives the compiler all the information about the
>> type and its constraints, so I see no reason why Ada could not be
>> extended simply to allow S'Range in a variable declaration, as in the
>> above quoted "I : S'Range". The declared variable "I" would have the
>> same (sub)type as the loop counter in "for I in S'Range loop ...".
>
> I think most would agree that this is a "convenience" feature.
> I think the language (and its compiler) is probably complicated
> enough for these types of additions.

On the contrary, it is complicated because ranges and indices are irregular
types. Hard coded special cases make language more complex for both
programmer and compiler developer.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: Warren on
Dmitry A. Kazakov expounded in
news:xhhsthd26ppk$.1iukhhnnqoq42$.dlg(a)40tude.net:

> On Wed, 23 Jun 2010 16:33:43 +0000 (UTC), Warren wrote:
>
>> Niklas Holsti expounded in news:88ec2vF3uqU1(a)mid.individual.net:
>>> Dmitry A. Kazakov wrote:
>>>> On Wed, 23 Jun 2010 00:30:23 -0700 (PDT), Maciej Sobczak wrote:
>> ..
>>>>> 2. Is it possible to declare the index variable without hardcoding
>>>>> the index type (that is, to infer it from the array object)?
>>>>
>>>> No, without improving the type system. E.g. introducing abstract
>>>> index types, and abstract range types (or more general sets of
>>>> index types), and abstract composite types like arrays.
>>>
>>> I don't think such large language changes would be necessary. The
>>> expression S'Range gives the compiler all the information about the
>>> type and its constraints, so I see no reason why Ada could not be
>>> extended simply to allow S'Range in a variable declaration, as in
>>> the above quoted "I : S'Range". The declared variable "I" would have
>>> the same (sub)type as the loop counter in "for I in S'Range loop
>>> ...".
>>
>> I think most would agree that this is a "convenience" feature.
>> I think the language (and its compiler) is probably complicated
>> enough for these types of additions.
>
> On the contrary, it is complicated because ranges and indices are
> irregular types. Hard coded special cases make language more complex
> for both programmer and compiler developer.

"On the contrary" to what? I already said things were
"probably complicated enough".

Warren
From: Simon Wright on
"J-P. Rosen" <rosen(a)adalog.fr> writes:

> outside the instantiation, you are supposed to know how it was
> instantiated, therefore you have access to the actuals. Why would you
> need to reexport the formals?

Formal types, yes, not so sure about formal objects. Consider eg a
generic signature package ..

generic

type Severity_Code is (<>);
-- Messages are logged with this indication of severity.

Error : Severity_Code;
-- This value is used for error messages.

Informational : Severity_Code;
-- This value is used for informational messages.

with procedure Log (Severity : Severity_Code; Message : String);

package Logging_Signature is

-- Make the actual instantiation parameters visible.
package Exported is
Error : Severity_Code renames Logging_Signature.Error;
Informational : Severity_Code renames Logging_Signature.Informational;
procedure Log (Severity : Severity_Code; Message : String)
renames Logging_Signature.Log;
end Exported;