diff options
author | Eduardo Julian | 2017-08-21 23:38:13 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-08-21 23:38:13 -0400 |
commit | e22bc1ab2660119a26a5a77168a6566f8de3fe08 (patch) | |
tree | 1ae2ca93b925c2f32825c16d0126cb2a55c5bf9a /stdlib/source | |
parent | b081ce6741fb6796daeed216d4ffce948368abf3 (diff) |
- Small refactorings.
Diffstat (limited to 'stdlib/source')
-rw-r--r-- | stdlib/source/lux/data/result.lux | 21 | ||||
-rw-r--r-- | stdlib/source/lux/host.jvm.lux | 12 |
2 files changed, 26 insertions, 7 deletions
diff --git a/stdlib/source/lux/data/result.lux b/stdlib/source/lux/data/result.lux index 791bdee48..aa9de092b 100644 --- a/stdlib/source/lux/data/result.lux +++ b/stdlib/source/lux/data/result.lux @@ -1,5 +1,5 @@ (;module: - [lux #- assume] + [lux #- assume default] (lux (control functor applicative ["M" monad #+ do Monad]))) @@ -77,3 +77,22 @@ (#Error message) (error! message))) + +(macro: #export (default tokens compiler) + {#;doc (doc "Allows you to provide a default value that will be used" + "if a (Result x) value turns out to be #Error." + (is 10 + (default 20 (#Success 10))) + (is 20 + (default 20 (#Error "KABOOM!"))))} + (case tokens + (^ (list else result)) + (#Success [compiler (list (` (case (~ result) + (#;;Success (~' g!temp)) + (~' g!temp) + + (#;;Error (~ [dummy-cursor (#;Symbol ["" ""])])) + (~ else))))]) + + _ + (#Error "Wrong syntax for default"))) diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index 058f34555..a735a8570 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -2023,9 +2023,9 @@ (macro;fail (format "Cannot convert to JvmType: " (type;to-text type))) )) -(syntax: #export (array-load idx array) +(syntax: #export (array-read idx array) {#;doc (doc "Loads an element from an array." - (array-load +10 my-array))} + (array-read +10 my-array))} (case array [_ (#;Symbol array-name)] (do Monad<Lux> @@ -2050,11 +2050,11 @@ _ (with-gensyms [g!array] (wrap (list (` (let [(~ g!array) (~ array)] - (;;array-load (~ g!array) (~ idx))))))))) + (;;array-read (~ idx) (~ g!array))))))))) -(syntax: #export (array-store idx value array) +(syntax: #export (array-write idx value array) {#;doc (doc "Stores an element into an array." - (array-store +10 my-object my-array))} + (array-write +10 my-object my-array))} (case array [_ (#;Symbol array-name)] (do Monad<Lux> @@ -2079,7 +2079,7 @@ _ (with-gensyms [g!array] (wrap (list (` (let [(~ g!array) (~ array)] - (;;array-store (~ g!array) (~ idx) (~ value))))))))) + (;;array-write (~ idx) (~ value) (~ g!array))))))))) (def: simple-bindings^ (Syntax (List [Text Code])) |