diff options
Diffstat (limited to 'stdlib/source/library/lux/control')
26 files changed, 176 insertions, 428 deletions
diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux index 2dbcfda97..03ae8afe6 100644 --- a/stdlib/source/library/lux/control/concatenative.lux +++ b/stdlib/source/library/lux/control/concatenative.lux @@ -26,7 +26,8 @@ ["<>" parser ("#\." monad) ["<.>" code (#+ Parser)]]]) -(type: Alias [Text Code]) +(type: Alias + [Text Code]) (type: Stack {#bottom (Maybe Nat) @@ -67,20 +68,11 @@ _ (meta.failure (format "Cannot expand to more than a single AST/Code node:" text.new_line - (|> expansion (list\map %.code) (text.join_with " "))))))) + (|> expansion (list\map %.code) (text.interposed " "))))))) (syntax: .public (=> [aliases aliases^ inputs stack^ outputs stack^]) - {#.doc (example "Concatenative function types." - (=> [Nat] [Nat]) - (All [a] (-> a (=> [] [a]))) - (All [t] (=> [t] [])) - (All [a b c] (=> [a b c] [b c a])) - (All [___a ___z] - (=> {then (=> ___a ___z) - else (=> ___a ___z)} - ___a [Bit then else] ___z)))} (let [de_alias (function (_ aliased) (list\fold (function (_ [from to] pre) (code.replaced (code.local_identifier from) to pre)) @@ -104,7 +96,9 @@ (-> (~ (de_alias inputC)) (~ (de_alias outputC)))))))))))) -(def: begin! Any []) +(def: begin! + Any + []) (def: end! (All [a] (-> [Any a] a)) @@ -112,13 +106,6 @@ top)) (syntax: .public (||> [commands (<>.some <code>.any)]) - {#.doc (example "A self-contained sequence of concatenative instructions." - (same? value - (||> (..push sample))) - - (||> (push 123) - dup - n/=))} (in (list (` (|> (~! ..begin!) (~+ commands) ((~! ..end!))))))) (def: word @@ -135,21 +122,12 @@ ))) (syntax: .public (word: [[export_policy name annotations type commands] ..word]) - {#.doc (example "A named concatenative function." - (word: square - (=> [Nat] [Nat]) - - dup - (apply/2 n.*)))} (in (list (` (def: (~ export_policy) (~ (code.local_identifier name)) (~ (|annotations|.format annotations)) (~ type) (|>> (~+ commands))))))) (syntax: .public (apply [arity (<>.only (n.> 0) <code>.nat)]) - {#.doc (example "A generator for functions that turn arity N functions into arity N concatenative functions." - (: (=> [Nat] [Nat]) - ((apply 1) inc)))} (with_identifiers [g! g!func g!stack g!output] (monad.do {! meta.monad} [g!inputs (|> (macro.identifier "input") (list.repeated arity) (monad.seq !))] @@ -161,80 +139,65 @@ [(~ g!stack) ((~ g!func) (~+ g!inputs))]))))))))) (template [<arity>] - [(with_expansions [<name> (template.identifier ["apply/" <arity>]) - <doc> (template.text ["Lift a function of arity " <arity> - " into a concatenative function of arity " <arity> "."])] - (def: .public <name> - {#.doc (example <doc>)} - (apply <arity>)))] + [(`` (def: .public (~~ (template.identifier ["apply/" <arity>])) + (..apply <arity>)))] [1] [2] [3] [4] [5] [6] [7] [8] ) (def: .public (push x) - {#.doc (example "Push a value onto the stack.")} (All [a] (-> a (=> [] [a]))) (function (_ stack) [stack x])) (def: .public drop - {#.doc (example "Drop/pop a value from the top of the stack.")} (All [t] (=> [t] [])) (function (_ [stack top]) stack)) (def: .public nip - {#.doc (example "Drop the second-to-last value from the top of the stack.")} (All [_ a] (=> [_ a] [a])) (function (_ [[stack _] top]) [stack top])) (def: .public dup - {#.doc (example "Duplicate the top of the stack.")} (All [a] (=> [a] [a a])) (function (_ [stack top]) [[stack top] top])) (def: .public swap - {#.doc (example "Swaps the 2 topmost stack values.")} (All [a b] (=> [a b] [b a])) (function (_ [[stack l] r]) [[stack r] l])) (def: .public rotL - {#.doc (example "Rotes the 3 topmost stack values to the left.")} (All [a b c] (=> [a b c] [b c a])) (function (_ [[[stack a] b] c]) [[[stack b] c] a])) (def: .public rotR - {#.doc (example "Rotes the 3 topmost stack values to the right.")} (All [a b c] (=> [a b c] [c a b])) (function (_ [[[stack a] b] c]) [[[stack c] a] b])) (def: .public && - {#.doc (example "Groups the 2 topmost stack values as a 2-tuple.")} (All [a b] (=> [a b] [(Tuple a b)])) (function (_ [[stack l] r]) [stack [l r]])) (def: .public ||L - {#.doc (example "Left-injects the top into sum.")} (All [a b] (=> [a] [(Or a b)])) (function (_ [stack l]) [stack (0 #0 l)])) (def: .public ||R - {#.doc (example "Right-injects the top into sum.")} (All [a b] (=> [b] [(Or a b)])) (function (_ [stack r]) [stack (0 #1 r)])) (template [<input> <output> <word> <func>] [(`` (def: .public <word> - {#.doc (example (~~ (template.text [<func> " for " <input> " arithmetic."])))} (=> [<input> <input>] [<output>]) (function (_ [[stack subject] param]) [stack (<func> param subject)])))] @@ -285,12 +248,6 @@ ) (def: .public if - {#.doc (example "If expression." - (same? "then" - (||> (push true) - (push "then") - (push "else") - if)))} (All [___a ___z] (=> {then (=> ___a ___z) else (=> ___a ___z)} @@ -301,7 +258,6 @@ (else stack)))) (def: .public call - {#.doc (example "Executes an anonymous block on the stack.")} (All [___a ___z] (=> {quote (=> ___a ___z)} ___a [quote] ___z)) @@ -309,7 +265,6 @@ (quote stack))) (def: .public loop - {#.doc (example "Executes a block as a loop until it yields #0 to stop.")} (All [___] (=> {test (=> ___ ___ [Bit])} ___ [test] ___)) @@ -320,7 +275,6 @@ stack')))) (def: .public dip - {#.doc (example "Executes a block on the stack, save for the topmost value.")} (All [___ a] (=> ___ [a (=> ___ ___)] ___ [a])) @@ -328,7 +282,6 @@ [(quote stack) a])) (def: .public dip/2 - {#.doc (example "Executes a block on the stack, save for the 2 topmost values.")} (All [___ a b] (=> ___ [a b (=> ___ ___)] ___ [a b])) @@ -336,12 +289,6 @@ [[(quote stack) a] b])) (def: .public do - {#.doc (example "Do-while loop expression." - (n.= (inc sample) - (||> (push sample) - (push (push false)) - (push (|>> (push 1) n/+)) - do while)))} (All [___a ___z] (=> {body (=> ___a ___z) pred (=> ___z ___a [Bit])} @@ -351,14 +298,6 @@ [[(body stack) pred] body])) (def: .public while - {#.doc (example "While loop expression." - (n.= (n.+ distance start) - (||> (push start) - (push (|>> dup - (push start) n/- - (push distance) n/<)) - (push (|>> (push 1) n/+)) - while)))} (All [___a ___z] (=> {body (=> ___z ___a) pred (=> ___a ___z [Bit])} @@ -371,13 +310,6 @@ stack')))) (def: .public compose - {#.doc (example "Function composition." - (n.= (n.+ 2 sample) - (||> (push sample) - (push (|>> (push 1) n/+)) - (push (|>> (push 1) n/+)) - compose - call)))} (All [___a ___ ___z] (=> [(=> ___a ___) (=> ___ ___z)] [(=> ___a ___z)])) @@ -385,13 +317,6 @@ [stack (|>> f g)])) (def: .public partial - {#.doc (example "Partial application." - (n.= (n.+ sample sample) - (||> (push sample) - (push sample) - (push n/+) - partial - call)))} (All [___a ___z a] (=> ___a [a (=> ___a [a] ___z)] ___a [(=> ___a ___z)])) @@ -399,7 +324,6 @@ [stack (|>> (push arg) quote)])) (word: .public when - {#.doc (example "Only execute the block when #1.")} (All [___] (=> {body (=> ___ ___)} ___ [Bit body] @@ -410,7 +334,6 @@ if) (word: .public ? - {#.doc (example "Choose the top value when #0 and the second-to-top when #1.")} (All [a] (=> [Bit a a] [a])) rotL diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux index 1557a9f89..e51be0b98 100644 --- a/stdlib/source/library/lux/control/concurrency/actor.lux +++ b/stdlib/source/library/lux/control/concurrency/actor.lux @@ -1,5 +1,4 @@ (.module: - {#.doc "The actor model of concurrency."} [library [lux #* ["." debug] @@ -64,27 +63,23 @@ (in #.End)))) (abstract: .public (Actor s) - {#.doc (example "An entity that can react to messages (mail) sent to it concurrently.")} + {} {#obituary [(Async <Obituary>) (Resolver <Obituary>)] #mailbox (Atom <Mailbox>)} (type: .public (Mail s) - {#.doc (example "A one-way message sent to an actor, without expecting a reply.")} <Mail>) (type: .public (Obituary s) - {#.doc (example "Details on the death of an actor.")} <Obituary>) (type: .public (Behavior o s) - {#.doc (example "An actor's behavior when mail is received and when a fatal error occurs.")} {#on_init (-> o s) #on_mail (-> (Mail s) s (Actor s) (Async (Try s)))}) (def: .public (spawn! behavior init) - {#.doc (example "Given a behavior and initial state, spawns an actor and returns it.")} (All [o s] (-> (Behavior o s) o (IO (Actor s)))) (io (let [[on_init on_mail] behavior self (:sharing [o s] @@ -130,14 +125,12 @@ (async.value obituary))) (def: .public obituary - {#.doc (example "Await for an actor to stop working.")} (All [s] (-> (Actor s) (Async (Obituary s)))) (|>> :representation (get@ #obituary) product.left)) (def: .public (mail! mail actor) - {#.doc (example "Send mail to an actor.")} (All [s] (-> (Mail s) (Actor s) (IO (Try Any)))) (do {! io.monad} [alive? (..alive? actor)] @@ -163,7 +156,6 @@ (in (exception.except ..dead []))))) (type: .public (Message s o) - {#.doc (example "A two-way message sent to an actor, expecting a reply.")} (-> s (Actor s) (Async (Try [s o])))) (def: (mail message) @@ -191,7 +183,6 @@ (async.resolved (#try.Failure error))))))])) (def: .public (tell! message actor) - {#.doc (example "Communicate with an actor through message-passing.")} (All [s o] (-> (Message s o) (Actor s) (Async (Try o)))) (let [[async mail] (..mail message)] (do async.monad @@ -210,14 +201,11 @@ (mail state self)) (def: .public default - {#.doc (example "Default actor behavior.")} (All [s] (Behavior s s)) {#on_init function.identity #on_mail ..default_on_mail}) (def: .public (poison! actor) - {#.doc (example "Kills the actor by sending mail that will kill it upon processing," - "but allows the actor to handle previous mail.")} (All [s] (-> (Actor s) (IO (Try Any)))) (..mail! (function (_ state self) (async.resolved (exception.except ..poisoned []))) @@ -270,151 +258,102 @@ (<>.and <code>.any private) (<>.and (<>\in (` .private)) private)))) -(with_expansions [<examples> (as_is (actor: .public (stack a) - {} - - (List a) - - ((on_mail mail state self) - (do (try.with async.monad) - [.let [_ (debug.log! "BEFORE")] - output (mail state self) - .let [_ (debug.log! "AFTER")]] - (in output))) - - (message: .public (push {value a} state self) - (List a) - (let [state' (#.Item value state)] - (async.resolved (#try.Success [state' state']))))) - - (actor: .public counter - {} - - Nat - - (message: .public (count! {increment Nat} state self) - Any - (let [state' (n.+ increment state)] - (async.resolved (#try.Success [state' state'])))) - - (message: .public (read! state self) - Nat - (async.resolved (#try.Success [state state])))))] - (syntax: .public (actor: [[export_policy [name vars] annotations state_type [?on_mail messages]] ..actorP]) - {#.doc (example "Defines a named actor, with its behavior and internal state." - "Messages for the actor must be defined after the on_mail handler." - <examples>)} - (with_identifiers [g!_] - (do meta.monad - [g!type (macro.identifier (format name "_abstract_type")) - .let [g!actor (code.local_identifier name) - g!vars (list\map code.local_identifier vars)]] - (in (list (` ((~! abstract:) (~ export_policy) ((~ g!type) (~+ g!vars)) - {} - - (~ state_type) - - (def: (~ export_policy) (~ g!actor) - (All [(~+ g!vars)] - (..Behavior (~ state_type) ((~ g!type) (~+ g!vars)))) - {#..on_init (|>> ((~! abstract.:abstraction) (~ g!type))) - #..on_mail (~ (..on_mail g!_ ?on_mail))}) - - (~+ messages)))))))) - - (syntax: .public (actor [[state_type init] (<code>.record (<>.and <code>.any <code>.any)) - [?on_mail messages] behavior^]) - {#.doc (example "Defines an anonymous actor, with its behavior and internal state." - "Messages for the actor must be defined after the on_mail handler." - (actor {Nat - 123} - ((on_mail message state self) - (message (inc state) self))))} - (with_identifiers [g!_] - (in (list (` (: ((~! io.IO) (..Actor (~ state_type))) - (..spawn! (: (..Behavior (~ state_type) (~ state_type)) - {#..on_init (|>>) - #..on_mail (~ (..on_mail g!_ ?on_mail))}) - (: (~ state_type) - (~ init))))))))) - - (type: Signature - {#vars (List Text) - #name Text - #inputs (List |input|.Input) - #state Text - #self Text}) - - (def: signature^ - (Parser Signature) - (<code>.form ($_ <>.and - (<>.else (list) (<code>.tuple (<>.some <code>.local_identifier))) - <code>.local_identifier - (<>.some |input|.parser) - <code>.local_identifier - <code>.local_identifier))) - - (def: reference^ - (Parser [Name (List Text)]) - (<>.either (<code>.form (<>.and <code>.identifier (<>.some <code>.local_identifier))) - (<>.and <code>.identifier (\ <>.monad in (list))))) - - (def: messageP - (Parser [Code Signature |annotations|.Annotations Code Code]) - (let [private ($_ <>.and - ..signature^ - (<>.else |annotations|.empty |annotations|.parser) - <code>.any - <code>.any)] - ($_ <>.either - (<>.and <code>.any private) - (<>.and (<>\in (` .private)) private)))) - - (syntax: .public (message: [[export_policy signature annotations output_type body] ..messageP]) - {#.doc (example "A message can access the actor's state through the state parameter." - "A message can also access the actor itself through the self parameter." - "A message's output must be an async containing a 2-tuple with the updated state and a return value." - "A message may succeed or fail (in case of failure, the actor dies)." - - <examples>)} - (with_identifiers [g!_ g!return] - (do meta.monad - [actor_scope abstract.current - .let [g!type (code.local_identifier (get@ #abstract.name actor_scope)) - g!message (code.local_identifier (get@ #name signature)) - g!actor_vars (get@ #abstract.type_vars actor_scope) - g!all_vars (|> signature (get@ #vars) (list\map code.local_identifier) (list\compose g!actor_vars)) - g!inputsC (|> signature (get@ #inputs) (list\map product.left)) - g!inputsT (|> signature (get@ #inputs) (list\map product.right)) - g!state (|> signature (get@ #state) code.local_identifier) - g!self (|> signature (get@ #self) code.local_identifier)]] - (in (list (` (def: (~ export_policy) ((~ g!message) (~+ g!inputsC)) - (~ (|annotations|.format annotations)) - (All [(~+ g!all_vars)] - (-> (~+ g!inputsT) - (..Message (~ (get@ #abstract.abstraction actor_scope)) - (~ output_type)))) - (function ((~ g!_) (~ g!state) (~ g!self)) - (let [(~ g!state) (:as (~ (get@ #abstract.representation actor_scope)) - (~ g!state))] - (|> (~ body) - (: ((~! async.Async) ((~! try.Try) [(~ (get@ #abstract.representation actor_scope)) - (~ output_type)]))) - (:as ((~! async.Async) ((~! try.Try) [(~ (get@ #abstract.abstraction actor_scope)) - (~ output_type)])))))))) - )))))) +(syntax: .public (actor: [[export_policy [name vars] annotations state_type [?on_mail messages]] ..actorP]) + (with_identifiers [g!_] + (do meta.monad + [g!type (macro.identifier (format name "_abstract_type")) + .let [g!actor (code.local_identifier name) + g!vars (list\map code.local_identifier vars)]] + (in (list (` ((~! abstract:) (~ export_policy) ((~ g!type) (~+ g!vars)) + {} + + (~ state_type) + + (def: (~ export_policy) (~ g!actor) + (All [(~+ g!vars)] + (..Behavior (~ state_type) ((~ g!type) (~+ g!vars)))) + {#..on_init (|>> ((~! abstract.:abstraction) (~ g!type))) + #..on_mail (~ (..on_mail g!_ ?on_mail))}) + + (~+ messages)))))))) + +(syntax: .public (actor [[state_type init] (<code>.record (<>.and <code>.any <code>.any)) + [?on_mail messages] behavior^]) + (with_identifiers [g!_] + (in (list (` (: ((~! io.IO) (..Actor (~ state_type))) + (..spawn! (: (..Behavior (~ state_type) (~ state_type)) + {#..on_init (|>>) + #..on_mail (~ (..on_mail g!_ ?on_mail))}) + (: (~ state_type) + (~ init))))))))) + +(type: Signature + {#vars (List Text) + #name Text + #inputs (List |input|.Input) + #state Text + #self Text}) + +(def: signature^ + (Parser Signature) + (<code>.form ($_ <>.and + (<>.else (list) (<code>.tuple (<>.some <code>.local_identifier))) + <code>.local_identifier + (<>.some |input|.parser) + <code>.local_identifier + <code>.local_identifier))) + +(def: reference^ + (Parser [Name (List Text)]) + (<>.either (<code>.form (<>.and <code>.identifier (<>.some <code>.local_identifier))) + (<>.and <code>.identifier (\ <>.monad in (list))))) + +(def: messageP + (Parser [Code Signature |annotations|.Annotations Code Code]) + (let [private ($_ <>.and + ..signature^ + (<>.else |annotations|.empty |annotations|.parser) + <code>.any + <code>.any)] + ($_ <>.either + (<>.and <code>.any private) + (<>.and (<>\in (` .private)) private)))) + +(syntax: .public (message: [[export_policy signature annotations output_type body] ..messageP]) + (with_identifiers [g!_ g!return] + (do meta.monad + [actor_scope abstract.current + .let [g!type (code.local_identifier (get@ #abstract.name actor_scope)) + g!message (code.local_identifier (get@ #name signature)) + g!actor_vars (get@ #abstract.type_vars actor_scope) + g!all_vars (|> signature (get@ #vars) (list\map code.local_identifier) (list\compose g!actor_vars)) + g!inputsC (|> signature (get@ #inputs) (list\map product.left)) + g!inputsT (|> signature (get@ #inputs) (list\map product.right)) + g!state (|> signature (get@ #state) code.local_identifier) + g!self (|> signature (get@ #self) code.local_identifier)]] + (in (list (` (def: (~ export_policy) ((~ g!message) (~+ g!inputsC)) + (~ (|annotations|.format annotations)) + (All [(~+ g!all_vars)] + (-> (~+ g!inputsT) + (..Message (~ (get@ #abstract.abstraction actor_scope)) + (~ output_type)))) + (function ((~ g!_) (~ g!state) (~ g!self)) + (let [(~ g!state) (:as (~ (get@ #abstract.representation actor_scope)) + (~ g!state))] + (|> (~ body) + (: ((~! async.Async) ((~! try.Try) [(~ (get@ #abstract.representation actor_scope)) + (~ output_type)]))) + (:as ((~! async.Async) ((~! try.Try) [(~ (get@ #abstract.abstraction actor_scope)) + (~ output_type)])))))))) + ))))) (type: .public Stop - {#.doc (example "A signal to stop an actor from observing a channel.")} (IO Any)) (def: continue! true) (def: stop! false) (def: .public (observe! action channel actor) - {#.doc (example "Use an actor to observe a channel by transforming each datum" - "flowing through the channel into mail the actor can process." - "Can stop observing the channel by executing the Stop value.")} (All [e s] (-> (-> e Stop (Mail s)) (Channel e) (Actor s) (IO Any))) (let [signal (: (Atom Bit) (atom.atom ..continue!)) diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index 32f1913b6..3dcb864b6 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -18,13 +18,11 @@ ["." atom (#+ Atom atom)]]) (abstract: .public (Async a) - {#.doc "Represents values produced by asynchronous computations (unlike IO, which is synchronous)."} + {} (Atom [(Maybe a) (List (-> a (IO Any)))]) (type: .public (Resolver a) - {#.doc (example "The function used to give a value to an async." - "Will signal 'true' if the async has been resolved for the 1st time, 'false' otherwise.")} (-> a (IO Bit))) (def: (resolver async) @@ -50,25 +48,21 @@ (resolve value)))))))) (def: .public (resolved value) - {#.doc (example "Produces an async that has already been resolved to the given value.")} (All [a] (-> a (Async a))) (:abstraction (atom [(#.Some value) (list)]))) (def: .public (async _) - {#.doc (example "Creates a fresh async that has not been resolved yet.")} (All [a] (-> Any [(Async a) (Resolver a)])) (let [async (:abstraction (atom [#.None (list)]))] [async (..resolver async)])) (def: .public value - {#.doc "Polls an async for its value."} (All [a] (-> (Async a) (IO (Maybe a)))) (|>> :representation atom.read! (\ io.functor map product.left))) (def: .public (upon! f async) - {#.doc (example "Executes the given function as soon as the async has been resolved.")} (All [a] (-> (-> a (IO Any)) (Async a) (IO Any))) (do {! io.monad} [.let [async (:representation async)] @@ -87,7 +81,6 @@ ) (def: .public resolved? - {#.doc "Checks whether an async's value has already been resolved."} (All [a] (-> (Async a) (IO Bit))) (|>> ..value (\ io.functor map @@ -133,7 +126,6 @@ ma)))) (def: .public (and left right) - {#.doc (example "Combines the results of both asyncs, in-order.")} (All [a b] (-> (Async a) (Async b) (Async [a b]))) (let [[read! write!] (:sharing [a b] [(Async a) (Async b)] @@ -150,8 +142,6 @@ read!)) (def: .public (or left right) - {#.doc (example "Yields the results of whichever async gets resolved first." - "You can tell which one was resolved first through pattern-matching.")} (All [a b] (-> (Async a) (Async b) (Async (Or a b)))) (let [[a|b resolve] (..async [])] (with_expansions @@ -166,8 +156,6 @@ a|b)))) (def: .public (either left right) - {#.doc (example "Yields the results of whichever async gets resolved first." - "You cannot tell which one was resolved first.")} (All [a] (-> (Async a) (Async a) (Async a))) (let [[left||right resolve] (..async [])] (`` (exec @@ -179,8 +167,6 @@ left||right)))) (def: .public (schedule! milli_seconds computation) - {#.doc (example "Runs an I/O computation on its own thread (after a specified delay)." - "Returns an async that will eventually host its result.")} (All [a] (-> Nat (IO a) (Async a))) (let [[!out resolve] (..async [])] (exec @@ -192,22 +178,17 @@ !out))) (def: .public future - {#.doc (example "Runs an I/O computation on its own thread." - "Returns an async that will eventually host its result.")} (All [a] (-> (IO a) (Async a))) (..schedule! 0)) (def: .public (delayed milli_seconds value) - {#.doc "Delivers a value after a certain period has passed."} (All [a] (-> Nat a (Async a))) (..schedule! milli_seconds (io value))) (def: .public (delay milli_seconds) - {#.doc "An async that will be resolved after the specified amount of milli-seconds."} (-> Nat (Async Any)) (..delayed milli_seconds [])) (def: .public (time_out milli_seconds async) - {#.doc "Wait for an async to be resolved within the specified amount of milli-seconds."} (All [a] (-> Nat (Async a) (Async (Maybe a)))) (..or (..delay milli_seconds) async)) diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 07e2640f8..b6d9461f0 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -47,7 +47,7 @@ @.scheme "scheme array read"} (as_is))] (abstract: .public (Atom a) - {#.doc "Atomic references that are safe to mutate concurrently."} + {} (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference a)] (for {@.old <jvm> @@ -69,8 +69,6 @@ (<read> 0 (:representation atom)))))) (def: .public (compare_and_swap! current new atom) - {#.doc (example "Only mutates an atom if you can present its current value." - "That guarantees that atom was not updated since you last read from it.")} (All [a] (-> a a (Atom a) (IO Bit))) (io.io (with_expansions [<jvm> (java/util/concurrent/atomic/AtomicReference::compareAndSet current new (:representation atom))] (for {@.old <jvm> @@ -83,9 +81,6 @@ )) (def: .public (update! f atom) - {#.doc (example "Updates an atom by applying a function to its current value." - "If it fails to update it (because some other process wrote to it first), it will retry until it succeeds." - "The retries will be done with the new values of the atom, as they show up.")} (All [a] (-> (-> a a) (Atom a) (IO [a a]))) (loop [_ []] (do io.monad @@ -97,8 +92,6 @@ (recur []))))) (def: .public (write! value atom) - {#.doc (example "Writes the given value to an atom." - "If it fails to write it (because some other process wrote to it first), it will retry until it succeeds.")} (All [a] (-> a (Atom a) (IO a))) (|> atom (..update! (function.constant value)) diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux index 676aa0b8a..e14fb6505 100644 --- a/stdlib/source/library/lux/control/concurrency/frp.lux +++ b/stdlib/source/library/lux/control/concurrency/frp.lux @@ -18,13 +18,11 @@ ["." async (#+ Async) ("#\." functor)]]) (type: .public (Channel a) - {#.doc "An asynchronous channel to distribute values."} (Async (Maybe [a (Channel a)]))) (exception: .public channel_is_already_closed) (interface: .public (Sink a) - {#.doc (example "The tail-end of a channel, which can be written-to to fee the channel.")} (: (IO (Try Any)) close) (: (-> a (IO (Try Any))) @@ -80,7 +78,6 @@ (recur [])))))))))) (def: .public (channel _) - {#.doc (example "Creates a brand-new channel and hands it over, along with the sink to write to it.")} (All [a] (-> Any [(Channel a) (Sink a)])) (let [[async resolve] (async.async [])] [async (..sink resolve)])) @@ -150,7 +147,6 @@ output)))) (type: .public (Subscriber a) - {#.doc (example "A function that can receive every value fed into a channel.")} (-> a (IO (Maybe Any)))) (def: .public (subscribe! subscriber channel) @@ -174,8 +170,6 @@ []))) (def: .public (only pass? channel) - {#.doc (example "Produces a new channel based on the old one, only with values" - "that pass the test.")} (All [a] (-> (-> a Bit) (Channel a) (Channel a))) (do async.monad [item channel] @@ -190,14 +184,12 @@ (in #.None)))) (def: .public (of_async async) - {#.doc (example "A one-element channel containing the output from an async.")} (All [a] (-> (Async a) (Channel a))) (async\map (function (_ value) (#.Some [value ..empty])) async)) (def: .public (fold f init channel) - {#.doc "Asynchronous fold over channels."} (All [a b] (-> (-> b a (Async a)) a (Channel b) (Async a))) @@ -291,7 +283,6 @@ (in #.End)))) (def: .public (sequential milli_seconds values) - {#.doc (example "Transforms the given list into a channel with the same elements.")} (All [a] (-> Nat (List a) (Channel a))) (case values #.End diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux index f7f4f5f50..c266617a5 100644 --- a/stdlib/source/library/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux @@ -30,7 +30,7 @@ #waiting_list (Queue (Resolver Any))}) (abstract: .public Semaphore - {#.doc "A tool for controlling access to resources by multiple concurrent processes."} + {} (Atom State) @@ -46,25 +46,24 @@ #waiting_list queue.empty})))) (def: .public (wait! semaphore) - {#.doc (example "Wait on a semaphore until there are open positions." - "After finishing your work, you must 'signal' to the semaphore that you're done.")} (Ex [k] (-> Semaphore (Async Any))) (let [semaphore (:representation semaphore) [signal sink] (: [(Async Any) (Resolver Any)] (async.async []))] - (exec (io.run! - (with_expansions [<had_open_position?> (as_is (get@ #open_positions) (i.> -1))] - (do io.monad - [[_ state'] (atom.update! (|>> (update@ #open_positions dec) - (if> [<had_open_position?>] - [] - [(update@ #waiting_list (queue.end sink))])) - semaphore)] - (with_expansions [<go_ahead> (sink []) - <get_in_line> (in false)] - (if (|> state' <had_open_position?>) - <go_ahead> - <get_in_line>))))) + (exec + (io.run! + (with_expansions [<had_open_position?> (as_is (get@ #open_positions) (i.> -1))] + (do io.monad + [[_ state'] (atom.update! (|>> (update@ #open_positions dec) + (if> [<had_open_position?>] + [] + [(update@ #waiting_list (queue.end sink))])) + semaphore)] + (with_expansions [<go_ahead> (sink []) + <get_in_line> (in false)] + (if (|> state' <had_open_position?>) + <go_ahead> + <get_in_line>))))) signal))) (exception: .public (semaphore_is_maxed_out {max_positions Nat}) @@ -72,7 +71,6 @@ ["Max Positions" (%.nat max_positions)])) (def: .public (signal! semaphore) - {#.doc (example "Signal to a semaphore that you're done with your work, and that there is a new open position.")} (Ex [k] (-> Semaphore (Async (Try Int)))) (let [semaphore (:representation semaphore)] (async.future @@ -98,12 +96,11 @@ ) (abstract: .public Mutex - {#.doc "A mutual-exclusion lock that can only be acquired by one process at a time."} + {} Semaphore (def: .public (mutex _) - {#.doc (example "Creates a brand-new mutex.")} (-> Any Mutex) (:abstraction (semaphore 1))) @@ -116,7 +113,6 @@ (|>> :representation ..signal!)) (def: .public (synchronize! mutex procedure) - {#.doc (example "Runs the procedure with exclusive control of the mutex.")} (All [a] (-> Mutex (IO (Async a)) (Async a))) (do async.monad [_ (..acquire! mutex) @@ -126,15 +122,13 @@ ) (def: .public limit - {#.doc (example "Produce a limit for a barrier.")} (refinement.refiner (n.> 0))) (type: .public Limit - {#.doc (example "A limit for barriers.")} (:~ (refinement.type limit))) (abstract: .public Barrier - {#.doc "A barrier that blocks all processes from proceeding until a given number of processes are parked at the barrier."} + {} {#limit Limit #count (Atom Nat) @@ -174,7 +168,6 @@ ) (def: .public (block! barrier) - {#.doc (example "Wait on a barrier until all processes have arrived and met the barrier's limit.")} (-> Barrier (Async Any)) (do async.monad [_ (..start! barrier)] diff --git a/stdlib/source/library/lux/control/concurrency/stm.lux b/stdlib/source/library/lux/control/concurrency/stm.lux index f3bdbcbb6..a41d12aba 100644 --- a/stdlib/source/library/lux/control/concurrency/stm.lux +++ b/stdlib/source/library/lux/control/concurrency/stm.lux @@ -24,12 +24,11 @@ (-> a (IO Any))) (abstract: .public (Var a) - {#.doc "A mutable cell containing a value, and observers that will be alerted of any change to it."} + {} (Atom [a (List (Sink a))]) (def: .public (var value) - {#.doc "Creates a new STM var, with a default value."} (All [a] (-> a (Var a))) (:abstraction (atom.atom [value (list)]))) @@ -67,7 +66,6 @@ (write! new_value var)))) (def: .public (follow! target) - {#.doc "Creates a channel that will receive all changes to the value of the given var."} (All [a] (-> (Var a) (IO [(Channel a) (Sink a)]))) (do io.monad [.let [[channel sink] (frp.channel [])] @@ -86,7 +84,6 @@ (List (Ex [a] (Tx_Frame a)))) (type: .public (STM a) - {#.doc "A computation which updates a transaction and produces a value."} (-> Tx [Tx a])) (def: (var_value var tx) @@ -175,7 +172,6 @@ (ma tx'))))) (def: .public (update f var) - {#.doc "Update a var's value, and return a tuple with the old and the new values."} (All [a] (-> (-> a a) (Var a) (STM [a a]))) (do ..monad [a (..read var) @@ -261,9 +257,6 @@ ))) (def: .public (commit! stm_proc) - {#.doc (example "Commits a transaction and returns its result (asynchronously)." - "Note that a transaction may be re-run an indeterminate number of times if other transactions involving the same variables successfully commit first." - "For this reason, it's important to note that transactions must be free from side-effects, such as I/O.")} (All [a] (-> (STM a) (Async a))) (let [[output resolver] (async.async [])] (exec diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index 6d47059b0..e067d1ac5 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -65,7 +65,6 @@ )) (def: .public parallelism - {#.doc (example "How many processes can run in parallel.")} Nat (with_expansions [<jvm> (|> (java/lang/Runtime::getRuntime) (java/lang/Runtime::availableProcessors) @@ -102,7 +101,6 @@ [])) (def: .public (schedule! milli_seconds action) - {#.doc (example "Executes an I/O procedure after some milli-seconds.")} (-> Nat (IO Any) (IO Any)) (with_expansions [<jvm> (as_is (let [runnable (ffi.object [] [java/lang/Runnable] [] diff --git a/stdlib/source/library/lux/control/continuation.lux b/stdlib/source/library/lux/control/continuation.lux index e9b702f55..9a65c9d3e 100644 --- a/stdlib/source/library/lux/control/continuation.lux +++ b/stdlib/source/library/lux/control/continuation.lux @@ -14,21 +14,17 @@ ["." code]]]]) (type: .public (Cont i o) - {#.doc "Continuations."} (-> (-> i o) o)) -(def: .public (continue next cont) - {#.doc "Continues a continuation thunk."} +(def: .public (continued next cont) (All [i o] (-> (-> i o) (Cont i o) o)) (cont next)) -(def: .public (result cont) - {#.doc "Forces a continuation thunk to be evaluated."} +(def: .public result (All [a] (-> (Cont a a) a)) - (cont function.identity)) + (..continued function.identity)) -(def: .public (call/cc f) - {#.doc "Call with current continuation."} +(def: .public (with_current f) (All [a b z] (-> (-> (-> a (Cont b z)) (Cont a z)) @@ -38,8 +34,6 @@ k))) (syntax: .public (pending [expr <code>.any]) - {#.doc (example "Turns any expression into a function that is pending a continuation." - (pending (some_function some_input)))} (with_identifiers [g!_ g!k] (in (list (` (.function ((~ g!_) (~ g!k)) ((~ g!k) (~ expr)))))))) @@ -61,7 +55,8 @@ (All [o] (Functor (All [i] (Cont i o)))) (def: (map f fv) - (function (_ k) (fv (function.compose k f))))) + (function (_ k) + (fv (function.composite k f))))) (implementation: .public apply (All [o] (Apply (All [i] (Cont i o)))) @@ -84,7 +79,7 @@ (def: (join ffa) (function (_ k) - (ffa (continue k))))) + (ffa (continued k))))) (def: .public (portal init) (All [i o z] @@ -92,9 +87,10 @@ (Cont [(-> i (Cont o z)) i] z))) - (call/cc (function (_ k) - (do ..monad - [.let [nexus (function (nexus val) - (k [nexus val]))] - _ (k [nexus init])] - (in (undefined)))))) + (with_current + (function (_ k) + (do ..monad + [.let [nexus (function (nexus val) + (k [nexus val]))] + _ (k [nexus init])] + (in (undefined)))))) diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 9a9e7f845..f89611e19 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -28,18 +28,14 @@ ["//" try (#+ Try)]]) (type: .public (Exception a) - {#.doc "An exception provides a way to decorate error messages."} {#label Text #constructor (-> a Text)}) (def: .public (match? exception error) - {#.doc (example "Is this exception the cause of the error message?")} (All [e] (-> (Exception e) Text Bit)) (text.starts_with? (get@ #label exception) error)) (def: .public (when exception then try) - {#.doc (example "If a particular exception is detected on a possibly-erroneous value, handle it." - "If no exception was detected, or a different one from the one being checked, then pass along the original value.")} (All [e a] (-> (Exception e) (-> Text a) (Try a) (Try a))) @@ -52,12 +48,11 @@ (if (text.starts_with? reference error) (#//.Success (|> error (text.clip' (text.size reference)) - maybe.assume + maybe.trusted then)) (#//.Failure error))))) (def: .public (otherwise else try) - {#.doc "If no handler could be found to catch the exception, then run a function as a last-resort measure."} (All [a] (-> (-> Text a) (Try a) a)) (case try @@ -68,12 +63,10 @@ (else error))) (def: .public (error exception message) - {#.doc "Constructs an error message from an exception."} (All [e] (-> (Exception e) e Text)) ((get@ #..constructor exception) message)) (def: .public (except exception message) - {#.doc "Decorate an error message with an Exception and lift it into the error-handling context."} (All [e a] (-> (Exception e) e (Try a))) (#//.Failure (..error exception message))) @@ -98,15 +91,9 @@ ))) (syntax: .public (exception: [[export_policy t_vars [name inputs] body] ..exception]) - {#.doc (example "Define a new exception type." - "It mostly just serves as a way to tag error messages for later catching." + {#.doc (example "" - "Simple case:" - (exception: .public some_exception) - "" - "Complex case:" - (exception: .public [arbitrary type variables] (some_exception {optional Text} {arguments Int}) - optional_body))} + )} (macro.with_identifiers [g!descriptor] (do meta.monad [current_module meta.current_module_name @@ -132,14 +119,14 @@ on_new_line (|> " " (list.repeated (n.+ (text.size header_separator) largest_header_size)) - (text.join_with "") + text.joined (text\compose text.new_line)) on_entry (: (-> [Text Text] Text) (function (_ [header message]) (let [padding (|> " " (list.repeated (n.- (text.size header) largest_header_size)) - (text.join_with ""))] + text.joined)] (|> message (text.replaced text.new_line on_new_line) ($_ text\compose padding header header_separator)))))] @@ -154,19 +141,11 @@ tail)))) (syntax: .public (report [entries (<>.many (<code>.tuple (<>.and <code>.any <code>.any)))]) - {#.doc (example "An error report." - (: Text - (report ["Row 0" value/0] - ["Row 1" value/1] - ,,, - ["Row N" value/N])))} (in (list (` ((~! report') (list (~+ (|> entries (list\map (function (_ [header message]) (` [(~ header) (~ message)]))))))))))) (def: .public (listing format entries) - {#.doc (example "A numbered report of the entries on a list." - "NOTE: 0-based numbering.")} (All [a] (-> (-> a Text) (List a) Text)) (|> entries @@ -181,7 +160,7 @@ (def: separator (let [gap ($_ "lux text concat" text.new_line text.new_line) - horizontal_line (|> "-" (list.repeated 64) (text.join_with ""))] + horizontal_line (|> "-" (list.repeated 64) text.joined)] ($_ "lux text concat" gap horizontal_line @@ -195,7 +174,6 @@ error)) (def: .public (with exception message computation) - {#.doc (example "If a computation fails, prepends the exception to the error.")} (All [e a] (-> (Exception e) e (Try a) (Try a))) (case computation (#//.Failure error) diff --git a/stdlib/source/library/lux/control/function.lux b/stdlib/source/library/lux/control/function.lux index d0bc286ae..865ea6930 100644 --- a/stdlib/source/library/lux/control/function.lux +++ b/stdlib/source/library/lux/control/function.lux @@ -5,38 +5,24 @@ [monoid (#+ Monoid)]]]]) (def: .public identity - {#.doc (example "Identity function." - "Does nothing to its argument and just returns it." - (same? (identity value) - value))} (All [a] (-> a a)) (|>>)) -(def: .public (compose f g) - {#.doc (example "Function composition." - (= ((compose f g) "foo") - (f (g "foo"))))} +(def: .public (composite f g) (All [a b c] (-> (-> b c) (-> a b) (-> a c))) (|>> g f)) (def: .public (constant value) - {#.doc (example "Create constant functions." - (= ((constant "foo") "bar") - "foo"))} (All [o] (-> o (All [i] (-> i o)))) (function (_ _) value)) (def: .public (flipped f) - {#.doc (example "Flips the order of the arguments of a function." - (= ((flipped f) "foo" "bar") - (f "bar" "foo")))} (All [a b c] (-> (-> a b c) (-> b a c))) (function (_ x y) (f y x))) (def: .public (apply input function) - {#.doc (example "Simple 1-argument function application.")} (All [i o] (-> i (-> i o) o)) (function input)) @@ -45,4 +31,4 @@ (All [a] (Monoid (-> a a))) (def: identity ..identity) - (def: compose ..compose)) + (def: compose ..composite)) diff --git a/stdlib/source/library/lux/control/io.lux b/stdlib/source/library/lux/control/io.lux index 321b7159e..1b3b58f7b 100644 --- a/stdlib/source/library/lux/control/io.lux +++ b/stdlib/source/library/lux/control/io.lux @@ -16,7 +16,7 @@ ["." template]]]]) (abstract: .public (IO a) - {#.doc "A type that represents synchronous, effectful computations that may interact with the outside world."} + {} (-> Any a) @@ -34,17 +34,11 @@ [((:representation io) [])]) (syntax: .public (io [computation <code>.any]) - {#.doc (example "Delays the evaluation of an expression, by wrapping it in an IO 'thunk'." - "Great for wrapping effectful computations (which will not be performed until the IO is 'run!')." - (io (exec - (log! msg) - "Some value...")))} (with_identifiers [g!func g!arg] (in (list (` ((~! ..label) (function ((~ g!func) (~ g!arg)) (~ computation)))))))) (def: .public run! - {#.doc "A way to execute IO computations and perform their side-effects."} (All [a] (-> (IO a) a)) (|>> run!')) diff --git a/stdlib/source/library/lux/control/lazy.lux b/stdlib/source/library/lux/control/lazy.lux index dec12c5f5..46901a3c1 100644 --- a/stdlib/source/library/lux/control/lazy.lux +++ b/stdlib/source/library/lux/control/lazy.lux @@ -18,8 +18,7 @@ abstract]]]) (abstract: .public (Lazy a) - {#.doc (example "A value specified by an expression that is calculated only at the last moment possible." - "Afterwards, the value is cached for future reference.")} + {} (-> [] a) @@ -42,7 +41,6 @@ ((:representation lazy) []))) (syntax: .public (lazy [expression <code>.any]) - {#.doc (example "Specifies a lazy value by providing the expression that computes it.")} (with_identifiers [g!_] (in (list (` ((~! lazy') (function ((~ g!_) (~ g!_)) (~ expression)))))))) diff --git a/stdlib/source/library/lux/control/maybe.lux b/stdlib/source/library/lux/control/maybe.lux index 2d9b56039..74b5f06d2 100644 --- a/stdlib/source/library/lux/control/maybe.lux +++ b/stdlib/source/library/lux/control/maybe.lux @@ -96,7 +96,8 @@ (implementation: .public (with monad) (All [M] (-> (Monad M) (Monad (All [a] (M (Maybe a)))))) - (def: &functor (functor.compose (get@ #monad.&functor monad) ..functor)) + (def: &functor + (functor.composite (get@ #monad.&functor monad) ..functor)) (def: in (|>> (\ ..monad in) (\ monad in))) @@ -110,22 +111,11 @@ (#.Some Mma) Mma)))) -(def: .public (lift monad) - {#.doc (example "Wraps a monadic value with Maybe machinery.")} +(def: .public (lifted monad) (All [M a] (-> (Monad M) (-> (M a) (M (Maybe a))))) (\ monad map (\ ..monad in))) (macro: .public (else tokens state) - {#.doc (example "Allows you to provide a default value that will be used" - "if a (Maybe x) value turns out to be #.None." - "Note: the expression for the default value will not be computed if the base computation succeeds." - (else +20 (#.Some +10)) - "=>" - +10 - -------------------------- - (else +20 #.None) - "=>" - +20)} (case tokens (^ (.list else maybe)) (let [g!temp (: Code [location.dummy (#.Identifier ["" ""])])] @@ -139,10 +129,7 @@ _ (#.Left "Wrong syntax for else"))) -(def: .public assume - {#.doc (example "Assumes that a Maybe value is a #.Some and yields its value." - "Raises/throws a runtime error otherwise." - "WARNING: Use with caution.")} +(def: .public trusted (All [a] (-> (Maybe a) a)) (|>> (..else (undefined)))) @@ -156,11 +143,6 @@ (#.Item value #.End))) (macro: .public (when tokens state) - {#.doc (example "Can be used as a guard in (co)monadic be/do expressions." - (do monad - [value (do_something 1 2 3) - ..when (passes_test? value)] - (do_something_else 4 5 6)))} (case tokens (^ (.list test then)) (#.Right [state (.list (` (.if (~ test) diff --git a/stdlib/source/library/lux/control/parser.lux b/stdlib/source/library/lux/control/parser.lux index 4c86373f5..f4e304045 100644 --- a/stdlib/source/library/lux/control/parser.lux +++ b/stdlib/source/library/lux/control/parser.lux @@ -230,7 +230,7 @@ (function (_ input) (#try.Failure message))) -(def: .public (lift operation) +(def: .public (lifted operation) {#.doc (example "Lift a potentially failed computation into a parser.")} (All [s a] (-> (Try a) (Parser s a))) (function (_ input) diff --git a/stdlib/source/library/lux/control/parser/analysis.lux b/stdlib/source/library/lux/control/parser/analysis.lux index 94e7ca9c1..fb32f4608 100644 --- a/stdlib/source/library/lux/control/parser/analysis.lux +++ b/stdlib/source/library/lux/control/parser/analysis.lux @@ -37,8 +37,7 @@ (format text.new_line "Remaining input: " (|> asts (list\map /.%analysis) - (list.interposed " ") - (text.join_with "")))) + (text.interposed " ")))) (exception: .public (cannot_parse {input (List Analysis)}) (exception.report diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux index 7cf526d41..d2d195888 100644 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ b/stdlib/source/library/lux/control/parser/binary.lux @@ -121,7 +121,7 @@ (^template [<number> <tag> <parser>] [<number> (\ ! map (|>> <tag>) <parser>)]) ((~~ (template.spliced <case>+))) - _ (//.lift (exception.except ..invalid_tag [(~~ (template.amount <case>+)) flag])))))]) + _ (//.lifted (exception.except ..invalid_tag [(~~ (template.amount <case>+)) flag])))))]) (def: .public (or left right) (All [l r] (-> (Parser l) (Parser r) (Parser (Or l r)))) @@ -153,7 +153,7 @@ (case value 0 (in #0) 1 (in #1) - _ (//.lift (exception.except ..not_a_bit [value]))))) + _ (//.lifted (exception.except ..not_a_bit [value]))))) (def: .public (segment size) {#.doc (example "Parses a chunk of data of a given size.")} @@ -185,7 +185,7 @@ (Parser Text) (do //.monad [utf8 <binary>] - (//.lift (\ utf8.codec decode utf8)))))] + (//.lifted (\ utf8.codec decode utf8)))))] [08 utf8/8 ..binary/8] [16 utf8/16 ..binary/16] diff --git a/stdlib/source/library/lux/control/parser/cli.lux b/stdlib/source/library/lux/control/parser/cli.lux index cc9bf19ab..3dd50a349 100644 --- a/stdlib/source/library/lux/control/parser/cli.lux +++ b/stdlib/source/library/lux/control/parser/cli.lux @@ -24,7 +24,7 @@ (#try.Success output) _ - (#try.Failure (format "Remaining CLI inputs: " (text.join_with " " remaining)))) + (#try.Failure (format "Remaining CLI inputs: " (text.interposed " " remaining)))) (#try.Failure try) (#try.Failure try))) @@ -85,7 +85,7 @@ (function (_ inputs) (case inputs #.End (#try.Success [inputs []]) - _ (#try.Failure (format "Unknown parameters: " (text.join_with " " inputs)))))) + _ (#try.Failure (format "Unknown parameters: " (text.interposed " " inputs)))))) (def: .public (named name value) {#.doc (example "Parses a named parameter and yields its value.")} diff --git a/stdlib/source/library/lux/control/parser/code.lux b/stdlib/source/library/lux/control/parser/code.lux index d22039f4a..93a2f65d9 100644 --- a/stdlib/source/library/lux/control/parser/code.lux +++ b/stdlib/source/library/lux/control/parser/code.lux @@ -31,10 +31,11 @@ {#.doc "A Lux code parser."} (//.Parser (List Code))) -(def: (remaining_inputs codes) +(def: remaining_inputs (-> (List Code) Text) - ($_ text\compose text.new_line "Remaining input: " - (|> codes (list\map code.format) (list.interposed " ") (text.join_with "")))) + (|>> (list\map code.format) + (text.interposed " ") + ($_ text\compose text.new_line "Remaining input: "))) (def: .public any {#.doc "Yields the next input without applying any logic."} @@ -189,9 +190,10 @@ (#try.Success value) _ - (#try.Failure (text\compose "Unconsumed inputs: " - (|> (list\map code.format unconsumed) - (text.join_with ", "))))))) + (#try.Failure (|> unconsumed + (list\map code.format) + (text.interposed ", ") + (text\compose "Unconsumed inputs: ")))))) (def: .public (local inputs parser) {#.doc "Runs parser against the given list of inputs."} diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index ffe6e6f27..fb2c59128 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -39,7 +39,7 @@ (def: (remaining' offset tape) (-> Offset Text Text) - (|> tape (/.split_at offset) maybe.assume product.right)) + (|> tape (/.split_at offset) maybe.trusted product.right)) (exception: .public (unconsumed_input {offset Offset} {tape Text}) (exception.report @@ -174,7 +174,7 @@ (-> Nat Nat (Parser Text)) (do //.monad [char any - .let [char' (maybe.assume (/.char 0 char))] + .let [char' (maybe.trusted (/.char 0 char))] _ (//.assertion ($_ /\compose "Character is not within range: " (/.of_char bottom) "-" (/.of_char top)) (.and (n.>= bottom char') (n.<= top char')))] @@ -392,4 +392,4 @@ (//.Parser s a))) (do //.monad [raw text] - (//.lift (..result structured raw)))) + (//.lifted (..result structured raw)))) diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 619526cdb..8016080b5 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -58,7 +58,7 @@ (exception.report ["Types" (|> remaining (list\map (|>> %.type (format text.new_line "* "))) - (text.join_with ""))])) + (text.interposed ""))])) (type: .public Env {#.doc (example "An environment for type parsing.")} diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux index 73737cb54..09fcd2058 100644 --- a/stdlib/source/library/lux/control/reader.lux +++ b/stdlib/source/library/lux/control/reader.lux @@ -57,9 +57,11 @@ {#.doc "Monad transformer for Reader."} (All [M] (-> (Monad M) (All [e] (Monad (All [a] (Reader e (M a))))))) - (def: &functor (functor.compose ..functor (get@ #monad.&functor monad))) + (def: &functor + (functor.composite ..functor (get@ #monad.&functor monad))) - (def: in (|>> (\ monad in) (\ ..monad in))) + (def: in + (|>> (\ monad in) (\ ..monad in))) (def: (join eMeMa) (function (_ env) @@ -67,7 +69,7 @@ [eMa (result env eMeMa)] (result env eMa))))) -(def: .public lift +(def: .public lifted {#.doc "Lift monadic values to the Reader wrapper."} (All [M e a] (-> (M a) (Reader e (M a)))) (\ ..monad in)) diff --git a/stdlib/source/library/lux/control/region.lux b/stdlib/source/library/lux/control/region.lux index ba3962400..191c6a328 100644 --- a/stdlib/source/library/lux/control/region.lux +++ b/stdlib/source/library/lux/control/region.lux @@ -154,7 +154,7 @@ (All [r] (Region r ! a)))) (failure monad (exception.error exception message))) -(def: .public (lift monad operation) +(def: .public (lifted monad operation) {#.doc (example "Lift an effectful computation into a region-based computation.")} (All [! a] (-> (Monad !) (! a) diff --git a/stdlib/source/library/lux/control/state.lux b/stdlib/source/library/lux/control/state.lux index 9cb56fb89..470751832 100644 --- a/stdlib/source/library/lux/control/state.lux +++ b/stdlib/source/library/lux/control/state.lux @@ -142,7 +142,7 @@ [[state' sMa] (sMsMa state)] (sMa state'))))) -(def: .public (lift monad ma) +(def: .public (lifted monad ma) {#.doc "Lift monadic values to the +State wrapper."} (All [M s a] (-> (Monad M) (M a) (+State M s a))) (function (_ state) diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux index 7e785b6fa..c7dc9f1d9 100644 --- a/stdlib/source/library/lux/control/try.lux +++ b/stdlib/source/library/lux/control/try.lux @@ -65,7 +65,7 @@ (All [!] (-> (Monad !) (Monad (All [a] (! (Try a)))))) (def: &functor - (functor.compose (get@ #monad.&functor monad) ..functor)) + (functor.composite (get@ #monad.&functor monad) ..functor)) (def: in (|>> (\ ..monad in) @@ -101,7 +101,7 @@ false ))) -(def: .public (assumed try) +(def: .public (trusted try) {#.doc (example "Assumes a Try value succeeded, and yields its value." "If it didn't, raises the error as a runtime error." "WARNING: Use with caution.")} diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux index fe7511a68..18a0fc7e1 100644 --- a/stdlib/source/library/lux/control/writer.lux +++ b/stdlib/source/library/lux/control/writer.lux @@ -55,8 +55,8 @@ (All [l M] (-> (Monoid l) (Monad M) (Monad (All [a] (M (Writer l a)))))) (def: &functor - (functor.compose (get@ #monad.&functor monad) - ..functor)) + (functor.composite (get@ #monad.&functor monad) + ..functor)) (def: in (let [writer (..monad monoid)] @@ -72,7 +72,7 @@ [l2 a] Mla] (in [(\ monoid compose l1 l2) a])))) -(def: .public (lift monoid monad) +(def: .public (lifted monoid monad) {#.doc (example "Wraps a monadic value with Writer machinery.")} (All [l M a] (-> (Monoid l) (Monad M) |