ref: 797b4ce60e118ccc6b0b38b2d46b6c3acbe50778
parent: 076907e11308f988a76dc73fc97641e2ae6b238e
author: Ori Bernstein <[email protected]>
date: Fri Sep 13 13:19:51 EDT 2013
Add 'try' wrapper function.
--- a/libstd/option.myr
+++ b/libstd/option.myr
@@ -1,6 +1,24 @@
+use "types.use"
+use "fmt.use"
+use "varargs.use"
+
pkg std =
type option(@a) = union
`Some @a
`None
;;
+
+ generic try : (v : option(@a), msg : byte[:], args : ... -> @a)
+ generic tryv : (v : option(@a), msg : byte[:], args : valist -> @a)
;;
+
+generic try = {v, msg, args
+ -> tryv(v, msg, vastart(&args))
+}
+
+generic tryv = {v, msg, ap
+ match v
+ `None: fatalv(1, msg, ap);;
+ `Some a: -> a;;
+ ;;
+}