From: mario.blunk.gplus@gmail.com
Subject: Re: type definition for an integer with discrete range
Date: Sat, 30 Mar 2019 13:44:05 -0700 (PDT)
Date: 2019-03-30T13:44:05-07:00 [thread overview]
Message-ID: <c3f1bebd-98b7-45fb-b778-8542130bcdf5@googlegroups.com> (raw)
In-Reply-To: <lylg0x2x22.fsf@pushface.org>
On Friday, March 29, 2019 at 10:24:55 PM UTC+1, Simon Wright wrote:
>
> What about this?
>
> pragma Assertion_Policy (Check);
> with Ada.Text_Io; use Ada.Text_Io;
> procedure Type_Integer is
> subtype Number is Integer range -100 .. 100
> with Dynamic_Predicate => Number mod 5 = 0;
> V : Number;
> begin
> V := 0;
> Put_Line ("0'image is " & V'Image);
> V := -50;
> Put_Line ("-50'image is " & V'Image);
> V := 42;
> Put_Line ("42'image is " & V'Image);
> end Type_Integer;
>
> Executing gives
>
> $ ./type_integer
> 0'image is 0
> -50'image is -50
>
> raised SYSTEM.ASSERTIONS.ASSERT_FAILURE : Dynamic_Predicate failed at
> type_integer.adb:12
Great, that brings me a lot further. I updated the file at
https://github.com/Blunk-electronic/ada_training/blob/master/src/type_angle/type_angle.adb
Two more questions:
1. How can I catch the exception SYSTEM.ASSERTIONS.ASSERT_FAILURE in the exception handler ? See line 26.
2. How can I print the "gap size" via put ? See line 28.
Thanks to all of you out there.
next prev parent reply other threads:[~2019-03-30 20:44 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-29 16:10 type definition for an integer with discrete range mario.blunk.gplus
2019-03-29 16:34 ` tranngocduong
2019-03-29 16:46 ` mario.blunk.gplus
2019-03-30 4:17 ` tranngocduong
2019-03-30 4:19 ` tranngocduong
2019-03-29 20:24 ` Simon Wright
2019-03-29 20:51 ` mario.blunk.gplus
2019-03-29 21:24 ` Simon Wright
2019-03-30 20:44 ` mario.blunk.gplus [this message]
2019-03-30 22:13 ` Jere
2019-04-01 6:59 ` mario.blunk.gplus
2019-04-01 15:52 ` AdaMagica
2019-04-01 16:27 ` Simon Wright
2019-04-01 16:41 ` AdaMagica
2019-03-29 21:57 ` Dmitry A. Kazakov
2019-03-30 21:45 ` John Perry
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox