comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Musings on RxAda
Date: Thu, 19 Nov 2015 14:14:56 +0100
Date: 2015-11-19T14:14:56+01:00	[thread overview]
Message-ID: <87610y2krz.fsf@adaheads.sparre-andersen.dk> (raw)
In-Reply-To: mvlopk$49j$1@dont-email.me

Alejandro R. Mosteo wrote:

> Anyway, the gist of it is that you chain function calls (operators in
> their jargon) to process data asynchronously.

This sounds like how you chain filters in a Unix shell using pipes.

Continuing that thought, an obvious mapping to Ada is tasks (acting as
filters) and protected objects (acting as pipes/buffers).

Even though Ada doesn't explicitly have lambda functions, localised
scopes allow similar (if somewhat more verbose) formulations.

> Observable.just("Hello, world!")
>     .map(s -> s + " -Dan")
>     .map(s -> s.hashCode())
>     .map(i -> Integer.toString(i))
>     .subscribe(s -> System.out.println(s));

   Q1 : String_Queues.Queue;

   task Hello_World;
   task body Hello_World is
   begin
      Q1.Enqueue (+"Hello, world!");
   end Hello_World;

   Q2 : String_Queues.Queue;

   task Add_Source;
   task body Add_Source is
      Buffer : Unbounded_String;
   begin
      Q1.Dequeue (Buffer);
      Q2.Enqueue (Buffer & " -Dan");
   end Add_Source;

   Q3 : Hash_Queues.Queue;

   task Hash_String;
   task body Hash_String is
      Buffer : Unbounded_String;
   begin
      Q2.Dequeue (Buffer);
      Q3.Enqueue (Hash (Buffer));
   end Hash_String;

   Q4 : String_Queues.Queue;

   task Hash_As_String;
   task body Hash_As_String is
      Buffer : Hash_Type;
   begin
      Q3.Dequeue (Buffer);
      Q4.Enqueue (+Hash_Type'Image (Buffer));
   end Hash_As_String;

   task Output;
   task body Output is
      Buffer : Unbounded_String;
   begin
      Q4.Dequeue (Buffer);
      Put_Line (+Buffer);
   end Output;

See <https://bitbucket.org/sparre/ada-2012-examples>
("src/chained_calls.adb") for the full, compilable version.

I'm tempted to make the tasks task types with references to the input
and output queues as discriminants, but I'm not sure it really would be
an improvement.

Greetings,

Jacob
-- 
"If it's a mess, hide it..." -- J-P. Rosen

      parent reply	other threads:[~2015-11-19 13:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 14:30 Musings on RxAda Alejandro R.  Mosteo
2015-10-15 14:40 ` brbarkstrom
2015-10-21 11:45 ` Hadrien Grasland
2015-10-21 12:12 ` Hadrien Grasland
2015-10-21 13:35   ` Dmitry A. Kazakov
2015-10-21 16:18     ` Hadrien Grasland
2015-10-21 16:47       ` Dmitry A. Kazakov
2015-10-21 19:09         ` Hadrien Grasland
2015-10-21 19:35           ` Dmitry A. Kazakov
2015-10-21 21:04             ` Hadrien Grasland
2015-10-22 11:02               ` Alejandro R.  Mosteo
2015-10-22 12:33                 ` Dmitry A. Kazakov
2015-10-22 16:41                   ` Alejandro R.  Mosteo
2015-11-19 13:14 ` Jacob Sparre Andersen [this message]
replies disabled

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