diff options
Diffstat (limited to 'stdlib/source/library/lux/data/collection/list.lux')
-rw-r--r-- | stdlib/source/library/lux/data/collection/list.lux | 169 |
1 files changed, 86 insertions, 83 deletions
diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index ba1902276..d29b0889a 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -454,85 +454,87 @@ 0 output' _ (again input' output'))))) -(macro: .public (zipped tokens state) - (case tokens - (pattern (list [_ {.#Nat num_lists}])) - (if (n.> 0 num_lists) - (let [(open "[0]") ..functor - indices (..indices num_lists) - type_vars (is (List Code) (each (|>> nat#encoded symbol$) indices)) - zipped_type (` (.All ((~ (symbol$ "0_")) (~+ type_vars)) - (-> (~+ (each (is (-> Code Code) (function (_ var) (` (List (~ var))))) - type_vars)) - (List [(~+ type_vars)])))) - vars+lists (|> indices - (each ++) - (each (function (_ idx) - (let [base (nat#encoded idx)] - [(symbol$ base) - (symbol$ ("lux text concat" base "'"))])))) - pattern (` [(~+ (each (function (_ [v vs]) (` {.#Item (~ v) (~ vs)})) - vars+lists))]) - g!step (symbol$ "0step0") - g!blank (symbol$ "0,0") - list_vars (each product.right vars+lists) - code (` (is (~ zipped_type) - (function ((~ g!step) (~+ list_vars)) - (case [(~+ list_vars)] - (~ pattern) - {.#Item [(~+ (each product.left vars+lists))] - ((~ g!step) (~+ list_vars))} - - (~ g!blank) - {.#End}))))] - {.#Right [state (list code)]}) - {.#Left "Cannot zipped 0 lists."}) - - _ - {.#Left "Wrong syntax for zipped"})) +(def: .public zipped + (macro (_ tokens state) + (case tokens + (pattern (list [_ {.#Nat num_lists}])) + (if (n.> 0 num_lists) + (let [(open "[0]") ..functor + indices (..indices num_lists) + type_vars (is (List Code) (each (|>> nat#encoded symbol$) indices)) + zipped_type (` (.All ((~ (symbol$ "0_")) (~+ type_vars)) + (-> (~+ (each (is (-> Code Code) (function (_ var) (` (List (~ var))))) + type_vars)) + (List [(~+ type_vars)])))) + vars+lists (|> indices + (each ++) + (each (function (_ idx) + (let [base (nat#encoded idx)] + [(symbol$ base) + (symbol$ ("lux text concat" base "'"))])))) + pattern (` [(~+ (each (function (_ [v vs]) (` {.#Item (~ v) (~ vs)})) + vars+lists))]) + g!step (symbol$ "0step0") + g!blank (symbol$ "0,0") + list_vars (each product.right vars+lists) + code (` (is (~ zipped_type) + (function ((~ g!step) (~+ list_vars)) + (case [(~+ list_vars)] + (~ pattern) + {.#Item [(~+ (each product.left vars+lists))] + ((~ g!step) (~+ list_vars))} + + (~ g!blank) + {.#End}))))] + {.#Right [state (list code)]}) + {.#Left "Cannot zipped 0 lists."}) + + _ + {.#Left "Wrong syntax for zipped"}))) (def: .public zipped_2 (zipped 2)) (def: .public zipped_3 (zipped 3)) -(macro: .public (zipped_with tokens state) - (case tokens - (pattern (list [_ {.#Nat num_lists}])) - (if (n.> 0 num_lists) - (let [(open "[0]") ..functor - indices (..indices num_lists) - g!return_type (symbol$ "0return_type0") - g!func (symbol$ "0func0") - type_vars (is (List Code) (each (|>> nat#encoded symbol$) indices)) - zipped_type (` (All ((~ (symbol$ "0_")) (~+ type_vars) (~ g!return_type)) - (-> (-> (~+ type_vars) (~ g!return_type)) - (~+ (each (is (-> Code Code) (function (_ var) (` (List (~ var))))) - type_vars)) - (List (~ g!return_type))))) - vars+lists (|> indices - (each ++) - (each (function (_ idx) - (let [base (nat#encoded idx)] - [(symbol$ base) - (symbol$ ("lux text concat" base "'"))])))) - pattern (` [(~+ (each (function (_ [v vs]) (` {.#Item (~ v) (~ vs)})) - vars+lists))]) - g!step (symbol$ "0step0") - g!blank (symbol$ "0,0") - list_vars (each product.right vars+lists) - code (` (is (~ zipped_type) - (function ((~ g!step) (~ g!func) (~+ list_vars)) - (case [(~+ list_vars)] - (~ pattern) - {.#Item ((~ g!func) (~+ (each product.left vars+lists))) - ((~ g!step) (~ g!func) (~+ list_vars))} - - (~ g!blank) - {.#End}))))] - {.#Right [state (list code)]}) - {.#Left "Cannot zipped_with 0 lists."}) - - _ - {.#Left "Wrong syntax for zipped_with"})) +(def: .public zipped_with + (macro (_ tokens state) + (case tokens + (pattern (list [_ {.#Nat num_lists}])) + (if (n.> 0 num_lists) + (let [(open "[0]") ..functor + indices (..indices num_lists) + g!return_type (symbol$ "0return_type0") + g!func (symbol$ "0func0") + type_vars (is (List Code) (each (|>> nat#encoded symbol$) indices)) + zipped_type (` (All ((~ (symbol$ "0_")) (~+ type_vars) (~ g!return_type)) + (-> (-> (~+ type_vars) (~ g!return_type)) + (~+ (each (is (-> Code Code) (function (_ var) (` (List (~ var))))) + type_vars)) + (List (~ g!return_type))))) + vars+lists (|> indices + (each ++) + (each (function (_ idx) + (let [base (nat#encoded idx)] + [(symbol$ base) + (symbol$ ("lux text concat" base "'"))])))) + pattern (` [(~+ (each (function (_ [v vs]) (` {.#Item (~ v) (~ vs)})) + vars+lists))]) + g!step (symbol$ "0step0") + g!blank (symbol$ "0,0") + list_vars (each product.right vars+lists) + code (` (is (~ zipped_type) + (function ((~ g!step) (~ g!func) (~+ list_vars)) + (case [(~+ list_vars)] + (~ pattern) + {.#Item ((~ g!func) (~+ (each product.left vars+lists))) + ((~ g!step) (~ g!func) (~+ list_vars))} + + (~ g!blank) + {.#End}))))] + {.#Right [state (list code)]}) + {.#Left "Cannot zipped_with 0 lists."}) + + _ + {.#Left "Wrong syntax for zipped_with"}))) (def: .public zipped_with_2 (zipped_with 2)) (def: .public zipped_with_3 (zipped_with 3)) @@ -606,15 +608,16 @@ {.#Item x xs'} {.#Item [idx x] (again (++ idx) xs')}))) -(macro: .public (when tokens state) - (case tokens - (pattern (.list test then)) - {.#Right [state (.list (` (.if (~ test) - (~ then) - (.list))))]} +(def: .public when + (macro (_ tokens state) + (case tokens + (pattern (.list test then)) + {.#Right [state (.list (` (.if (~ test) + (~ then) + (.list))))]} - _ - {.#Left "Wrong syntax for when"})) + _ + {.#Left "Wrong syntax for when"}))) (def: .public (revised item revision it) (All (_ a) (-> Nat (-> a a) (List a) (List a))) |