diff options
Diffstat (limited to 'stdlib')
-rw-r--r-- | stdlib/source/lux/data/coll/list.lux | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/stdlib/source/lux/data/coll/list.lux b/stdlib/source/lux/data/coll/list.lux index e4add4dec..fdef97988 100644 --- a/stdlib/source/lux/data/coll/list.lux +++ b/stdlib/source/lux/data/coll/list.lux @@ -6,7 +6,7 @@ ["M" monad #*] eq [fold]) - (data [number "Int/" Number<Int> Codec<Text,Int>] + (data [number "Nat/" Codec<Text,Nat>] bool [product]))) @@ -338,24 +338,25 @@ (macro: #export (zip tokens state) {#;doc (doc "Create list zippers with the specified number of input lists." - (def: #export zip2 (zip 2)) - (def: #export zip3 (zip 3)) - ((zip 3) xs ys zs))} + (def: #export zip2 (zip +2)) + (def: #export zip3 (zip +3)) + ((zip +3) xs ys zs))} (case tokens - (^ (list [_ (#;Int num-lists)])) - (if (i.> 0 num-lists) + (^ (list [_ (#;Nat num-lists)])) + (if (n.> +0 num-lists) (let [(^open) Functor<List> - indices (i.range 0 (i.dec num-lists)) - type-vars (: (List AST) (map (. symbol$ Int/encode) indices)) + indices (n.range +0 (n.dec num-lists)) + type-vars (: (List AST) (map (. symbol$ Nat/encode) indices)) zip-type (` (All [(~@ type-vars)] (-> (~@ (map (: (-> AST AST) (function [var] (` (List (~ var))))) type-vars)) (List [(~@ type-vars)])))) vars+lists (|> indices - (map i.inc) + (map n.inc) (map (function [idx] - [(symbol$ (Int/encode idx)) - (symbol$ (Int/encode (Int/negate idx)))]))) + (let [base (Nat/encode idx)] + [(symbol$ base) + (symbol$ (_lux_proc ["text" "append"] [base "'"]))])))) pattern (` [(~@ (map (function [[v vs]] (` (#;Cons (~ v) (~ vs)))) vars+lists))]) g!step (symbol$ "\tstep\t") @@ -376,32 +377,33 @@ _ (#;Left "Wrong syntax for zip"))) -(def: #export zip2 (zip 2)) -(def: #export zip3 (zip 3)) +(def: #export zip2 (zip +2)) +(def: #export zip3 (zip +3)) (macro: #export (zip-with tokens state) {#;doc (doc "Create list zippers with the specified number of input lists." - (def: #export zip2-with (zip-with 2)) - (def: #export zip3-with (zip-with 3)) - ((zip-with 2) i.+ xs ys))} + (def: #export zip2-with (zip-with +2)) + (def: #export zip3-with (zip-with +3)) + ((zip-with +2) i.+ xs ys))} (case tokens - (^ (list [_ (#;Int num-lists)])) - (if (i.> 0 num-lists) + (^ (list [_ (#;Nat num-lists)])) + (if (n.> +0 num-lists) (let [(^open) Functor<List> - indices (i.range 0 (i.dec num-lists)) + indices (n.range +0 (n.dec num-lists)) g!return-type (symbol$ "\treturn-type\t") g!func (symbol$ "\tfunc\t") - type-vars (: (List AST) (map (. symbol$ Int/encode) indices)) + type-vars (: (List AST) (map (. symbol$ Nat/encode) indices)) zip-type (` (All [(~@ type-vars) (~ g!return-type)] (-> (-> (~@ type-vars) (~ g!return-type)) (~@ (map (: (-> AST AST) (function [var] (` (List (~ var))))) type-vars)) (List (~ g!return-type))))) vars+lists (|> indices - (map i.inc) + (map n.inc) (map (function [idx] - [(symbol$ (Int/encode idx)) - (symbol$ (Int/encode (Int/negate idx)))]))) + (let [base (Nat/encode idx)] + [(symbol$ base) + (symbol$ (_lux_proc ["text" "append"] [base "'"]))])))) pattern (` [(~@ (map (function [[v vs]] (` (#;Cons (~ v) (~ vs)))) vars+lists))]) g!step (symbol$ "\tstep\t") @@ -422,8 +424,8 @@ _ (#;Left "Wrong syntax for zip-with"))) -(def: #export zip2-with (zip-with 2)) -(def: #export zip3-with (zip-with 3)) +(def: #export zip2-with (zip-with +2)) +(def: #export zip3-with (zip-with +3)) (def: #export (last xs) (All [a] (-> (List a) (Maybe a))) |