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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.unit0.net!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Thu, 07 Nov 2013 11:23:29 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Predicates (was: Question about asynchronous calls) References: <19b9cc6b-28a4-45e4-939c-7720ae5666b9@googlegroups.com> <8a7f97ef-672e-4930-9502-e1202dd158fd@googlegroups.com> <60be5eb1-85e0-43c5-8c81-d191ee805dd3@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <527b6a22$0$6628$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 07 Nov 2013 11:23:30 CET NNTP-Posting-Host: 6a7327d0.newsspool2.arcor-online.net X-Trace: DXC=BhI?\_hfWEUHigV@eW57PQA9EHlD;3YcR4Fo<]lROoRQ8kFZLh>_cHTX3j]gUcPkBiIOhY X-Complaints-To: usenet-abuse@arcor.de Xref: news.eternal-september.org comp.lang.ada:17596 Date: 2013-11-07T11:23:30+01:00 List-Id: On 07.11.13 08:46, Stefan.Lucks@uni-weimar.de wrote: > On Wed, 6 Nov 2013, mockturtle wrote: > >> type Matlab_Name is new >> String >> with Dynamic_Predicate => >> (for all I in Matlab_Name'Range => >> Is_Alphanumeric (Matlab_Name (I)) or Matlab_Name (I) = '_') >> and >> Is_Letter (Matlab_Name (Matlab_Name'First)); > > I suggest to write the following. > > with Dynamic_Predicate => > ( Natlab_Name'Length > 0 > and then > Is_Letter (Matlab_Name (Matlab_Name'First) > and then > for all I in Matlab_Name'First+1 .. Matlab'Last => > Is_Alphanumeric (Matlab_Name (I)) or Matlab_Name (I) = '_') > ); > > (Warning: not syntax checked!) > > The "Natlab_Name'Length > 0 and then" part is important -- your code would raise Constraint_Error if the Matlab_Name is the empty string. > > The other modifications are a matter of taste. Most interesting to see how the development of a provable predicate would hinge on testing with mind or hand: either by thinking of all the possibilities, or even by writing them down as objects of type Matlab_Name for AUnit testing, say. Since two predicates can have a "combined" value once two objects are involved, a level of indirection for predicates seems warranted; it would allow testing different combinations without having to perform cut&paste, a technique know to be prone to human error. Perhaps, thinking of ML style local definitions, and then selecting one of the expressions as predicate seems possible with the help of the new function expressions? with Dynamic_Predicate => (declare function test_1 return Boolean is (for all I in Matlab'Range ...); function test_2 return Boolean is (Matlab_Name'Length > 0 ...); select -- or "if" test_1 else raise AI_12_0022_Exception with "test_1 failed"); Hm... given test_1 etc are Boolean functions, a declarative part here seems to have value on its own? Function expressions can add structure to otherwise huge expressions in predicates. Thus, with Dynamic_Predicate => (declare function Is_Name (Lo, Hi) return Boolean is (for all I in Lo .. Hi => Is_Alphanumeric (Matlab_Name (I)) or Matlab_Name (I) = '_'); select -- or "if" Natlab_Name'Length > 0 and then Is_Letter (Matlab_Name (Matlab_Name'First) and then Is_Name (Matlab_Name'First+1, Matlab'Last) else raise AI_12_0022_Exception with "test_1 failed"); This particular example may tear things apart more than add clarity through structured programming, though, but the idea seems valid.