aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
authorEduardo Julian2017-10-22 12:35:52 -0400
committerEduardo Julian2017-10-22 12:35:52 -0400
commit097b4f312b7426cc9064e5f7b28bea3deb60fe63 (patch)
tree9f81ff9cb71ce917ca570197c5362073a0896578 /stdlib/source
parent49f74e0ea7e9ef22ac7a189ff536a839d703ac5d (diff)
- Better names for piping macros.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/control/pipe.lux59
1 files changed, 26 insertions, 33 deletions
diff --git a/stdlib/source/lux/control/pipe.lux b/stdlib/source/lux/control/pipe.lux
index 937935684..6f7721cf6 100644
--- a/stdlib/source/lux/control/pipe.lux
+++ b/stdlib/source/lux/control/pipe.lux
@@ -1,4 +1,4 @@
-(;module: {#;doc "Composable extensions to the piping macro |> that enhance it with various abilities."}
+(;module: {#;doc "Composable extensions to the piping macros (|> and <|) that enhance them with various abilities."}
lux
(lux (control ["M" monad #+ do Monad]
["p" parser])
@@ -13,12 +13,12 @@
(Syntax (List Code))
(s;tuple (p;many s;any)))
-(syntax: #export (_> [tokens (p;at-least +2 s;any)])
+(syntax: #export (new> [tokens (p;at-least +2 s;any)])
{#;doc (doc "Ignores the piped argument, and begins a new pipe."
(|> 20
(i.* 3)
(i.+ 4)
- (_> 0 i.inc)))}
+ (new> 0 i.inc)))}
(case (list;reverse tokens)
(^ (list& _ r-body))
(wrap (list (` (|> (~@ (list;reverse r-body))))))
@@ -26,33 +26,26 @@
_
(undefined)))
-(syntax: #export (@> [name (p;default "@" s;local-symbol)]
- [body body^]
- prev)
+(syntax: #export (let> lhs [body body^] prev)
{#;doc (doc "Gives a name to the piped-argument, within the given expression."
- "If given no name, defaults to '@'."
(|> 5
- (@> X [(i.+ X X)]))
-
- (|> 5
- (@> [(i.+ @ @)])))}
+ (let> X [(i.+ X X)])))}
(wrap (list (L/fold (function [next prev]
- (` (with-expansions
- [(~ (code;symbol ["" name])) (~ prev)]
+ (` (let [(~ lhs) (~ prev)]
(~ next))))
prev
body))))
-(syntax: #export (?> [branches (p;many (p;seq body^ body^))]
- [?else (p;maybe body^)]
- prev)
+(syntax: #export (cond> [branches (p;many (p;seq body^ body^))]
+ [?else (p;maybe body^)]
+ prev)
{#;doc (doc "Branching for pipes."
"Both the tests and the bodies are piped-code, and must be given inside a tuple."
"If a last else-pipe is not given, the piped-argument will be used instead."
(|> 5
- (?> [i.even?] [(i.* 2)]
- [i.odd?] [(i.* 3)]
- [(_> -1)])))}
+ (cond> [i.even?] [(i.* 2)]
+ [i.odd?] [(i.* 3)]
+ [(new> -1)])))}
(with-gensyms [g!temp]
(wrap (list (` (with-expansions
[(~ g!temp) (~ prev)]
@@ -67,26 +60,26 @@
_
g!temp)))))))))
-(syntax: #export (!> [test body^] [then body^] prev)
+(syntax: #export (loop> [test body^] [then body^] prev)
{#;doc (doc "Loops for pipes."
"Both the testing and calculating steps are pipes and must be given inside tuples."
(|> 1
- (!> [(i.< 10)]
- [i.inc])))}
+ (loop> [(i.< 10)]
+ [i.inc])))}
(with-gensyms [g!temp]
(wrap (list (` (loop [(~ g!temp) (~ prev)]
(if (|> (~ g!temp) (~@ test))
((~' recur) (|> (~ g!temp) (~@ then)))
(~ g!temp))))))))
-(syntax: #export (%> monad [steps (p;some body^)] prev)
+(syntax: #export (do> monad [steps (p;some body^)] prev)
{#;doc (doc "Monadic pipes."
"Each steps in the monadic computation is a pipe and must be given inside a tuple."
(|> 5
- (%> Id/Monad
- [(i.* 3)]
- [(i.+ 4)]
- [i.inc])))}
+ (do> Monad<Identity>
+ [(i.* 3)]
+ [(i.+ 4)]
+ [i.inc])))}
(with-gensyms [g!temp]
(case (list;reverse steps)
(^ (list& last-step prev-steps))
@@ -101,11 +94,11 @@
_
(wrap (list prev)))))
-(syntax: #export (~> [body body^] prev)
+(syntax: #export (exec> [body body^] prev)
{#;doc (doc "Non-updating pipes."
"Will generate piped computations, but their results will not be used in the larger scope."
(|> 5
- (~> [int-to-nat %n log!])
+ (exec> [int-to-nat %n log!])
(i.* 10)))}
(do @
[g!temp (meta;gensym "")]
@@ -113,13 +106,13 @@
(exec (|> (~ g!temp) (~@ body))
(~ g!temp))))))))
-(syntax: #export (&> [paths (p;many body^)] prev)
+(syntax: #export (tuple> [paths (p;many body^)] prev)
{#;doc (doc "Parallel branching for pipes."
"Allows to run multiple pipelines for a value and gives you a tuple of the outputs."
(|> 5
- (&> [(i.* 10)]
- [i.dec (i./ 2)]
- [Int/encode]))
+ (tuple> [(i.* 10)]
+ [i.dec (i./ 2)]
+ [Int/encode]))
"Will become: [50 2 \"5\"]")}
(do @
[g!temp (meta;gensym "")]