comp.lang.ada
 help / color / mirror / Atom feed
From: Xavier Petit <xpetit@becoast.fr>
Subject: Predicate and value attribute
Date: Sat, 23 Jan 2016 12:16:10 +0100
Date: 2016-01-23T12:16:10+01:00	[thread overview]
Message-ID: <56a360fa$0$3294$426a74cc@news.free.fr> (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

             reply	other threads:[~2016-01-23 11:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-23 11:16 Xavier Petit [this message]
2016-01-24 11:38 ` Predicate and value attribute 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
replies disabled

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