diff options
author | Eduardo Julian | 2017-03-30 23:09:25 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-03-30 23:09:25 -0400 |
commit | ae7c062bdf4ab8337f0eedae78b38df24e62822c (patch) | |
tree | 21654507c07c719b9d1a480d8b2ea6b9b439a6df /stdlib/source/lux.lux | |
parent | 020f625b3d94cdb00242ead397595eeff842533c (diff) |
- Nat encoding/decoding is now implemented in the standard library.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/lux.lux | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index fc606bc36..964cf5b57 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1544,8 +1544,7 @@ #Nil ($' Monad Maybe) {#wrap - (lambda' return [x] - (#Some x)) + (lambda' [x] (#Some x)) #bind (lambda' [f ma] @@ -2070,10 +2069,32 @@ (-> Bool Text) (if x "true" "false")) -(def:''' (Nat/encode x) +(def:''' (digit-to-text digit) #Nil (-> Nat Text) - (_lux_proc ["nat" "encode"] [x])) + (_lux_case digit + +0 "0" + +1 "1" +2 "2" +3 "3" + +4 "4" +5 "5" +6 "6" + +7 "7" +8 "8" +9 "9" + _ (_lux_proc ["io" "error"] ["undefined"]))) + +(def:''' (Nat/encode value) + #Nil + (-> Nat Text) + (_lux_case value + +0 + "+0" + + _ + (let' [loop (_lux_: (-> Nat Text Text) + (lambda' recur [input output] + (if (_lux_proc ["nat" "="] [input +0]) + (_lux_proc ["text" "append"] ["+" output]) + (recur (_lux_proc ["nat" "/"] [input +10]) + (_lux_proc ["text" "append"] [(digit-to-text (_lux_proc ["nat" "%"] [input +10])) + output])))))] + (loop value "")))) (def:''' (Int/encode x) #Nil |