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

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