From 4610968193df10af12c91f699fec39aeb3ef703a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 10 Jul 2021 03:10:43 -0400 Subject: Made the "try" macro into a common one, instead of a host-specific one. --- stdlib/source/lux.lux | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'stdlib/source/lux.lux') 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))))) -- cgit v1.2.3