From 607904a5238ecfcf7761143207ca41e082a12aa8 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 22 Jul 2017 18:06:39 -0400 Subject: - Renamed Chan to Channel. --- stdlib/source/lux/concurrency/actor.lux | 6 +-- stdlib/source/lux/concurrency/frp.lux | 84 ++++++++++++++++---------------- stdlib/source/lux/concurrency/stm.lux | 16 +++--- stdlib/test/test/lux/concurrency/frp.lux | 20 ++++---- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/stdlib/source/lux/concurrency/actor.lux b/stdlib/source/lux/concurrency/actor.lux index 93f1ed6d8..dd34a7ae8 100644 --- a/stdlib/source/lux/concurrency/actor.lux +++ b/stdlib/source/lux/concurrency/actor.lux @@ -61,15 +61,15 @@ {#mailbox (stm;var (:! (Message ($ +0)) [])) #kill-switch (P;promise Unit) #obituary (P;promise (Obituary ($ +0)))}) - mailbox-chan (io;run (stm;follow (get@ #mailbox self))) - |mailbox| (stm;var mailbox-chan) + mailbox-channel (io;run (stm;follow (get@ #mailbox self))) + |mailbox| (stm;var mailbox-channel) _ (P/map (function [_] (io;run (do Monad [mb (stm;read! |mailbox|)] (frp;close mb)))) (get@ #kill-switch self)) process (loop [state init - messages mailbox-chan] + messages mailbox-channel] (do P;Monad [?messages+ messages] (case ?messages+ diff --git a/stdlib/source/lux/concurrency/frp.lux b/stdlib/source/lux/concurrency/frp.lux index 538bbdcbd..a1839850d 100644 --- a/stdlib/source/lux/concurrency/frp.lux +++ b/stdlib/source/lux/concurrency/frp.lux @@ -13,22 +13,22 @@ (.. ["&" promise])) ## [Types] -(type: #export (Chan a) +(type: #export (Channel a) {#;doc "An asynchronous channel of values which may be closed. Reading from a channel does not remove the read piece of data, as it can still be accessed if you have an earlier node of the channel."} - (&;Promise (Maybe [a (Chan a)]))) + (&;Promise (Maybe [a (Channel a)]))) ## [Syntax] -(syntax: #export (chan [type s;any]) - {#;doc (doc "Makes an uninitialized Chan (in this case, of Unit)." - (chan Unit))} - (wrap (list (` (: (Chan (~ type)) +(syntax: #export (channel [type s;any]) + {#;doc (doc "Makes an uninitialized Channel (in this case, of Nat)." + (channel Nat))} + (wrap (list (` (: (Channel (~ type)) (&;promise' #;None)))))) ## [Values] (def: #export (filter p xs) - (All [a] (-> (-> a Bool) (Chan a) (Chan a))) + (All [a] (-> (-> a Bool) (Channel a) (Channel a))) (do &;Monad [?x+xs xs] (case ?x+xs @@ -39,16 +39,16 @@ (def: #export (write value target) {#;doc "Write to a channel, so long as it's still open."} - (All [a] (-> a (Chan a) (IO (Maybe (Chan a))))) + (All [a] (-> a (Channel a) (IO (Maybe (Channel a))))) (case (&;poll target) - (^template [ ] + (^template [ ] (do Monad - [#let [new-tail (chan ($ +0))] - done? (&;resolve (#;Some [value new-tail]) )] + [#let [new-tail (channel ($ +0))] + done? (&;resolve (#;Some [value new-tail]) )] (if done? (wrap (#;Some new-tail)) - (write value )))) + (write value )))) ([#;None target] [(#;Some (#;Some [_ target'])) target']) @@ -57,15 +57,15 @@ )) (def: #export (close target) - (All [a] (-> (Chan a) (IO Bool))) + (All [a] (-> (Channel a) (IO Bool))) (case (&;poll target) - (^template [ ] + (^template [ ] (do Monad - [done? (&;resolve #;None )] + [done? (&;resolve #;None )] (if done? (wrap true) - (close )))) + (close )))) ([#;None target] [(#;Some (#;Some [_ target'])) target']) @@ -74,7 +74,7 @@ )) (def: (pipe' input output) - (All [a] (-> (Chan a) (Chan a) (&;Promise Unit))) + (All [a] (-> (Channel a) (Channel a) (&;Promise Unit))) (do &;Monad [?x+xs input] (case ?x+xs @@ -88,7 +88,7 @@ (def: #export (pipe input output) {#;doc "Copy/pipe the contents of a channel on to another."} - (All [a] (-> (Chan a) (Chan a) (&;Promise Unit))) + (All [a] (-> (Channel a) (Channel a) (&;Promise Unit))) (do &;Monad [_ (pipe' input output)] (exec (io;run (close output)) @@ -96,8 +96,8 @@ (def: #export (merge xss) {#;doc "Fuse all the elements in a list of channels by piping them onto a new output channel."} - (All [a] (-> (List (Chan a)) (Chan a))) - (let [output (chan ($ +0))] + (All [a] (-> (List (Channel a)) (Channel a))) + (let [output (channel ($ +0))] (exec (do &;Monad [_ (mapM @ (function [input] (pipe' input output)) xss)] (exec (io;run (close output)) @@ -106,7 +106,7 @@ (def: #export (fold f init xs) {#;doc "Asynchronous fold over channels."} - (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (&;Promise a))) + (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (&;Promise a))) (do &;Monad [?x+xs xs] (case ?x+xs @@ -117,7 +117,7 @@ (def: #export (folds f init xs) {#;doc "A channel of folds."} - (All [a b] (-> (-> b a (&;Promise a)) a (Chan b) (Chan a))) + (All [a b] (-> (-> b a (&;Promise a)) a (Channel b) (Channel a))) (do &;Monad [?x+xs xs] (case ?x+xs @@ -127,7 +127,7 @@ (folds f init' xs'))))) (def: (distinct' eq last-one xs) - (All [a] (-> (Eq a) a (Chan a) (Chan a))) + (All [a] (-> (Eq a) a (Channel a) (Channel a))) (let [(^open) eq] (do &;Monad [?x+xs xs] @@ -139,7 +139,7 @@ (def: #export (distinct eq xs) {#;doc "Multiple consecutive equal values in the input channel will just be single value in the output channel."} - (All [a] (-> (Eq a) (Chan a) (Chan a))) + (All [a] (-> (Eq a) (Channel a) (Channel a))) (let [(^open) eq] (do &;Monad [?x+xs xs] @@ -149,7 +149,7 @@ (def: #export (consume xs) {#;doc "Reads the entirety of a channel's contents and returns them as a list."} - (All [a] (-> (Chan a) (&;Promise (List a)))) + (All [a] (-> (Channel a) (&;Promise (List a)))) (do &;Monad [?x+xs' xs] (case ?x+xs' @@ -162,13 +162,13 @@ (wrap (#;Cons x =xs)))))) (def: #export (once p) - (All [a] (-> (&;Promise a) (Chan a))) + (All [a] (-> (&;Promise a) (Channel a))) (do &;Monad [x p] (wrap (#;Some [x (wrap #;None)])))) (def: #export (poll time action) - (All [a] (-> Nat (IO (Maybe a)) (Chan a))) + (All [a] (-> Nat (IO (Maybe a)) (Channel a))) (do &;Monad [?output (&;future action)] (case ?output @@ -181,7 +181,7 @@ (wrap (#;Some [head (poll time action)])))))) (def: #export (periodic time value) - (All [a] (-> Nat a (Chan a))) + (All [a] (-> Nat a (Channel a))) (do &;Monad [] (wrap (#;Some [value (do @ @@ -189,7 +189,7 @@ (periodic time value))])))) (def: #export (sequential time xs) - (All [a] (-> Nat (List a) (Chan a))) + (All [a] (-> Nat (List a) (Channel a))) (do &;Monad [] (case xs @@ -202,7 +202,7 @@ (sequential time xs'))]))))) (def: #export (cycle time values) - (All [a] (-> Nat (List a) (Chan a))) + (All [a] (-> Nat (List a) (Channel a))) (do &;Monad [] (case values @@ -231,7 +231,7 @@ xs')) (def: #export (sliding-window max inputs) - (All [a] (-> Nat (Chan a) (Chan (List a)))) + (All [a] (-> Nat (Channel a) (Channel (List a)))) (let [(^open) &;Monad] (folds (function [input window] (let [window' (L/append window (list input))] @@ -242,7 +242,7 @@ inputs))) (def: #export (iterate f init) - (All [a] (-> (-> a (&;Promise (Maybe a))) a (Chan a))) + (All [a] (-> (-> a (&;Promise (Maybe a))) a (Channel a))) (do &;Monad [] (wrap (#;Some [init (do @ @@ -255,7 +255,7 @@ (iterate f init')))])))) (def: #export (sample time inputs) - (All [a] (-> Nat (Chan a) (Chan a))) + (All [a] (-> Nat (Channel a) (Channel a))) (do &;Monad [?h+t inputs] (case ?h+t @@ -276,7 +276,7 @@ (wrap (#;Some [value (sample time next-inputs)])))))) ## [Structures] -(struct: #export _ (Functor Chan) +(struct: #export _ (Functor Channel) (def: (map f xs) (:: &;Functor map (function [?x+xs] @@ -285,26 +285,26 @@ (#;Some [x xs']) (#;Some [(f x) (map f xs')]))) xs))) -(struct: #export _ (Applicative Chan) - (def: functor Functor) +(struct: #export _ (Applicative Channel) + (def: functor Functor) (def: (wrap a) (let [(^open) &;Monad] (wrap (#;Some [a (wrap #;None)])))) (def: (apply ff fa) - (let [fb (chan ($ +1))] - (exec (let [(^open) Functor] + (let [fb (channel ($ +1))] + (exec (let [(^open) Functor] (map (function [f] (pipe (map f fa) fb)) ff)) fb)))) -(struct: #export _ (Monad Chan) - (def: applicative Applicative) +(struct: #export _ (Monad Channel) + (def: applicative Applicative) (def: (join mma) - (let [output (chan ($ +0))] - (exec (let [(^open) Functor] + (let [output (channel ($ +0))] + (exec (let [(^open) Functor] (map (function [ma] (pipe ma output)) mma)) diff --git a/stdlib/source/lux/concurrency/stm.lux b/stdlib/source/lux/concurrency/stm.lux index ed9f28038..946f9bac4 100644 --- a/stdlib/source/lux/concurrency/stm.lux +++ b/stdlib/source/lux/concurrency/stm.lux @@ -127,20 +127,20 @@ (def: #export (follow target) {#;doc "Creates a channel that will receive all changes to the value of the given var."} - (All [a] (-> (Var a) (IO (frp;Chan a)))) - (let [head (frp;chan ($ +0)) - chan-var (var head) + (All [a] (-> (Var a) (IO (frp;Channel a)))) + (let [head (frp;channel ($ +0)) + channel-var (var head) observer (function [label value] - (case (io;run (|> chan-var raw-read (frp;write value))) + (case (io;run (|> channel-var raw-read (frp;write value))) #;None - ## By closing the output Chan, the + ## By closing the output Channel, the ## observer becomes obsolete. (atom;update (function [[value observers]] [value (dict;remove label observers)]) target) (#;Some tail') - (write! tail' chan-var)))] + (write! tail' channel-var)))] (do Monad [_ (atom;update (function [[value observers]] (let [label (Nat/encode (L/fold (function [key base] @@ -226,7 +226,7 @@ (atom false)) (def: (process-commit commits) - (-> (frp;Chan [(STM Unit) (P;Promise Unit)]) + (-> (frp;Channel [(STM Unit) (P;Promise Unit)]) (P;Promise Unit)) (do P;Monad [?head+tail commits] @@ -257,7 +257,7 @@ (if was-first? (do Monad [inputs (follow pending-commits)] - (exec (process-commit (:! (frp;Chan [(STM Unit) (P;Promise Unit)]) + (exec (process-commit (:! (frp;Channel [(STM Unit) (P;Promise Unit)]) inputs)) (wrap []))) (wrap []))) diff --git a/stdlib/test/test/lux/concurrency/frp.lux b/stdlib/test/test/lux/concurrency/frp.lux index 3447a55b2..302a59d06 100644 --- a/stdlib/test/test/lux/concurrency/frp.lux +++ b/stdlib/test/test/lux/concurrency/frp.lux @@ -9,19 +9,19 @@ lux/test) (def: (to-channel values) - (-> (List Int) (&;Chan Int)) - (let [_chan (&;chan Int)] + (-> (List Int) (&;Channel Int)) + (let [_channel (&;channel Int)] (io;run (do Monad - [_ (mapM @ (function [value] (&;write value _chan)) + [_ (mapM @ (function [value] (&;write value _channel)) values) - _ (&;close _chan)] - (wrap _chan))))) + _ (&;close _channel)] + (wrap _channel))))) (context: "FRP" ($_ seq (do P;Monad [elems (&;consume (to-channel (list 0 1 2 3 4 5)))] - (test "Can consume a chan into a list." + (test "Can consume a channel into a list." (case elems (^ (list 0 1 2 3 4 5)) true @@ -31,7 +31,7 @@ (do P;Monad [elems (&;consume (let [input (to-channel (list 0 1 2 3 4 5)) - output (&;chan Int)] + output (&;channel Int)] (exec (&;pipe input output) output)))] (test "Can pipe one channel into another." @@ -89,7 +89,7 @@ false))) (do P;Monad - [elems (&;consume (:: &;Functor map i.inc (to-channel (list 0 1 2 3 4 5))))] + [elems (&;consume (:: &;Functor map i.inc (to-channel (list 0 1 2 3 4 5))))] (test "Functor goes over every element in a channel." (case elems (^ (list 1 2 3 4 5 6)) @@ -99,7 +99,7 @@ false))) (do P;Monad - [elems (&;consume (let [(^open) &;Applicative] + [elems (&;consume (let [(^open) &;Applicative] (apply (wrap i.inc) (wrap 12345))))] (test "Applicative works over all channel values." (case elems @@ -110,7 +110,7 @@ false))) (do P;Monad - [elems (&;consume (do &;Monad + [elems (&;consume (do &;Monad [f (wrap i.inc) a (wrap 12345)] (wrap (f a))))] -- cgit v1.2.3