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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,6327f05d4989a68d X-Google-NewGroupId: yes X-Google-Thread: 107e1d,6327f05d4989a68d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,gid43d0c745c,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.66.89.135 with SMTP id bo7mr496286pab.16.1355865147607; Tue, 18 Dec 2012 13:12:27 -0800 (PST) Path: s9ni52235pbb.0!nntp.google.com!news.glorb.com!feeder.erje.net!us.feeder.erje.net!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bill Findlay Newsgroups: comp.lang.ada,fr.comp.lang.ada Subject: Re: Press Release - Ada 2012 Language Standard Approved by ISO Date: Tue, 18 Dec 2012 21:12:25 +0000 Message-ID: References: Mime-Version: 1.0 X-Trace: individual.net F41W5KCo/5dYiwqtiiiXpA1MbXEXmGSzCP3UAz/IGyuR89gIHvi8vMT1xqKIb5lJBq Cancel-Lock: sha1:fB2I4aFejq/HqXZOcec4cfEiOQE= User-Agent: Microsoft-Entourage/12.33.0.120411 Thread-Topic: Press Release - Ada 2012 Language Standard Approved by ISO Thread-Index: Ac3dZGCOqWIM6TWm2U2nISNb7/QkqQ== Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: 2012-12-18T21:12:25+00:00 List-Id: On 18/12/2012 16:57, in article wcc8v8vti17.fsf@shell01.TheWorld.com, "Robert A Duff" wrote: > dirk@vana.cs.kuleuven.be. (Dirk Craeynest) writes: > >> Ada 2012 brings significant enhancements to Ada, most notably in the >> area of "contract-based programming." New features here include the >> ability to specify preconditions and postconditions for subprograms, >> and invariants for private (encapsulated) types. > > Why does everybody neglect predicates, which are more important > than pre/post/invariant? A bit of fun with a predicate: -- compile with gnatmake -gnat12la pn.adb with Ada.Text_IO; use Ada.Text_IO; procedure pn is type candidate is range 1 .. 2**30; function is_prime (nr : candidate) return Boolean is n : constant candidate := nr; j : candidate; begin if n < 2 then return False; end if; for d in candidate range 2..3 loop if n = d then return True; elsif n mod d = 0 then return False; end if; end loop; j := 5; -- j = 6k-1, k = 1 loop if n mod j = 0 then return False; end if; j := j + 2; -- j = 6k+1 exit when j >= n; if n mod j = 0 then return False; end if; j := j + 4; -- j = 6k+5 = 6k'-1, k' = k+1 exit when j >= n; end loop; return True; end is_prime; -- The following exemplifies a couple of new features in Ada 2012, -- namely predicates on subtypes, -- and conditional expressions (redux, after Algol 60). -- Only prime numbers can be successfully assigned to this subtype. subtype prime_number is candidate with Dynamic_Predicate => is_prime(prime_number); OK : constant prime_number := 31; -- 31 is prime KO : prime_number := 19; -- 19 is prime begin Put_Line(candidate'Image(OK) & (if is_prime(OK) then " is" else " is not") & " a prime"); Flush; KO := 32; -- 32 is NOT prime, so this should raise an exception! Put_Line(candidate'Image(OK) & (if is_prime(KO) then " is" else " is not") & " a prime"); Flush; exception when others => Put_Line("KO was" & (if KO = 19 then " NOT" else " WRONGLY") & " set to 32"); Flush; end pn; -- Bill Findlay with blueyonder.co.uk; use surname & forename;