comp.lang.ada
 help / color / mirror / Atom feed
* Predicate and value attribute
@ 2016-01-23 11:16 Xavier Petit
  2016-01-24 11:38 ` AdaMagica
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Xavier Petit @ 2016-01-23 11:16 UTC (permalink / raw)


Hello, I have some beginner questions.

subtype Number is String
   with Dynamic_Predicate => Positive'Value (Number) in -1 | 5;

This line compiles and works. I would like some confirmation that 'Value 
attribute returns in this case the type Integer and doesn't take into 
account Positive subtype, and is why the following is valid:

Test : Number := "-1";

So I should never write "Positive'Value" right ?

And now my real newbie question : why do I have the error "Value_Integer 
is undefined" if I switch '|' to ".." this way :

subtype Number is String
   with Dynamic_Predicate => Positive'Value (Number) in -1 .. 5;

Knowing it works like this :

function Check (Item : String) return Boolean
is
   (Positive'Value (Item) in -1 .. 5);

subtype Number is String
   with Dynamic_Predicate => Check (Number);


Anyway now I use the oldschool :

type Number is range -1 .. 5;

and then do the conversion as string when I need to :

Number'Image (Item).

I could write a function to remove the first whitespace in case of 
non-negative number.

Thanks by advance !

-- 
Xavier Petit

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

* Re: Predicate and value attribute
  2016-01-23 11:16 Predicate and value attribute Xavier Petit
@ 2016-01-24 11:38 ` AdaMagica
  2016-01-25  8:28 ` Jacob Sparre Andersen
  2016-01-25 14:52 ` Xavier Petit
  2 siblings, 0 replies; 11+ messages in thread
From: AdaMagica @ 2016-01-24 11:38 UTC (permalink / raw)


Am Samstag, 23. Januar 2016 12:16:12 UTC+1 schrieb Xavier Petit:
> Hello, I have some beginner questions.
> 
> subtype Number is String
>    with Dynamic_Predicate => Positive'Value (Number) in -1 | 5;
> 
> This line compiles and works. I would like some confirmation that 'Value 
> attribute returns in this case the type Integer and doesn't take into 
> account Positive subtype, and is why the following is valid:
> 
> Test : Number := "-1";
> 
> So I should never write "Positive'Value" right ?

It's the *type's* attribute, the subtype name is irreleveant (Integer, Natural, Positive all are subtypes of the same anonymous type).


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

* Re: Predicate and value attribute
  2016-01-23 11:16 Predicate and value attribute Xavier Petit
  2016-01-24 11:38 ` AdaMagica
@ 2016-01-25  8:28 ` Jacob Sparre Andersen
  2016-01-25 14:52 ` Xavier Petit
  2 siblings, 0 replies; 11+ messages in thread
From: Jacob Sparre Andersen @ 2016-01-25  8:28 UTC (permalink / raw)


Xavier Petit wrote:

> So I should never write "Positive'Value" right?

It is completely okay to use "Positive'Value", but it generally only
makes sense if you are putting the result into an object of type
Positive.

As S'Value attribute returns S'Base, "Integer'Value" isn't much more
appropriate than "Positive'Value".

Greetings,

Jacob
-- 
"The problem with America is stupidity. I'm not saying there
 should be a capital punishment for stupidity, but why don't
 we just take the safety labels off of everything and let
 the problem solve itself?"

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

* Re: Predicate and value attribute
  2016-01-23 11:16 Predicate and value attribute Xavier Petit
  2016-01-24 11:38 ` AdaMagica
  2016-01-25  8:28 ` Jacob Sparre Andersen
@ 2016-01-25 14:52 ` Xavier Petit
  2016-01-26  0:28   ` Anh Vo
  2 siblings, 1 reply; 11+ messages in thread
From: Xavier Petit @ 2016-01-25 14:52 UTC (permalink / raw)


Many thanks for the answers, it's clearer for me now.
And concerning the "Value_Integer is undefined" error in the predicate, 
anyone has an idea ?

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

* Re: Predicate and value attribute
  2016-01-25 14:52 ` Xavier Petit
