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!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Musings on RxAda Date: Thu, 19 Nov 2015 14:14:56 +0100 Organization: JSA Research & Innovation Message-ID: <87610y2krz.fsf@adaheads.sparre-andersen.dk> References: NNTP-Posting-Host: 109.56.61.124.mobile.3.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: loke.gir.dk 1447939898 2065 109.56.61.124 (19 Nov 2015 13:31:38 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Thu, 19 Nov 2015 13:31:38 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) Cancel-Lock: sha1:GD4YTdQ8KqsavlYUUciPEB39AnU= Xref: news.eternal-september.org comp.lang.ada:28463 Date: 2015-11-19T14:14:56+01:00 List-Id: 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 ("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