diff options
author | Eduardo Julian | 2022-07-07 20:47:14 -0400 |
---|---|---|
committer | Eduardo Julian | 2022-07-07 20:47:14 -0400 |
commit | fc6e6f19818dc24c8932b74a274b081f5720fda4 (patch) | |
tree | 0a35130aa9b3358345b9ca15a6c7d507ec7cf9bb /stdlib/source/library/lux/math/number/nat.lux | |
parent | f7880ce83ba82ada2d04a0c587448446e677d458 (diff) |
Added support for defining custom/closed macro systems.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/library/lux/math/number/nat.lux | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/stdlib/source/library/lux/math/number/nat.lux b/stdlib/source/library/lux/math/number/nat.lux index 75bf0fe2b..c502f4d96 100644 --- a/stdlib/source/library/lux/math/number/nat.lux +++ b/stdlib/source/library/lux/math/number/nat.lux @@ -12,10 +12,7 @@ [control ["[0]" function] ["[0]" maybe] - ["[0]" try (.only Try)]] - [meta - [macro - ["^" pattern]]]]]) + ["[0]" try (.only Try)]]]]) (with_template [<extension> <output> <name>] [(def .public (<name> parameter subject) @@ -122,14 +119,18 @@ (-> Nat Nat Bit) (..= 1 (..gcd a b))) -(def .public (lcm a b) - (-> Nat Nat Nat) - (case [a b] - (^.or [_ 0] [0 _]) - 0 +(`` (def .public (lcm a b) + (-> Nat Nat Nat) + (case [a b] + (,, (with_template [<pattern>] + [<pattern> + 0] + + [[_ 0]] + [[0 _]])) - _ - (|> a (../ (..gcd a b)) (..* b)))) + _ + (|> a (../ (..gcd a b)) (..* b))))) (def .public even? (-> Nat Bit) @@ -272,22 +273,28 @@ 15 "F" _ (undefined))) -(def (hexadecimal_value digit) - (-> Nat (Maybe Nat)) - (case digit - (^.with_template [<character> <number>] - [(char <character>) - {.#Some <number>}]) - (["0" 0] ["1" 1] ["2" 2] ["3" 3] ["4" 4] - ["5" 5] ["6" 6] ["7" 7] ["8" 8] ["9" 9]) - - (^.with_template [<lower> <upper> <number>] - [(^.or (char <lower>) - (char <upper>)) - {.#Some <number>}]) - (["a" "A" 10] ["b" "B" 11] ["c" "C" 12] - ["d" "D" 13] ["e" "E" 14] ["f" "F" 15]) - _ {.#None})) +(`` (def (hexadecimal_value digit) + (-> Nat (Maybe Nat)) + (case digit + (,, (with_template [<character> <number>] + [(char <character>) + {.#Some <number>}] + + ["0" 0] ["1" 1] ["2" 2] ["3" 3] ["4" 4] + ["5" 5] ["6" 6] ["7" 7] ["8" 8] ["9" 9])) + + (,, (with_template [<lower> <upper> <number>] + [(char <lower>) + {.#Some <number>} + + (char <upper>) + {.#Some <number>}] + + ["a" "A" 10] ["b" "B" 11] ["c" "C" 12] + ["d" "D" 13] ["e" "E" 14] ["f" "F" 15])) + + _ + {.#None}))) (with_template [<shift> <struct> <to_character> <to_value> <error>] [(def .public <struct> |