aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorEduardo Julian2022-03-30 14:46:09 -0400
committerEduardo Julian2022-03-30 14:46:09 -0400
commit8ebc505f1be8e103039d220b2d824dd687777f24 (patch)
treec439d60e014540de5bbfaa773664aec8acc85ee7 /stdlib
parent381ec5920d9ebeb335963778dec182268819e718 (diff)
"when" macro for Try.
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/source/library/lux/control/try.lux16
1 files changed, 15 insertions, 1 deletions
diff --git a/stdlib/source/library/lux/control/try.lux b/stdlib/source/library/lux/control/try.lux
index 4da14bb92..d00d15d28 100644
--- a/stdlib/source/library/lux/control/try.lux
+++ b/stdlib/source/library/lux/control/try.lux
@@ -150,4 +150,18 @@
(~ else))))]}
_
- {#Failure "Wrong syntax for else"}))
+ {#Failure "Wrong syntax for 'else'"}))
+
+(macro: .public (when tokens state)
+ (case tokens
+ (pattern (.list test then))
+ (let [code#encoded ("lux in-module" "library/lux" .code#encoded)
+ text$ ("lux in-module" "library/lux" .text$)]
+ {.#Right [state (.list (` (.if (~ test)
+ (~ then)
+ {..#Failure (~ (text$ ($_ "lux text concat"
+ "[" (code#encoded (` .when)) "]"
+ " " "Invalid condition:")))})))]})
+
+ _
+ {.#Left "Wrong syntax for 'when'"}))