aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2017-09-19 19:16:39 -0400
committerEduardo Julian2017-09-19 19:16:39 -0400
commitf371c3702eafdc38b3e1fac77a9388cab25e4751 (patch)
tree612e46d20ed7ae5db0ead11e8afc18be3eca1ef7
parent4474a2a3ba6b345cb5d369ad5654bf11481d0393 (diff)
- Added "when" function (great for piping).
-rw-r--r--stdlib/source/lux.lux11
-rw-r--r--stdlib/source/lux/control/concatenative.lux2
2 files changed, 10 insertions, 3 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index 641e8693d..6b29d7c42 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -5603,10 +5603,10 @@
(macro: #export (undefined tokens)
{#;doc (doc "Meant to be used as a stand-in for functions with undefined implementations."
"Undefined expressions will type-check against everything, so they make good dummy implementations."
+ "However, if an undefined expression is ever evaluated, it will raise a runtime error."
(def: (square x)
(-> Int Int)
- (undefined))
- "If an undefined expression is ever evaluated, it will raise an error.")}
+ (undefined)))}
(case tokens
#;Nil
(return (list (` (error! "Undefined behavior."))))
@@ -5761,3 +5761,10 @@
_
(#;Left "Wrong syntax for char")))
+
+(def: #export (when test f)
+ (All [a] (-> Bool (-> a a) (-> a a)))
+ (function [value]
+ (if test
+ (f value)
+ value)))
diff --git a/stdlib/source/lux/control/concatenative.lux b/stdlib/source/lux/control/concatenative.lux
index 61a6ddbd0..cdb9cc457 100644
--- a/stdlib/source/lux/control/concatenative.lux
+++ b/stdlib/source/lux/control/concatenative.lux
@@ -1,4 +1,4 @@
-(;module: [lux #- if loop
+(;module: [lux #- if loop when
n.+ n.- n.* n./ n.% n.= n.< n.<= n.> n.>=
i.+ i.- i.* i./ i.% i.= i.< i.<= i.> i.>=
d.+ d.- d.* d./ d.% d.= d.< d.<= d.> d.>=