comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Predicates (was: Question about asynchronous calls)
Date: Thu, 07 Nov 2013 11:23:29 +0100
Date: 2013-11-07T11:23:30+01:00	[thread overview]
Message-ID: <527b6a22$0$6628$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <alpine.DEB.2.10.1311070825170.26025@debian>

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.

  reply	other threads:[~2013-11-07 10:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-06 11:05 Question about asynchronous calls mockturtle
2013-11-06 18:49 ` J-P. Rosen
2013-11-06 20:40   ` mockturtle
2013-11-06 19:54 ` Shark8
2013-11-06 20:49   ` mockturtle
2013-11-07  7:46     ` Stefan.Lucks
2013-11-07 10:23       ` Georg Bauhaus [this message]
2013-11-07 18:59       ` mockturtle
2013-11-07  8:18     ` Jacob Sparre Andersen
2013-11-07 19:00       ` mockturtle
2013-11-06 20:49   ` Jeffrey Carter
2013-11-06 20:58     ` Shark8
replies disabled

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