comp.lang.ada
 help / color / mirror / Atom feed
* Question about asynchronous calls
@ 2013-11-06 11:05 mockturtle
  2013-11-06 18:49 ` J-P. Rosen
  2013-11-06 19:54 ` Shark8
  0 siblings, 2 replies; 12+ messages in thread
From: mockturtle @ 2013-11-06 11:05 UTC (permalink / raw)


Dear all,
I am scheduled to give an introductory talk (45 min) about Ada at the next "Open Source Day" here in Udine.  I was thinking about giving an overview of the language, emphasizing those parts that are unique (or almost unique) to Ada, with the objective of making people curious. 

Among other things, I am planning about saying something about the existence of Annex E for distributed systems.  

While reading section "E.4.1. Asynchronous Remote Calls" of our beloved RM, I got a doubt: as I understand the language does not define any specific mechanism for getting the "return value" of an asynchronous call; if I want the result back I must implement the "back channel" by myself (e.g., a callback or a polling function of type "are we there yet?" [to be said with childish voice] :-).  Am I right?

Thank you for your help

Riccardo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  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
  1 sibling, 1 reply; 12+ messages in thread
From: J-P. Rosen @ 2013-11-06 18:49 UTC (permalink / raw)


Le 06/11/2013 12:05, mockturtle a écrit :
> While reading section "E.4.1. Asynchronous Remote Calls" of our
> beloved RM, I got a doubt: as I understand the language does not
> define any specific mechanism for getting the "return value" of an
> asynchronous call; if I want the result back I must implement the
> "back channel" by myself (e.g., a callback or a polling function of
> type "are we there yet?" [to be said with childish voice] :-).  Am I
> right?
> 
Asynchronous calls is for calls that do not expect a returned value (no
functions, no out parameters). The only thing you loose is that
exceptions raised on the server side are not transmitted.

If you need a return channel, use synchronous calls. Asynchronous calls
are an optimization: you don't wait for the result if you don't expect
any result.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 11:05 Question about asynchronous calls mockturtle
  2013-11-06 18:49 ` J-P. Rosen
@ 2013-11-06 19:54 ` Shark8
  2013-11-06 20:49   ` mockturtle
  2013-11-06 20:49   ` Jeffrey Carter
  1 sibling, 2 replies; 12+ messages in thread
From: Shark8 @ 2013-11-06 19:54 UTC (permalink / raw)


On Wednesday, November 6, 2013 4:05:44 AM UTC-7, mockturtle wrote:
> Dear all,
> 
> I am scheduled to give an introductory talk (45 min) about Ada at the next "Open Source Day" here in Udine.  I was thinking about giving an overview of the language, emphasizing those parts that are unique (or almost unique) to Ada, with the objective of making people curious. 

While it doesn't seem like a big thing: subtypes.
It's nice not to have to check results of some-function from obviously-incorrect-but-technically-possible values like we have to in C/C++/PHP:

Ex: Some_Array'Length returns Natural, I don't have to check for -1 whenever I use it.

