From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:a24:2584:: with SMTP id g126mr4385994itg.23.1553978646053; Sat, 30 Mar 2019 13:44:06 -0700 (PDT) X-Received: by 2002:a05:6830:154e:: with SMTP id l14mr37367631otp.269.1553978645739; Sat, 30 Mar 2019 13:44:05 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!136no284457itk.0!news-out.google.com!r82ni298ita.0!nntp.google.com!78no285065itl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 30 Mar 2019 13:44:05 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=87.154.205.191; posting-account=3zVVBwoAAAC7BSMfgNP7DSbqU9urpt40 NNTP-Posting-Host: 87.154.205.191 References: <36c2ff61-8cca-4435-995f-dfc34fa44b69@googlegroups.com> <511923fb-dbb9-4e33-82a8-b4bbbf002a6d@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: type definition for an integer with discrete range From: mario.blunk.gplus@gmail.com Injection-Date: Sat, 30 Mar 2019 20:44:06 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:56018 Date: 2019-03-30T13:44:05-07:00 List-Id: 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.