@ 2016-01-26  0:28   ` Anh Vo
  2016-01-26 11:09     ` Xavier Petit
  0 siblings, 1 reply; 11+ messages in thread
From: Anh Vo @ 2016-01-26  0:28 UTC (permalink / raw)


On Monday, January 25, 2016 at 6:52:02 AM UTC-8, Xavier Petit wrote:
> Many thanks for the answers, it's clearer for me now.
> And concerning the "Value_Integer is undefined" error in the predicate, 
> anyone has an idea ?

I suggest you post your code which triggered the error. So, we can use the same reference.

Anh Vo

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

* Re: Predicate and value attribute
  2016-01-26  0:28   ` Anh Vo
@ 2016-01-26 11:09     ` Xavier Petit
  2016-01-26 18:06       ` Jeffrey R. Carter
  2016-01-26 20:43       ` Simon Wright
  0 siblings, 2 replies; 11+ messages in thread
From: Xavier Petit @ 2016-01-26 11:09 UTC (permalink / raw)


> I suggest you post your code which triggered the error. So, we can use the same reference.
>
> Anh Vo
>

Ok, here the main file is sandbox.adb =>

procedure Sandbox is
    subtype Number is String
      with Dynamic_Predicate => Integer'Value (Number) in -1 .. 5;

    subtype Number2 is String
      with Dynamic_Predicate => Integer'Value (Number2) in -1 | 5;

    function Check_Number3 (Item : String) return Boolean
    is
      (Integer'Value (Item) in -1 .. 5);

    subtype Number3 is String
      with Dynamic_Predicate => Check_Number3 (Number3);

    Test : constant Number := "-1";
    Test2 : constant Number2 := "-1";
    Test3 : constant Number3 := "-1";

begin
    null;
end;


$ gnatmake sandbox.adb
gcc -c sandbox.adb
sandbox.adb:3:39: "Value_Integer" is undefined
compilation abandoned due to previous error
gnatmake: "sandbox.adb" compilation error

$ gnatmake --version
GNATMAKE GPL 2015 (20150428-49)

Adacore GNAT 2015

The subtype "Number" seems to be wrong whereas "Number2" and "Number3" 
are valid.

-- 
Xavier Petit


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

* Re: Predicate and value attribute
  2016-01-26 11:09     ` Xavier Petit
@ 2016-01-26 18:06       ` Jeffrey R. Carter
  2016-01-26 20:41         ` Anh Vo
  2016-01-26 20:43       ` Simon Wright
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2016-01-26 18:06 UTC (permalink / raw)


On 01/26/2016 04:09 AM, Xavier Petit wrote:
> 
> procedure Sandbox is
>    subtype Number is String
>      with Dynamic_Predicate => Integer'Value (Number) in -1 .. 5;
> 
>    subtype Number2 is String
>      with Dynamic_Predicate => Integer'Value (Number2) in -1 | 5;
> 
>    function Check_Number3 (Item : String) return Boolean
>    is
>      (Integer'Value (Item) in -1 .. 5);
> 
>    subtype Number3 is String
>      with Dynamic_Predicate => Check_Number3 (Number3);
> 
>    Test : constant Number := "-1";
>    Test2 : constant Number2 := "-1";
>    Test3 : constant Number3 := "-1";
> 
> begin
>    null;
> end;

With GNAT 4.9.2 this compiles without problem.

-- 
Jeff Carter
"I'm a vicious jungle beast!"
Play It Again, Sam
131

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

* Re: Predicate and value attribute
  2016-01-26 18:06       ` Jeffrey R. Carter
@ 2016-01-26 20:41         ` Anh Vo
  0 siblings, 0 replies; 11+ messages in thread
From: Anh Vo @ 2016-01-26 20:41 UTC (permalink / raw)


On Tuesday, January 26, 2016 at 10:06:42 AM UTC-8, Jeffrey R. Carter wrote:
> On 01/26/2016 04:09 AM, Xavier Petit wrote:
> > 
> > procedure Sandbox is
> >    subtype Number is String
> >      with Dynamic_Predicate => Integer'Value (Number) in -1 .. 5;
> > 
> >    subtype Number2 is String
> >      with Dynamic_Predicate => Integer'Value (Number2) in -1 | 5;
> > 
> >    function Check_Number3 (Item : String) return Boolean
> >    is
> >      (Integer'Value (Item) in -1 .. 5);
> > 
> >    subtype Number3 is String
> >      with Dynamic_Predicate => Check_Number3 (Number3);
> > 
> >    Test : constant Number := "-1";
> >    Test2 : constant Number2 := "-1";
> >    Test3 : constant Number3 := "-1";
> > 
> > begin
> >    null;
> > end;
> 
> With GNAT 4.9.2 this compiles without problem.
 
A bug report should be in order. By the way, GNATMAKE GPL 2015 (20150428-49) was based on gcc version 4.9.3

Anh Vo


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

* Re: Predicate and value attribute
  2016-01-26 11:09     ` Xavier Petit
  2016-01-26 18:06       ` Jeffrey R. Carter
@ 2016-01-26 20:43       ` Simon Wright
  2016-01-27 22:02         ` Xavier Petit
  1 sibling, 1 reply; 11+ messages in thread
From: Simon Wright @ 2016-01-26 20:43 UTC (permalink / raw)


Xavier Petit <xpetit@becoast.fr> writes:

> $ gnatmake sandbox.adb
> gcc -c sandbox.adb
> sandbox.adb:3:39: "Value_Integer" is undefined
> compilation abandoned due to previous error
> gnatmake: "sandbox.adb" compilation error

Same problem with FSF GCC 5.2.0.

I think you have found a genuine bug; the recreated source given by
-gnatG shows that the internal representation for 'number' is quite
different from that for 'number2', for no apparent reason.

Time to report the problem to AdaCore, I think.


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

* Re: Predicate and value attribute
  2016-01-26 20:43       ` Simon Wright
@ 2016-01-27 22:02         ` Xavier Petit
  2016-01-28  7:56           ` Simon Wright
  0 siblings, 1 reply; 11+ messages in thread
From: Xavier Petit @ 2016-01-27 22:02 UTC (permalink / raw)


Thanks for the tests and explanations

To summurize 4.9.2 (current Debian Stable) compiles this file whereas
4.9.3 (GNAT GPL 2015), 5.2.0 and 5.3.1 (current Debian testing) makes 
the error "Value_Integer" is undefined.

I'm not sure about the way to report bugs to Adacore, should I send a 
mail to report-A-gnat,com ?

I didn't knew the -gnatG switch, very interesting output thank you.

-- 
Xavier Petit

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

* Re: Predicate and value attribute
  2016-01-27 22:02         ` Xavier Petit
@ 2016-01-28  7:56           ` Simon Wright
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Wright @ 2016-01-28  7:56 UTC (permalink / raw)


Xavier Petit <xpetit@becoast.fr> writes:

> I'm not sure about the way to report bugs to Adacore, should I send a
> mail to report-A-gnat,com ?

mail report at adacore . com with GNAT at the start of the Subject.


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

end of thread, other threads:[~2016-01-28  7:56 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-23 11:16 Predicate and value attribute Xavier Petit
2016-01-24 11:38 ` AdaMagica
2016-01-25  8:28 ` Jacob Sparre Andersen
2016-01-25 14:52 ` Xavier Petit
2016-01-26  0:28   ` Anh Vo
2016-01-26 11:09     ` Xavier Petit
2016-01-26 18:06       ` Jeffrey R. Carter
2016-01-26 20:41         ` Anh Vo
2016-01-26 20:43       ` Simon Wright
2016-01-27 22:02         ` Xavier Petit
2016-01-28  7:56           ` Simon Wright

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