comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <jacob@jacob-sparre.dk>
Subject: Re: Making sense of predicates
Date: Tue, 22 Oct 2013 09:35:02 +0200
Date: 2013-10-22T09:35:02+02:00	[thread overview]
Message-ID: <87eh7drc61.fsf@adaheads.sparre-andersen.dk> (raw)
In-Reply-To: 1830ad81-00dc-4639-922a-771a01cd06ec@googlegroups.com

Shark8 <onewingedshark@gmail.com> writes:

> Agreed; I was disappointed the following doesn't work:
>
>  Subtype Digit_Character is Character range '0'..'9';
>
>  Subtype Part_Number is String
>    with Static_Predicate => (for all C in Part_Number => C in Digit_Character);
>
> As it would be nice to basically subtype out [further-constrain] the
> element-type just as we can do to the index (e.g. "Subtype
> Phone_Digits is String(1..7);", which is equivalent to "subtype
> phone_range is Positive range 1..7; Subtype Phone_Digits is
> String(Phone_Range);", where 'phone_range' is an anonymous subtype.)

If you did it right, it would work:

package Parts is
   subtype Digit_Character is Character range '0' .. '9';

   subtype Part_Number is String
     with Dynamic_Predicate => (for all C of Part_Number
                                  => C in Digit_Character);
end Parts;

with Parts;

procedure Use_Parts is
   Work : Parts.Part_Number := "1234";
   Fail : Parts.Part_Number := "fail";
begin
   null;
end Use_Parts;

% ./use_parts

raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : Dynamic_Predicate failed at use_parts.adb:6
%

Greetings,

Jacob
-- 
Photos from the Faroe Islands:
       http://billeder.sparre-andersen.dk/The_Faroe_Islands/

  reply	other threads:[~2013-10-22  7:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 19:51 Making sense of predicates Dmitry A. Kazakov
2013-10-22  4:35 ` Randy Brukardt
2013-10-22  8:19   ` Dmitry A. Kazakov
2013-10-22 12:53     ` Georg Bauhaus
2013-10-22 13:38       ` Dmitry A. Kazakov
2013-10-22 20:38         ` Georg Bauhaus
2013-10-24  4:03     ` Randy Brukardt
2013-10-24  7:26       ` Dmitry A. Kazakov
2013-10-22  7:14 ` Shark8
2013-10-22  7:35   ` Jacob Sparre Andersen [this message]
2013-10-22 17:26     ` Shark8
2013-10-23  7:56       ` Jacob Sparre Andersen
2013-10-24  3:58       ` Randy Brukardt
2013-10-22  8:11   ` Dmitry A. Kazakov
2013-10-22  7:20 ` Jacob Sparre Andersen
2013-10-22  7:57   ` Dmitry A. Kazakov
2013-10-22 14:52     ` Dan'l Miller
2013-10-22 16:30       ` Dmitry A. Kazakov
2013-10-22 17:15         ` Dan'l Miller
2013-10-22 19:26           ` Dmitry A. Kazakov
2013-10-22 19:49             ` J-P. Rosen
2013-10-22 21:30             ` Dan'l Miller
2013-10-23  9:25               ` Dmitry A. Kazakov
replies disabled

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