aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/control')
-rw-r--r--stdlib/source/library/lux/control/concatenative.lux13
-rw-r--r--stdlib/source/library/lux/control/concurrency/actor.lux36
-rw-r--r--stdlib/source/library/lux/control/concurrency/async.lux24
-rw-r--r--stdlib/source/library/lux/control/concurrency/frp.lux106
-rw-r--r--stdlib/source/library/lux/control/concurrency/semaphore.lux36
-rw-r--r--stdlib/source/library/lux/control/concurrency/stm.lux27
-rw-r--r--stdlib/source/library/lux/control/continuation.lux4
-rw-r--r--stdlib/source/library/lux/control/exception.lux4
-rw-r--r--stdlib/source/library/lux/control/function/contract.lux10
-rw-r--r--stdlib/source/library/lux/control/function/memo.lux2
-rw-r--r--stdlib/source/library/lux/control/function/mutual.lux6
-rw-r--r--stdlib/source/library/lux/control/io.lux4
-rw-r--r--stdlib/source/library/lux/control/lazy.lux4
-rw-r--r--stdlib/source/library/lux/control/parser/json.lux2
-rw-r--r--stdlib/source/library/lux/control/parser/text.lux6
-rw-r--r--stdlib/source/library/lux/control/parser/type.lux10
-rw-r--r--stdlib/source/library/lux/control/pipe.lux63
-rw-r--r--stdlib/source/library/lux/control/reader.lux2
-rw-r--r--stdlib/source/library/lux/control/remember.lux8
-rw-r--r--stdlib/source/library/lux/control/security/capability.lux4
-rw-r--r--stdlib/source/library/lux/control/writer.lux16
21 files changed, 202 insertions, 185 deletions
diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux
index 554e6b21d..622bb213b 100644
--- a/stdlib/source/library/lux/control/concatenative.lux
+++ b/stdlib/source/library/lux/control/concatenative.lux
@@ -69,9 +69,9 @@
(meta.failure (format "Cannot expand to more than a single AST/Code node:" text.new_line
(|> expansion (list\map %.code) (text.join_with " ")))))))
-(syntax: .public (=> {aliases aliases^}
- {inputs stack^}
- {outputs stack^})
+(syntax: .public (=> [aliases aliases^
+ inputs stack^
+ outputs stack^])
{#.doc (example "Concatenative function types."
(=> [Nat] [Nat])
(All [a] (-> a (=> [] [a])))
@@ -111,7 +111,7 @@
(function (_ [_ top])
top))
-(syntax: .public (||> {commands (<>.some <code>.any)})
+(syntax: .public (||> [commands (<>.some <code>.any)])
{#.doc (example "A self-contained sequence of concatenative instructions."
(is? value
(||> (..push sample)))
@@ -134,8 +134,7 @@
(<>.and (<>\in (` .private)) private)
)))
-(syntax: .public (word:
- {[export_policy name annotations type commands] ..word})
+(syntax: .public (word: [[export_policy name annotations type commands] ..word])
{#.doc (example "A named concatenative function."
(word: square
(=> [Nat] [Nat])
@@ -147,7 +146,7 @@
(~ type)
(|>> (~+ commands)))))))
-(syntax: .public (apply {arity (<>.only (n.> 0) <code>.nat)})
+(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)))}
diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux
index 84d41564c..1557a9f89 100644
--- a/stdlib/source/library/lux/control/concurrency/actor.lux
+++ b/stdlib/source/library/lux/control/concurrency/actor.lux
@@ -54,7 +54,7 @@
(Resolver [a Mailbox])])
(IO (List a))))
(do {! io.monad}
- [current (async.poll read)]
+ [current (async.value read)]
(case current
(#.Some [head tail])
(\ ! map (|>> (#.Item head))
@@ -116,7 +116,7 @@
(All [s] (-> (Actor s) (IO Bit)))
(let [[obituary _] (get@ #obituary (:representation actor))]
(|> obituary
- async.poll
+ async.value
(\ io.functor map
(|>> (case> #.None
bit.yes
@@ -127,7 +127,7 @@
(def: .public (obituary' actor)
(All [s] (-> (Actor s) (IO (Maybe (Obituary s)))))
(let [[obituary _] (get@ #obituary (:representation actor))]
- (async.poll obituary)))
+ (async.value obituary)))
(def: .public obituary
{#.doc (example "Await for an actor to stop working.")}
@@ -147,7 +147,7 @@
[|mailbox|&resolve (atom.read! (get@ #mailbox (:representation actor)))]
(loop [[|mailbox| resolve] |mailbox|&resolve]
(do !
- [|mailbox| (async.poll |mailbox|)]
+ [|mailbox| (async.value |mailbox|)]
(case |mailbox|
#.None
(do !
@@ -300,8 +300,7 @@
(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})
+ (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>)}
@@ -323,8 +322,8 @@
(~+ messages))))))))
- (syntax: .public (actor {[state_type init] (<code>.record (<>.and <code>.any <code>.any))}
- {[?on_mail messages] behavior^})
+ (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
@@ -371,8 +370,7 @@
(<>.and <code>.any private)
(<>.and (<>\in (` .private)) private))))
- (syntax: .public (message:
- {[export_policy signature annotations output_type body] ..messageP})
+ (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."
@@ -422,12 +420,12 @@
(atom.atom ..continue!))
stop (: Stop
(atom.write! ..stop! signal))]
- (frp.subscribe (function (_ event)
- (do {! io.monad}
- [continue? (atom.read! signal)]
- (if continue?
- (|> actor
- (..mail! (action event stop))
- (\ ! map try.maybe))
- (in #.None))))
- channel)))
+ (frp.subscribe! (function (_ event)
+ (do {! io.monad}
+ [continue? (atom.read! signal)]
+ (if continue?
+ (|> actor
+ (..mail! (action event stop))
+ (\ ! map try.maybe))
+ (in #.None))))
+ channel)))
diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux
index 35ab37cac..32f1913b6 100644
--- a/stdlib/source/library/lux/control/concurrency/async.lux
+++ b/stdlib/source/library/lux/control/concurrency/async.lux
@@ -60,7 +60,7 @@
(let [async (:abstraction (atom [#.None (list)]))]
[async (..resolver async)]))
- (def: .public poll
+ (def: .public value
{#.doc "Polls an async for its value."}
(All [a] (-> (Async a) (IO (Maybe a))))
(|>> :representation
@@ -89,7 +89,7 @@
(def: .public resolved?
{#.doc "Checks whether an async's value has already been resolved."}
(All [a] (-> (Async a) (IO Bit)))
- (|>> ..poll
+ (|>> ..value
(\ io.functor map
(|>> (case> #.None
#0
@@ -178,7 +178,7 @@
[right]))
left||right))))
-(def: .public (schedule! millis_delay computation)
+(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)))
@@ -187,7 +187,7 @@
(|> (do io.monad
[value computation]
(resolve value))
- (thread.schedule! millis_delay)
+ (thread.schedule! milli_seconds)
io.run!)
!out)))
@@ -197,17 +197,17 @@
(All [a] (-> (IO a) (Async a)))
(..schedule! 0))
-(def: .public (delayed time_millis value)
+(def: .public (delayed milli_seconds value)
{#.doc "Delivers a value after a certain period has passed."}
(All [a] (-> Nat a (Async a)))
- (..schedule! time_millis (io value)))
+ (..schedule! milli_seconds (io value)))
-(def: .public (delay time_millis)
- {#.doc "An async that will be resolved after the specified amount of milliseconds."}
+(def: .public (delay milli_seconds)
+ {#.doc "An async that will be resolved after the specified amount of milli-seconds."}
(-> Nat (Async Any))
- (..delayed time_millis []))
+ (..delayed milli_seconds []))
-(def: .public (time_out time_millis async)
- {#.doc "Wait for an async to be resolved within the specified amount of milliseconds."}
+(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 time_millis) async))
+ (..or (..delay milli_seconds) async))
diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux
index 32cc8118a..97ed9bf6c 100644
--- a/stdlib/source/library/lux/control/concurrency/frp.lux
+++ b/stdlib/source/library/lux/control/concurrency/frp.lux
@@ -1,6 +1,6 @@
(.module:
[library
- [lux #*
+ [lux (#- list)
[abstract
[equivalence (#+ Equivalence)]
[functor (#+ Functor)]
@@ -124,50 +124,53 @@
(def: (join mma)
(let [[output sink] (channel [])]
- (exec (: (Async Any)
- (loop [mma mma]
- (do {! async.monad}
- [?mma mma]
- (case ?mma
- (#.Some [ma mma'])
- (do !
- [_ (loop [ma ma]
- (do !
- [?ma ma]
- (case ?ma
- (#.Some [a ma'])
- (exec (io.run! (\ sink feed a))
- (recur ma'))
-
- #.None
- (in []))))]
- (recur mma'))
-
- #.None
- (in (: Any (io.run! (\ sink close))))))))
+ (exec
+ (: (Async Any)
+ (loop [mma mma]
+ (do {! async.monad}
+ [?mma mma]
+ (case ?mma
+ (#.Some [ma mma'])
+ (do !
+ [_ (loop [ma ma]
+ (do !
+ [?ma ma]
+ (case ?ma
+ (#.Some [a ma'])
+ (exec
+ (io.run! (\ sink feed a))
+ (recur ma'))
+
+ #.None
+ (in []))))]
+ (recur mma'))
+
+ #.None
+ (in (: Any (io.run! (\ sink close))))))))
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)
+(def: .public (subscribe! subscriber channel)
(All [a] (-> (Subscriber a) (Channel a) (IO Any)))
- (io (exec (: (Async Any)
- (loop [channel channel]
- (do async.monad
- [item channel]
- (case item
- (#.Some [head tail])
- (case (io.run! (subscriber head))
- (#.Some _)
- (recur tail)
-
- #.None
- (in []))
-
- #.None
- (in [])))))
+ (io (exec
+ (: (Async Any)
+ (loop [channel channel]
+ (do async.monad
+ [item channel]
+ (case item
+ (#.Some [head tail])
+ (case (io.run! (subscriber head))
+ (#.Some _)
+ (recur tail)
+
+ #.None
+ (in []))
+
+ #.None
+ (in [])))))
[])))
(def: .public (only pass? channel)
@@ -228,11 +231,12 @@
(All [a]
(-> Nat (IO a) [(Channel a) (Sink a)]))
(let [[output sink] (channel [])]
- (exec (io.run! (loop [_ []]
- (do io.monad
- [value action
- _ (\ sink feed value)]
- (async.upon! recur (async.delay milli_seconds)))))
+ (exec
+ (io.run! (loop [_ []]
+ (do io.monad
+ [value action
+ _ (\ sink feed value)]
+ (async.upon! recur (async.delay milli_seconds)))))
[output sink])))
(def: .public (periodic milli_seconds)
@@ -267,21 +271,21 @@
(All [a] (-> (Equivalence a) (Channel a) (Channel a)))
(do async.monad
[item channel]
- (case item
- (#.Some [head tail])
- (in (#.Some [head (distinct' equivalence head tail)]))
-
- #.None
- (in #.None))))
+ (in (case item
+ (#.Some [head tail])
+ (#.Some [head (distinct' equivalence head tail)])
+
+ #.None
+ #.None))))
-(def: .public (consume channel)
+(def: .public (list channel)
(All [a] (-> (Channel a) (Async (List a))))
(do {! async.monad}
[item channel]
(case item
(#.Some [head tail])
(\ ! map (|>> (#.Item head))
- (consume tail))
+ (list tail))
#.None
(in #.End))))
diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux
index 06bb81b4e..55d87e6cd 100644
--- a/stdlib/source/library/lux/control/concurrency/semaphore.lux
+++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux
@@ -45,7 +45,7 @@
#open_positions (.int max_positions)
#waiting_list queue.empty}))))
- (def: .public (wait semaphore)
+ (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)))
@@ -71,7 +71,7 @@
(exception.report
["Max Positions" (%.nat max_positions)]))
- (def: .public (signal semaphore)
+ (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)]
@@ -107,21 +107,21 @@
(-> Any Mutex)
(:abstraction (semaphore 1)))
- (def: acquire
+ (def: acquire!
(-> Mutex (Async Any))
- (|>> :representation ..wait))
+ (|>> :representation ..wait!))
- (def: release
+ (def: release!
(-> Mutex (Async Any))
- (|>> :representation ..signal))
+ (|>> :representation ..signal!))
- (def: .public (synchronize mutex procedure)
+ (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)
+ [_ (..acquire! mutex)
output (io.run! procedure)
- _ (..release mutex)]
+ _ (..release! mutex)]
(in output)))
)
@@ -148,12 +148,12 @@
#start_turnstile (..semaphore 0)
#end_turnstile (..semaphore 0)}))
- (def: (un_block times turnstile)
+ (def: (un_block! times turnstile)
(-> Nat Semaphore (Async Any))
(loop [step 0]
(if (n.< times step)
(do async.monad
- [outcome (..signal turnstile)]
+ [outcome (..signal! turnstile)]
(recur (inc step)))
(\ async.monad in []))))
@@ -166,17 +166,17 @@
[_ count] (io.run! (atom.update! <update> (get@ #count barrier)))
reached? (n.= goal count)]]
(if reached?
- (..un_block (dec limit) (get@ <turnstile> barrier))
- (..wait (get@ <turnstile> barrier)))))]
+ (..un_block! (dec limit) (get@ <turnstile> barrier))
+ (..wait! (get@ <turnstile> barrier)))))]
- [start inc limit #start_turnstile]
- [end dec 0 #end_turnstile]
+ [start! inc limit #start_turnstile]
+ [end! dec 0 #end_turnstile]
)
- (def: .public (block barrier)
+ (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)]
- (..end barrier)))
+ [_ (..start! barrier)]
+ (..end! barrier)))
)
diff --git a/stdlib/source/library/lux/control/concurrency/stm.lux b/stdlib/source/library/lux/control/concurrency/stm.lux
index 321e8bfa8..e76d80b6a 100644
--- a/stdlib/source/library/lux/control/concurrency/stm.lux
+++ b/stdlib/source/library/lux/control/concurrency/stm.lux
@@ -112,7 +112,7 @@
[(#.Item [var value value] tx)
value]))))
-(def: (update_tx_value var value tx)
+(def: (with_updated_var var value tx)
(All [a] (-> (Var a) a Tx Tx))
(case tx
#.End
@@ -128,14 +128,14 @@
(#.Item {#var _var
#original _original
#current _current}
- (update_tx_value var value tx')))))
+ (with_updated_var var value tx')))))
(def: .public (write value var)
(All [a] (-> a (Var a) (STM Any)))
(function (_ tx)
(case (var_value var tx)
(#.Some _)
- [(update_tx_value var value tx)
+ [(with_updated_var var value tx)
[]]
#.None
@@ -213,14 +213,14 @@
(Atom Bit)
(atom #0))
-(def: (issue_commit commit)
+(def: (issue_commit! commit)
(All [a] (-> (Commit a) (IO Any)))
(let [entry [commit (async.async [])]]
(do {! io.monad}
[|commits|&resolve (atom.read! pending_commits)]
(loop [[|commits| resolve] |commits|&resolve]
(do !
- [|commits| (async.poll |commits|)]
+ [|commits| (async.value |commits|)]
(case |commits|
#.None
(do io.monad
@@ -232,17 +232,17 @@
(#.Some [head tail])
(recur tail)))))))
-(def: (process_commit commit)
+(def: (process_commit! commit)
(All [a] (-> (Commit a) (IO Any)))
(let [[stm_proc output resolve] commit
[finished_tx value] (stm_proc fresh_tx)]
(if (can_commit? finished_tx)
(do {! io.monad}
- [_ (monad.map ! commit_var! finished_tx)]
+ [_ (monad.map ! ..commit_var! finished_tx)]
(resolve value))
- (issue_commit commit))))
+ (..issue_commit! commit))))
-(def: init_processor!
+(def: start_commit_processor!
(IO Any)
(do {! io.monad}
[flag (atom.read! commit_processor_flag)]
@@ -255,7 +255,7 @@
[[async resolve] (atom.read! pending_commits)]
(async.upon! (function (recur [head [tail _resolve]])
(do !
- [_ (process_commit head)]
+ [_ (..process_commit! head)]
(async.upon! recur tail)))
async))
(in [])))
@@ -267,7 +267,8 @@
"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 (io.run! (do io.monad
- [_ init_processor!]
- (issue_commit [stm_proc output resolver])))
+ (exec
+ (io.run! (do io.monad
+ [_ ..start_commit_processor!]
+ (..issue_commit! [stm_proc output resolver])))
output)))
diff --git a/stdlib/source/library/lux/control/continuation.lux b/stdlib/source/library/lux/control/continuation.lux
index 7a46ed8a7..e9b702f55 100644
--- a/stdlib/source/library/lux/control/continuation.lux
+++ b/stdlib/source/library/lux/control/continuation.lux
@@ -8,7 +8,7 @@
[control
["." function]
[parser
- ["s" code]]]
+ ["<.>" code]]]
[macro (#+ with_identifiers)
[syntax (#+ syntax:)]
["." code]]]])
@@ -37,7 +37,7 @@
(f (function (_ a) (function (_ _) (k a)))
k)))
-(syntax: .public (pending expr)
+(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]
diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux
index ee5fd753a..9a9e7f845 100644
--- a/stdlib/source/library/lux/control/exception.lux
+++ b/stdlib/source/library/lux/control/exception.lux
@@ -97,7 +97,7 @@
(<>.and (<>\in (` .private)) private)
)))
-(syntax: .public (exception: {[export_policy t_vars [name inputs] body] ..exception})
+(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."
""
@@ -153,7 +153,7 @@
(on_entry head)
tail))))
-(syntax: .public (report {entries (<>.many (<code>.tuple (<>.and <code>.any <code>.any)))})
+(syntax: .public (report [entries (<>.many (<code>.tuple (<>.and <code>.any <code>.any)))])
{#.doc (example "An error report."
(: Text
(report ["Row 0" value/0]
diff --git a/stdlib/source/library/lux/control/function/contract.lux b/stdlib/source/library/lux/control/function/contract.lux
index ce62f8c45..0fb706a14 100644
--- a/stdlib/source/library/lux/control/function/contract.lux
+++ b/stdlib/source/library/lux/control/function/contract.lux
@@ -2,7 +2,9 @@
[library
[lux #*
[control
- ["." exception (#+ exception:)]]
+ ["." exception (#+ exception:)]
+ [parser
+ ["<.>" code]]]
[data
[text
["%" format (#+ format)]]]
@@ -28,7 +30,8 @@
[]
(panic! message)))
-(syntax: .public (pre test expr)
+(syntax: .public (pre [test <code>.any
+ expr <code>.any])
{#.doc (example "Pre-conditions."
"Given a test and an expression to run, only runs the expression if the test passes."
"Otherwise, an error is raised."
@@ -39,7 +42,8 @@
(~ test))
(~ expr))))))
-(syntax: .public (post test expr)
+(syntax: .public (post [test <code>.any
+ expr <code>.any])
{#.doc (example "Post-conditions."
"Given a predicate and an expression to run, evaluates the expression and then tests the output with the predicate."
"If the predicate returns #1, returns the value of the expression."
diff --git a/stdlib/source/library/lux/control/function/memo.lux b/stdlib/source/library/lux/control/function/memo.lux
index 924ec4c00..ae8c4e9bf 100644
--- a/stdlib/source/library/lux/control/function/memo.lux
+++ b/stdlib/source/library/lux/control/function/memo.lux
@@ -29,7 +29,7 @@
#.None
(do !
[output (delegate input)
- _ (state.update (dictionary.put input output))]
+ _ (state.update (dictionary.has input output))]
(in output)))))))
(type: .public (Memo i o)
diff --git a/stdlib/source/library/lux/control/function/mutual.lux b/stdlib/source/library/lux/control/function/mutual.lux
index e9cac3871..fd36ac10b 100644
--- a/stdlib/source/library/lux/control/function/mutual.lux
+++ b/stdlib/source/library/lux/control/function/mutual.lux
@@ -52,8 +52,8 @@
(function (_ parameters)
(\ meta.monad in (list (` (((~ g!self) (~ g!context)) (~+ parameters))))))))
-(syntax: .public (let {functions (<code>.tuple (<>.some ..mutual))}
- body)
+(syntax: .public (let [functions (<code>.tuple (<>.some ..mutual))
+ body <code>.any])
{#.doc (example "Locally-defined mutually-recursive functions."
(let [(even? number)
(-> Nat Bit)
@@ -118,7 +118,7 @@
(<code>.tuple (<>.either (<>.and <code>.any ..mutual)
(<>.and (<>\in (` .private)) ..mutual))))
-(syntax: .public (def: {functions (<>.many ..definition)})
+(syntax: .public (def: [functions (<>.many ..definition)])
{#.doc (example "Globally-defined mutually-recursive functions."
(def:
[.public (even? number)
diff --git a/stdlib/source/library/lux/control/io.lux b/stdlib/source/library/lux/control/io.lux
index bcb0f4d8c..321b7159e 100644
--- a/stdlib/source/library/lux/control/io.lux
+++ b/stdlib/source/library/lux/control/io.lux
@@ -8,7 +8,7 @@
[monad (#+ Monad do)]]
[control
[parser
- ["s" code]]]
+ ["<.>" code]]]
[type
abstract]
[macro (#+ with_identifiers)
@@ -33,7 +33,7 @@
... creatio ex nihilo
[((:representation io) [])])
- (syntax: .public (io computation)
+ (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
diff --git a/stdlib/source/library/lux/control/lazy.lux b/stdlib/source/library/lux/control/lazy.lux
index 677832ebd..dec12c5f5 100644
--- a/stdlib/source/library/lux/control/lazy.lux
+++ b/stdlib/source/library/lux/control/lazy.lux
@@ -9,7 +9,7 @@
[control
["." io]
[parser
- ["s" code]]
+ ["<.>" code]]
[concurrency
["." atom]]]
[macro (#+ with_identifiers)
@@ -41,7 +41,7 @@
(All [a] (-> (Lazy a) a))
((:representation lazy) [])))
-(syntax: .public (lazy expression)
+(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/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux
index 133f78332..51c3cc2bf 100644
--- a/stdlib/source/library/lux/control/parser/json.lux
+++ b/stdlib/source/library/lux/control/parser/json.lux
@@ -159,7 +159,7 @@
dictionary.entries
(list\map (function (_ [key value])
(list (#/.String key) value)))
- list.concat
+ list.joined
(//.result parser))
(#try.Failure error)
(//.failure error)
diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux
index 8d314634c..8ca2af321 100644
--- a/stdlib/source/library/lux/control/parser/text.lux
+++ b/stdlib/source/library/lux/control/parser/text.lux
@@ -302,7 +302,7 @@
[(def: .public (<name> parser)
{#.doc (code.text ($_ /\compose "Yields " <doc_modifier> " characters as a single continuous text (as a slice)."))}
(-> (Parser Text) (Parser Text))
- (|> parser <base> (\ //.monad map /.concat)))]
+ (|> parser <base> (\ //.monad map /.joined)))]
[some //.some "some"]
[many //.many "many"]
@@ -324,7 +324,7 @@
(-> Nat (Parser Text) (Parser Text))
(|> parser
(<base> amount)
- (\ //.monad map /.concat)))]
+ (\ //.monad map /.joined)))]
[exactly //.exactly "exactly"]
[at_most //.at_most "at most"]
@@ -347,7 +347,7 @@
(-> Nat Nat (Parser Text) (Parser Text))
(|> parser
(//.between minimum additional)
- (\ //.monad map /.concat)))
+ (\ //.monad map /.joined)))
(def: .public (between! minimum additional parser)
(-> Nat Nat (Parser Slice) (Parser Slice))
diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux
index aaebfb594..964513f24 100644
--- a/stdlib/source/library/lux/control/parser/type.lux
+++ b/stdlib/source/library/lux/control/parser/type.lux
@@ -152,7 +152,7 @@
(let [current_id (dictionary.size env)
g!var (label current_id)]
(case (//.result poly
- [(dictionary.put current_id [type g!var] env)
+ [(dictionary.has current_id [type g!var] env)
inputs])
(#try.Failure error)
(#try.Failure error)
@@ -200,8 +200,8 @@
(let [varL (label (inc funcI))]
(recur (inc current_arg)
(|> env'
- (dictionary.put funcI [headT funcL])
- (dictionary.put (inc funcI) [(#.Parameter (inc funcI)) varL]))
+ (dictionary.has funcI [headT funcL])
+ (dictionary.has (inc funcI) [(#.Parameter (inc funcI)) varL]))
(#.Item varL all_varsL)))
(let [partialI (|> current_arg (n.* 2) (n.+ funcI))
partial_varI (inc partialI)
@@ -211,8 +211,8 @@
list.reversed))))]
(recur (inc current_arg)
(|> env'
- (dictionary.put partialI [.Nothing partialC])
- (dictionary.put partial_varI [(#.Parameter partial_varI) partial_varL]))
+ (dictionary.has partialI [.Nothing partialC])
+ (dictionary.has partial_varI [(#.Parameter partial_varI) partial_varL]))
(#.Item partial_varL all_varsL))))
[all_varsL env']))]]
(<| (with_env env')
diff --git a/stdlib/source/library/lux/control/pipe.lux b/stdlib/source/library/lux/control/pipe.lux
index 07f38e15e..4d31c2035 100644
--- a/stdlib/source/library/lux/control/pipe.lux
+++ b/stdlib/source/library/lux/control/pipe.lux
@@ -5,9 +5,9 @@
[abstract
[monad (#+ do)]]
[control
- ["e" try]
- ["p" parser
- ["s" code (#+ Parser)]]]
+ ["." try]
+ ["<>" parser
+ ["<.>" code (#+ Parser)]]]
[data
["." identity]
[collection
@@ -22,11 +22,11 @@
(def: body^
(Parser (List Code))
- (s.tuple (p.some s.any)))
+ (<code>.tuple (<>.some <code>.any)))
-(syntax: .public (new> start
- {body body^}
- prev)
+(syntax: .public (new> [start <code>.any
+ body body^
+ prev <code>.any])
{#.doc (example "Ignores the piped argument, and begins a new pipe."
(n.= 1
(|> 20
@@ -35,7 +35,9 @@
(new> 0 [inc]))))}
(in (list (` (|> (~ start) (~+ body))))))
-(syntax: .public (let> binding body prev)
+(syntax: .public (let> [binding <code>.any
+ body <code>.any
+ prev <code>.any])
{#.doc (example "Gives a name to the piped-argument, within the given expression."
(n.= 10
(|> 5
@@ -46,13 +48,13 @@
(def: _reversed_
(Parser Any)
(function (_ tokens)
- (#e.Success [(list.reversed tokens) []])))
+ (#try.Success [(list.reversed tokens) []])))
-(syntax: .public (cond> {_ _reversed_}
- prev
- {else body^}
- {_ _reversed_}
- {branches (p.some (p.and body^ body^))})
+(syntax: .public (cond> [_ _reversed_
+ prev <code>.any
+ else body^
+ _ _reversed_
+ branches (<>.some (<>.and body^ body^))])
{#.doc (example "Branching for pipes."
"Both the tests and the bodies are piped-code, and must be given inside a tuple."
(|> +5
@@ -67,7 +69,10 @@
(` (|> (~ g!temp) (~+ then))))))
(|> (~ g!temp) (~+ else)))))))))
-(syntax: .public (if> {test body^} {then body^} {else body^} prev)
+(syntax: .public (if> [test body^
+ then body^
+ else body^
+ prev <code>.any])
{#.doc (example "If-branching."
(is? (if (n.even? sample)
"even"
@@ -80,7 +85,9 @@
[(~+ else)]
(~ prev))))))
-(syntax: .public (when> {test body^} {then body^} prev)
+(syntax: .public (when> [test body^
+ then body^
+ prev <code>.any])
{#.doc (example "Only execute the body when the test passes."
(is? (if (n.even? sample)
(n.* 2 sample)
@@ -92,9 +99,9 @@
[]
(~ prev))))))
-(syntax: .public (loop> {test body^}
- {then body^}
- prev)
+(syntax: .public (loop> [test body^
+ then body^
+ prev <code>.any])
{#.doc (example "Loops for pipes."
"Both the testing and calculating steps are pipes and must be given inside tuples."
(|> +1
@@ -106,9 +113,9 @@
((~' recur) (|> (~ g!temp) (~+ then)))
(~ g!temp))))))))
-(syntax: .public (do> monad
- {steps (p.some body^)}
- prev)
+(syntax: .public (do> [monad <code>.any
+ steps (<>.some body^)
+ prev <code>.any])
{#.doc (example "Monadic pipes."
"Each steps in the monadic computation is a pipe and must be given inside a tuple."
(|> +5
@@ -130,8 +137,8 @@
_
(in (list prev)))))
-(syntax: .public (exec> {body body^}
- prev)
+(syntax: .public (exec> [body body^
+ prev <code>.any])
{#.doc (example "Non-updating pipes."
"Will generate piped computations, but their results will not be used in the larger scope."
(|> +5
@@ -142,8 +149,8 @@
(exec (|> (~ g!temp) (~+ body))
(~ g!temp))))))))
-(syntax: .public (tuple> {paths (p.many body^)}
- prev)
+(syntax: .public (tuple> [paths (<>.many body^)
+ prev <code>.any])
{#.doc (example "Parallel branching for pipes."
"Allows to run multiple pipelines for a value and gives you a tuple of the outputs."
(|> +5
@@ -156,8 +163,8 @@
[(~+ (list\map (function (_ body) (` (|> (~ g!temp) (~+ body))))
paths))]))))))
-(syntax: .public (case> {branches (p.many (p.and s.any s.any))}
- prev)
+(syntax: .public (case> [branches (<>.many (<>.and <code>.any <code>.any))
+ prev <code>.any])
{#.doc (example "Pattern-matching for pipes."
"The bodies of each branch are NOT pipes; just regular values."
(|> +5
diff --git a/stdlib/source/library/lux/control/reader.lux b/stdlib/source/library/lux/control/reader.lux
index b2e5b9399..73737cb54 100644
--- a/stdlib/source/library/lux/control/reader.lux
+++ b/stdlib/source/library/lux/control/reader.lux
@@ -10,7 +10,7 @@
{#.doc "Computations that have access to some environmental value."}
(-> r a))
-(def: .public ask
+(def: .public read
{#.doc "Get the environment."}
(All [r] (Reader r r))
(function (_ env) env))
diff --git a/stdlib/source/library/lux/control/remember.lux b/stdlib/source/library/lux/control/remember.lux
index f4f9c4213..25b595b63 100644
--- a/stdlib/source/library/lux/control/remember.lux
+++ b/stdlib/source/library/lux/control/remember.lux
@@ -47,7 +47,9 @@
(#try.Failure message)
(<>.failure message)))))
-(syntax: .public (remember {deadline ..deadline} {message <c>.text} {focus (<>.maybe <c>.any)})
+(syntax: .public (remember [deadline ..deadline
+ message <c>.text
+ focus (<>.maybe <c>.any)])
{#.doc (example "A message with an expiration date."
"Can have an optional piece of code to focus on."
(remember "2022-04-01"
@@ -67,7 +69,9 @@
(meta.failure (exception.error ..must_remember [deadline today message focus])))))
(template [<name> <message>]
- [(`` (syntax: .public (<name> {deadline ..deadline} {message <c>.text} {focus (<>.maybe <c>.any)})
+ [(`` (syntax: .public (<name> [deadline ..deadline
+ message <c>.text
+ focus (<>.maybe <c>.any)])
{#.doc (example (~~ (template.text ["A " <message> " message with an expiration date."]))
"Can have an optional piece of code to focus on."
(<name> "2022-04-01"
diff --git a/stdlib/source/library/lux/control/security/capability.lux b/stdlib/source/library/lux/control/security/capability.lux
index bf689a80c..cebf0534e 100644
--- a/stdlib/source/library/lux/control/security/capability.lux
+++ b/stdlib/source/library/lux/control/security/capability.lux
@@ -44,12 +44,12 @@
output))
((:representation capability) input))
- (syntax: .public (capability: {[export_policy declaration annotations [forger input output]]
+ (syntax: .public (capability: [[export_policy declaration annotations [forger input output]]
(|export|.parser
($_ <>.and
|declaration|.parser
(<>.maybe |annotations|.parser)
- (<c>.form ($_ <>.and <c>.local_identifier <c>.any <c>.any))))})
+ (<c>.form ($_ <>.and <c>.local_identifier <c>.any <c>.any))))])
{#.doc (example "Defines a capability as a unique type, and a constructor for instances."
(capability: (Can_Duplicate a)
diff --git a/stdlib/source/library/lux/control/writer.lux b/stdlib/source/library/lux/control/writer.lux
index 7ac976d6b..fe7511a68 100644
--- a/stdlib/source/library/lux/control/writer.lux
+++ b/stdlib/source/library/lux/control/writer.lux
@@ -8,15 +8,15 @@
["." functor (#+ Functor)]
["." monad (#+ Monad do)]]]])
-(type: .public (Writer l a)
- {#.doc "Represents a value with an associated 'log' value to record arbitrary information."}
- {#log l
- #value a})
+(type: .public (Writer log value)
+ {#.doc "Represents a value with an associated 'log' to record arbitrary information."}
+ {#log log
+ #value value})
-(def: .public (write l)
- {#.doc "Set the log to a particular value."}
- (All [l] (-> l (Writer l Any)))
- [l []])
+(def: .public (write message)
+ {#.doc "Write a value to the log."}
+ (All [log] (-> log (Writer log Any)))
+ [message []])
(implementation: .public functor
(All [l]