aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-07-10 03:10:43 -0400
committerEduardo Julian2021-07-10 03:10:43 -0400
commit4610968193df10af12c91f699fec39aeb3ef703a (patch)
tree27d1578548ad49f5aefe76fb696a7af10361c9cf /stdlib/source/lux.lux
parentf3e869d0246e956399ec31a074c6c6299ff73602 (diff)
Made the "try" macro into a common one, instead of a host-specific one.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux.lux18
1 files changed, 18 insertions, 0 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux
index be6755ebe..d4e8efda6 100644
--- a/stdlib/source/lux.lux
+++ b/stdlib/source/lux.lux
@@ -5907,3 +5907,21 @@
_
(..fail (..wrong_syntax_error (name_of ..:let)))))
+
+(macro: #export (try tokens)
+ {#.doc (doc (case (try (risky_computation input))
+ (#.Right success)
+ (do_something success)
+
+ (#.Left error)
+ (recover_from_failure error)))}
+ (case tokens
+ (^ (list expression))
+ (do meta_monad
+ [g!_ (gensym "g!_")]
+ (wrap (list (` ("lux try"
+ (.function ((~ g!_) (~ g!_))
+ (~ expression)))))))
+
+ _
+ (..fail (..wrong_syntax_error (name_of ..try)))))