And that's from all the way back to Ada 83, with Ada 2012 we have subtype-predicates and can say the following:

    -- Refactor to a parent-type for SSN or EID.
    -- Note SSN is 11 characters long, EIN is 10.
    Type ID_String is new String
      with Dynamic_Predicate => ID_String'Length in 10|11;

    -- SSN format: ###-##-####
    Subtype Social_Security_Number is ID_String(1..11)
      with Dynamic_Predicate =>
	(for all Index in Social_Security_Number'Range =>
          (case Index is
           when 4|7 => Social_Security_Number(Index) = '-',
           when others => Social_Security_Number(Index) in '0'..'9'
          )
         );

    -- EIN format: ##-#######
    Subtype EIN is ID_String(1..10)
      with Dynamic_Predicate =>
	(for all Index in EIN'Range =>
          (case Index is
           when 3 => EIN(Index) = '-',
           when others => EIN(Index) in '0'..'9'
          )
         );

    -- A string guaranteed to be an SSN (###-##-####) or EIN (##-#######).
    Subtype Tax_ID is ID_String
      with Dynamic_Predicate =>
          (Tax_ID in Social_Security_Number) or
          (Tax_ID in EIN);

> Among other things, I am planning about saying something about the existence of Annex E for distributed systems.  
> 
> While reading section "E.4.1. Asynchronous Remote Calls" of our beloved RM, I got a doubt: as I understand the language does not define any specific mechanism for getting the "return value" of an asynchronous call; if I want the result back I must implement the "back channel" by myself (e.g., a callback or a polling function of type "are we there yet?" [to be said with childish voice] :-).  Am I right?

Sorry, I haven't used asynchronous-calls.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 18:49 ` J-P. Rosen
@ 2013-11-06 20:40   ` mockturtle
  0 siblings, 0 replies; 12+ messages in thread
From: mockturtle @ 2013-11-06 20:40 UTC (permalink / raw)



> 
> Asynchronous calls is for calls that do not expect a returned value (no
> functions, no out parameters). The only thing you loose is that
> exceptions raised on the server side are not transmitted.
> 
> If you need a return channel, use synchronous calls. Asynchronous calls
> are an optimization: you don't wait for the result if you don't expect
> any result.
> 

I understand and agree.  However, I was thinking about a case where you have some fairly long computation done on a remote node and the task on the local node can do something else while wait for the result.  So, it could do an asynchronous call, carry some other stuff on and then query for the result.  However, I guess that in most of the cases it would be simpler to have another task on the local node doing  the "something else" while the caller waits for the result.  In the end, it was mostly academic curiosity... 

Thank you

Riccardo


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 19:54 ` Shark8
@ 2013-11-06 20:49   ` mockturtle
  2013-11-07  7:46     ` Stefan.Lucks
  2013-11-07  8:18     ` Jacob Sparre Andersen
  2013-11-06 20:49   ` Jeffrey Carter
  1 sibling, 2 replies; 12+ messages in thread
From: mockturtle @ 2013-11-06 20:49 UTC (permalink / raw)


On Wednesday, November 6, 2013 8:54:02 PM UTC+1, Shark8 wrote:

> 
> 
> While it doesn't seem like a big thing: subtypes.
> 
> It's nice not to have to check results of some-function from obviously-incorrect-but-technically-possible values like we have to in C/C++/PHP:
> 
> Ex: Some_Array'Length returns Natural, I don't have to check for -1 whenever I use it.

Thank you for the suggestion.  Actually, I already have something like that in program, with an example taken from some code of mine: a type representing a valid Matlab variable name (I hope the wrap-around does not mess with the code)

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 am just beginning to use this, contracts and invariants and it turns out that they are amazing "bug traps."

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 19:54 ` Shark8
  2013-11-06 20:49   ` mockturtle
@ 2013-11-06 20:49   ` Jeffrey Carter
  2013-11-06 20:58     ` Shark8
  1 sibling, 1 reply; 12+ messages in thread
From: Jeffrey Carter @ 2013-11-06 20:49 UTC (permalink / raw)


On 11/06/2013 12:54 PM, Shark8 wrote:
>
> Ex: Some_Array'Length returns Natural, I don't have to check for -1 whenever I use it.

'Length returns universal_integer (see ARM 3.6.2) so this is not an argument for 
subtypes (though there are many arguments for them). 'Length is defined not to 
return a negative value, so if it does do so, you have a compiler error.

-- 
Jeff Carter
"Mr. President, we must not allow a mine-shaft gap!"
Dr. Strangelove
33

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 20:49   ` Jeffrey Carter
@ 2013-11-06 20:58     ` Shark8
  0 siblings, 0 replies; 12+ messages in thread
From: Shark8 @ 2013-11-06 20:58 UTC (permalink / raw)


On Wednesday, November 6, 2013 1:49:52 PM UTC-7, Jeffrey Carter wrote:
> On 11/06/2013 12:54 PM, Shark8 wrote:
> >
> > Ex: Some_Array'Length returns Natural, I don't have to check for -1 whenever I use it.
> 
> 'Length returns universal_integer (see ARM 3.6.2) so this is not an argument for subtypes (though there are many arguments for them). 'Length is defined not to return a negative value, so if it does do so, you have a compiler error.

Ah, you're right. That's what happens when I try shortening/refactoring quickly.
(I should have stuck with the first thing I thought of, a hypothetical 'count' returning natural.)

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 20:49   ` mockturtle
@ 2013-11-07  7:46     ` Stefan.Lucks
  2013-11-07 10:23       ` Predicates (was: Question about asynchronous calls) Georg Bauhaus
  2013-11-07 18:59       ` Question about asynchronous calls mockturtle
  2013-11-07  8:18     ` Jacob Sparre Andersen
  1 sibling, 2 replies; 12+ messages in thread
From: Stefan.Lucks @ 2013-11-07  7:46 UTC (permalink / raw)


[-- Attachment #1: Type: TEXT/PLAIN, Size: 1560 bytes --]

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.

For me, first checking the first character, and then checking the other 
characters is more intuitive than doing it the other way. Also, I rather 
avoid the redundant check for the first letter being alphanumeric or '_',
since the first character is checked for being a letter, anyway.

And I wouldn't bother to replace the second "and then" by "and", as it has 
been in your code. However, mixing "and then" and "and" requires 
additional brackets, which I would prefer to avoid.




------  I  love  the  taste  of  Cryptanalysis  in  the morning!  ------
     <http://www.uni-weimar.de/cms/medien/mediensicherheit/home.html>
--Stefan.Lucks (at) uni-weimar.de, Bauhaus-Universität Weimar, Germany--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-06 20:49   ` mockturtle
  2013-11-07  7:46     ` Stefan.Lucks
@ 2013-11-07  8:18     ` Jacob Sparre Andersen
  2013-11-07 19:00       ` mockturtle
  1 sibling, 1 reply; 12+ messages in thread
From: Jacob Sparre Andersen @ 2013-11-07  8:18 UTC (permalink / raw)


Riccardo <framefritti@gmail.com> wrote:

> I am just beginning to use this, contracts and invariants and it turns
> out that they are amazing "bug traps."

You are welcome to pick some inspiration for your presentation from two
of my recent talks on Ada 2012:

   http://www.jacob-sparre.dk/programming/Contract-based-programming.pdf
   http://www.jacob-sparre.dk/programming/Alice-in-Adaland.pdf

Greetings,

Jacob
-- 
"Then, after a second or so, nothing continued to happen."


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Predicates (was: Question about asynchronous calls)
  2013-11-07  7:46     ` Stefan.Lucks
@ 2013-11-07 10:23       ` Georg Bauhaus
  2013-11-07 18:59       ` Question about asynchronous calls mockturtle
  1 sibling, 0 replies; 12+ messages in thread
From: Georg Bauhaus @ 2013-11-07 10:23 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-07  7:46     ` Stefan.Lucks
  2013-11-07 10:23       ` Predicates (was: Question about asynchronous calls) Georg Bauhaus
@ 2013-11-07 18:59       ` mockturtle
  1 sibling, 0 replies; 12+ messages in thread
From: mockturtle @ 2013-11-07 18:59 UTC (permalink / raw)


On Thursday, November 7, 2013 8:46:54 AM UTC+1, Stefan...@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.

Ops! Touche! You are right...  :-)


> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Question about asynchronous calls
  2013-11-07  8:18     ` Jacob Sparre Andersen
@ 2013-11-07 19:00       ` mockturtle
  0 siblings, 0 replies; 12+ messages in thread
From: mockturtle @ 2013-11-07 19:00 UTC (permalink / raw)


On Thursday, November 7, 2013 9:18:12 AM UTC+1, Jacob Sparre Andersen wrote:
> Riccardo <framefritti@gmail.com> wrote:
> 
> > I am just beginning to use this, contracts and invariants and it turns
> > out that they are amazing "bug traps."
> 
> You are welcome to pick some inspiration for your presentation from two
> of my recent talks on Ada 2012:
> 
>    http://www.jacob-sparre.dk/programming/Contract-based-programming.pdf
>    http://www.jacob-sparre.dk/programming/Alice-in-Adaland.pdf
>

Thank you.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-11-07 19:00 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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       ` Predicates (was: Question about asynchronous calls) Georg Bauhaus
2013-11-07 18:59       ` Question about asynchronous calls 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

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