aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2017-08-21 23:38:13 -0400
committerEduardo Julian2017-08-21 23:38:13 -0400
commite22bc1ab2660119a26a5a77168a6566f8de3fe08 (patch)
tree1ae2ca93b925c2f32825c16d0126cb2a55c5bf9a
parentb081ce6741fb6796daeed216d4ffce948368abf3 (diff)
- Small refactorings.
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/result.lux21
-rw-r--r--stdlib/source/lux/host.jvm.lux12
-rw-r--r--stdlib/test/test/lux/host.jvm.lux4
3 files changed, 28 insertions, 9 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]))
diff --git a/stdlib/test/test/lux/host.jvm.lux b/stdlib/test/test/lux/host.jvm.lux
index 5cbe2dffc..6d991d489 100644
--- a/stdlib/test/test/lux/host.jvm.lux
+++ b/stdlib/test/test/lux/host.jvm.lux
@@ -109,5 +109,5 @@
(test "Can set and get array values."
(let [arr (&;array Long size)]
- (exec (&;array-store idx value arr)
- (i.= value (&;array-load idx arr)))))))
+ (exec (&;array-write idx value arr)
+ (i.= value (&;array-read idx arr)))))))