* Subtype predicates
@ 2016-08-23 20:14 Anh Vo
2016-08-24 13:06 ` AdaMagica
0 siblings, 1 reply; 13+ messages in thread
From: Anh Vo @ 2016-08-23 20:14 UTC (permalink / raw)
The following type definition is rejected by GNAT-GPL-2016 with error message 'prefix of "First" attribute cannot be the current instance of a scalar type'.
type Human_Life_Span_Type is range 0 .. 130
with Default_Value => Human_Life_Span_Type'First;
Is it a legit syntax error based on 3.2.4 26/3 of LRM?
Anh Vo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-23 20:14 Subtype predicates Anh Vo
@ 2016-08-24 13:06 ` AdaMagica
2016-08-24 16:45 ` Shark8
2016-08-24 21:54 ` Jeffrey R. Carter
0 siblings, 2 replies; 13+ messages in thread
From: AdaMagica @ 2016-08-24 13:06 UTC (permalink / raw)
Am Dienstag, 23. August 2016 22:14:30 UTC+2 schrieb Anh Vo:
> type Human_Life_Span_Type is range 0 .. 130
> with Default_Value => Human_Life_Span_Type'First;
No, I think it's the rule that the name of the entity declared in a declaration (here Human_Life_Span_Type) may not be used again in the same declaration. (You cannot use something that is to be defined recursively in the definition.)
I just cannot find the RM chapter and verse.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-24 13:06 ` AdaMagica
@ 2016-08-24 16:45 ` Shark8
2016-08-24 21:18 ` Anh Vo
2016-08-24 21:54 ` Jeffrey R. Carter
1 sibling, 1 reply; 13+ messages in thread
From: Shark8 @ 2016-08-24 16:45 UTC (permalink / raw)
On Wednesday, August 24, 2016 at 7:06:10 AM UTC-6, AdaMagica wrote:
> Am Dienstag, 23. August 2016 22:14:30 UTC+2 schrieb Anh Vo:
> > type Human_Life_Span_Type is range 0 .. 130
> > with Default_Value => Human_Life_Span_Type'First;
>
> No, I think it's the rule that the name of the entity declared in a declaration (here Human_Life_Span_Type) may not be used again in the same declaration. (You cannot use something that is to be defined recursively in the definition.)
>
> I just cannot find the RM chapter and verse.
I think it's different for aspects -- similar that Rosen's Trick the name of the declaration is referent to the instance of the type. So we could say something like:
-- A string of upper-case letters followed by a single digit.
Subtype ID_String is new String
with Dynamic_Predicate =>
(For all Index in ID_String'Range =>
(if Index /= ID_String'Last
then ID_String(Index) in 'A'..'Z'
else ID_String(Index) in '0'..'9'
)
);
And since [some] aspects are essentially attribute-specification clauses (eg "Size => 8" = "For T'Size use 8;") there is some sense in thinking it is/should-be legit.
OTOH, you could certainly consider something like ID_String's predicate as being part of the definition.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-24 16:45 ` Shark8
@ 2016-08-24 21:18 ` Anh Vo
2016-08-24 21:32 ` Shark8
0 siblings, 1 reply; 13+ messages in thread
From: Anh Vo @ 2016-08-24 21:18 UTC (permalink / raw)
On Wednesday, August 24, 2016 at 9:45:52 AM UTC-7, Shark8 wrote:
> On Wednesday, August 24, 2016 at 7:06:10 AM UTC-6, AdaMagica wrote:
> > Am Dienstag, 23. August 2016 22:14:30 UTC+2 schrieb Anh Vo:
> > > type Human_Life_Span_Type is range 0 .. 130
> > > with Default_Value => Human_Life_Span_Type'First;
> >
> > No, I think it's the rule that the name of the entity declared in a declaration (here Human_Life_Span_Type) may not be used again in the same declaration. (You cannot use something that is to be defined recursively in the definition.)
> >
> > I just cannot find the RM chapter and verse.
>
> I think it's different for aspects -- similar that Rosen's Trick the name of the declaration is referent to the instance of the type. So we could say something like:
>
> -- A string of upper-case letters followed by a single digit.
> Subtype ID_String is new String
> with Dynamic_Predicate =>
> (For all Index in ID_String'Range =>
> (if Index /= ID_String'Last
> then ID_String(Index) in 'A'..'Z'
> else ID_String(Index) in '0'..'9'
> )
> );
>
>
> And since [some] aspects are essentially attribute-specification clauses (eg "Size => 8" = "For T'Size use 8;") there is some sense in thinking it is/should-be legit.
The 3.5 56.3/3 says that the Default_Value shall be static. Thus, S'First did not comply with Static Semantics. The compiler error should have complained about aspect "Default_Value" requires static expression instead of prefix of "First"... This caused the confusion in the first place.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-24 21:18 ` Anh Vo
@ 2016-08-24 21:32 ` Shark8
0 siblings, 0 replies; 13+ messages in thread
From: Shark8 @ 2016-08-24 21:32 UTC (permalink / raw)
On Wednesday, August 24, 2016 at 3:18:47 PM UTC-6, Anh Vo wrote:
> On Wednesday, August 24, 2016 at 9:45:52 AM UTC-7, Shark8 wrote:
> > On Wednesday, August 24, 2016 at 7:06:10 AM UTC-6, AdaMagica wrote:
> > > Am Dienstag, 23. August 2016 22:14:30 UTC+2 schrieb Anh Vo:
> > > > type Human_Life_Span_Type is range 0 .. 130
> > > > with Default_Value => Human_Life_Span_Type'First;
> > >
> > > No, I think it's the rule that the name of the entity declared in a declaration (here Human_Life_Span_Type) may not be used again in the same declaration. (You cannot use something that is to be defined recursively in the definition.)
> > >
> > > I just cannot find the RM chapter and verse.
> >
> > I think it's different for aspects -- similar that Rosen's Trick the name of the declaration is referent to the instance of the type. So we could say something like:
> >
> > -- A string of upper-case letters followed by a single digit.
> > Subtype ID_String is new String
> > with Dynamic_Predicate =>
> > (For all Index in ID_String'Range =>
> > (if Index /= ID_String'Last
> > then ID_String(Index) in 'A'..'Z'
> > else ID_String(Index) in '0'..'9'
> > )
> > );
> >
> >
> > And since [some] aspects are essentially attribute-specification clauses (eg "Size => 8" = "For T'Size use 8;") there is some sense in thinking it is/should-be legit.
>
> The 3.5 56.3/3 says that the Default_Value shall be static. Thus, S'First did not comply with Static Semantics. The compiler error should have complained about aspect "Default_Value" requires static expression instead of prefix of "First"... This caused the confusion in the first place.
Why wouldn't 'First (on the discrete-type) be considered Static? It's known at compile-time when the compiler chooses the representation.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-24 13:06 ` AdaMagica
2016-08-24 16:45 ` Shark8
@ 2016-08-24 21:54 ` Jeffrey R. Carter
2016-08-25 0:08 ` Shark8
1 sibling, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2016-08-24 21:54 UTC (permalink / raw)
On 08/24/2016 06:06 AM, AdaMagica wrote:
> Am Dienstag, 23. August 2016 22:14:30 UTC+2 schrieb Anh Vo:
>> type Human_Life_Span_Type is range 0 .. 130
>> with Default_Value => Human_Life_Span_Type'First;
>
> No, I think it's the rule that the name of the entity declared in a declaration (here Human_Life_Span_Type) may not be used again in the same declaration. (You cannot use something that is to be defined recursively in the definition.)
>
> I just cannot find the RM chapter and verse.
No, it's because of ARM 13.1.1(12/3): "If the associated declaration is a
type_declaration, within the aspect_definition ... the name of the first subtype
denotes the current instance of the type (see 8.6)." For a declaration:
V : Human_Life_Span_Type;
the current instance is V, so this says V's default value is V'First. Since you
can't apply 'First to a scalar object, the aspect is in error.
--
Jeff Carter
"He had no conception of the instrument. He
was blowing into it."
Take the Money and Run
135
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-24 21:54 ` Jeffrey R. Carter
@ 2016-08-25 0:08 ` Shark8
2016-08-25 0:31 ` Jeffrey R. Carter
2016-08-31 18:16 ` Randy Brukardt
0 siblings, 2 replies; 13+ messages in thread
From: Shark8 @ 2016-08-25 0:08 UTC (permalink / raw)
> No, it's because of ARM 13.1.1(12/3): "If the associated declaration is a
> type_declaration, within the aspect_definition ... the name of the first subtype
> denotes the current instance of the type (see 8.6)." For a declaration:
>
> V : Human_Life_Span_Type;
>
> the current instance is V, so this says V's default value is V'First. Since you
> can't apply 'First to a scalar object, the aspect is in error.
Hm, another argument for a 'Type attribute, then we could say
type Human_Life_Span is range 0 .. 130
with Default_Value => Human_Life_Span'Type'First;
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-25 0:08 ` Shark8
@ 2016-08-25 0:31 ` Jeffrey R. Carter
2016-08-25 17:28 ` Anh Vo
2016-08-31 18:16 ` Randy Brukardt
1 sibling, 1 reply; 13+ messages in thread
From: Jeffrey R. Carter @ 2016-08-25 0:31 UTC (permalink / raw)
On 08/24/2016 05:08 PM, Shark8 wrote:
>
> Hm, another argument for a 'Type attribute, then we could say
>
> type Human_Life_Span is range 0 .. 130
> with Default_Value => Human_Life_Span'Type'First;
Perhaps. The ARG seem leary of adding features where there's a work around, and
you can always say
type Human_Life_Span is range 0 .. 130 with
Default_Value => 0;
If you're worried about Human_Life_Span'First and its default value diverging,
you can instead say
Human_Life_Span_First : constant := 0;
type Human_Life_Span is range Human_Life_Span_First .. 130 with
Default_Value => Human_Life_Span_First;
--
Jeff Carter
"He had no conception of the instrument. He
was blowing into it."
Take the Money and Run
135
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-25 0:31 ` Jeffrey R. Carter
@ 2016-08-25 17:28 ` Anh Vo
0 siblings, 0 replies; 13+ messages in thread
From: Anh Vo @ 2016-08-25 17:28 UTC (permalink / raw)
On Wednesday, August 24, 2016 at 5:31:28 PM UTC-7, Jeffrey R. Carter wrote:
> On 08/24/2016 05:08 PM, Shark8 wrote:
> >
> > Hm, another argument for a 'Type attribute, then we could say
> >
> > type Human_Life_Span is range 0 .. 130
> > with Default_Value => Human_Life_Span'Type'First;
>
> Perhaps. The ARG seem leary of adding features where there's a work around, and
Yes, there are a number of ways to work around. Here is my preferred way
Min_Age : constant := 0;
Max_Age : constant := 130;
type Human_Life Span_Type is new Integer range Min_Age .. Max_Age
with Default_Value => Min_Age;
Anh Vo
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-25 0:08 ` Shark8
2016-08-25 0:31 ` Jeffrey R. Carter
@ 2016-08-31 18:16 ` Randy Brukardt
2016-09-01 8:09 ` J-P. Rosen
2016-09-01 20:16 ` Shark8
1 sibling, 2 replies; 13+ messages in thread
From: Randy Brukardt @ 2016-08-31 18:16 UTC (permalink / raw)
"Shark8" <onewingedshark@gmail.com> wrote in message
news:8955f6b0-18c6-41b9-91bf-b756189f53db@googlegroups.com...
...
> Hm, another argument for a 'Type attribute, then we could say
>
> type Human_Life_Span is range 0 .. 130
> with Default_Value => Human_Life_Span'Type'First;
We examined that extensively, since someone (you, perhaps??) already
suggested it. It's a can of worms, in fact a case of worms. See AI12-0123-1
for some problems.
The odds of Ada adding this attribute are roughly the same as me marrying a
supermodel.
Randy.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-31 18:16 ` Randy Brukardt
@ 2016-09-01 8:09 ` J-P. Rosen
2016-09-01 20:02 ` Randy Brukardt
2016-09-01 20:16 ` Shark8
1 sibling, 1 reply; 13+ messages in thread
From: J-P. Rosen @ 2016-09-01 8:09 UTC (permalink / raw)
Le 31/08/2016 à 20:16, Randy Brukardt a écrit :
> The odds of Ada adding this attribute are roughly the same as me marrying a
> supermodel.
>
Well, you often say that you married Ada... Isn't she a supermodel?
--
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-09-01 8:09 ` J-P. Rosen
@ 2016-09-01 20:02 ` Randy Brukardt
0 siblings, 0 replies; 13+ messages in thread
From: Randy Brukardt @ 2016-09-01 20:02 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 512 bytes --]
"J-P. Rosen" <rosen@adalog.fr> wrote in message
news:nq8no1$fen$1@dont-email.me...
> Le 31/08/2016 à 20:16, Randy Brukardt a écrit :
>> The odds of Ada adding this attribute are roughly the same as me marrying
>> a
>> supermodel.
>
> Well, you often say that you married Ada... Isn't she a supermodel?
<Grin>
She's not good at the physical aspects of marriage, though. (Come to think
of it, the average supermodel probably isn't, either [away most of the
time].)
Randy.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Subtype predicates
2016-08-31 18:16 ` Randy Brukardt
2016-09-01 8:09 ` J-P. Rosen
@ 2016-09-01 20:16 ` Shark8
1 sibling, 0 replies; 13+ messages in thread
From: Shark8 @ 2016-09-01 20:16 UTC (permalink / raw)
On Wednesday, August 31, 2016 at 12:16:54 PM UTC-6, Randy Brukardt wrote:
> "Shark8" wrote in message
> ...
> > Hm, another argument for a 'Type attribute, then we could say
> >
> > type Human_Life_Span is range 0 .. 130
> > with Default_Value => Human_Life_Span'Type'First;
>
> We examined that extensively, since someone (you, perhaps??) already
> suggested it. It's a can of worms, in fact a case of worms. See AI12-0123-1
> for some problems.
>
> The odds of Ada adding this attribute are roughly the same as me marrying a
> supermodel.
>
> Randy.
In this particular case it could be like the Fn'Result attribute: only available/valid in the function's aspects -- only in this case being the type's.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2016-09-01 20:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-23 20:14 Subtype predicates Anh Vo
2016-08-24 13:06 ` AdaMagica
2016-08-24 16:45 ` Shark8
2016-08-24 21:18 ` Anh Vo
2016-08-24 21:32 ` Shark8
2016-08-24 21:54 ` Jeffrey R. Carter
2016-08-25 0:08 ` Shark8
2016-08-25 0:31 ` Jeffrey R. Carter
2016-08-25 17:28 ` Anh Vo
2016-08-31 18:16 ` Randy Brukardt
2016-09-01 8:09 ` J-P. Rosen
2016-09-01 20:02 ` Randy Brukardt
2016-09-01 20:16 ` Shark8
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox