From cd5a8e1a266b953b38384b6f74de07cb7f3c9874 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 6 Jun 2024 05:23:45 -0400 Subject: [PATCH] Adapting to new `List` type (part 33). --- stdlib/source/library/lux.lux | 555 +++++++++--------- .../lux/compiler/language/lux/syntax.lux | 2 +- .../library/lux/compiler/meta/packager.lux | 2 +- .../lux/compiler/meta/packager/ruby.lux | 28 +- stdlib/source/library/lux/control/pattern.lux | 24 +- .../library/lux/data/collection/stream.lux | 148 +++-- stdlib/source/library/lux/ffi.jvm.lux | 6 - stdlib/source/library/lux/ffi.lux | 21 +- stdlib/source/library/lux/ffi/export.js.lux | 17 +- stdlib/source/library/lux/ffi/export.rb.lux | 1 - stdlib/source/library/lux/web/html.lux | 51 +- stdlib/source/program/compositor.lux | 26 +- stdlib/source/projection/lux/data/text.lux | 39 +- .../source/test/lux/abstract/comonad/free.lux | 4 +- stdlib/source/test/lux/color/terminal.lux | 16 +- .../test/lux/data/collection/stream.lux | 83 ++- stdlib/source/test/lux/music/chord.lux | 11 +- stdlib/source/test/lux/type/implicit.lux | 6 +- .../source/test/lux/world/net/http/cookie.lux | 27 +- 19 files changed, 536 insertions(+), 531 deletions(-) diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index a3666fcbe3..4dff7e6a6b 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -905,9 +905,9 @@ (failure ..wrong_syntax)))) ..private) -(.def# code#function +(.def# 'function# (.is# (Function Code (Function {#Reification Code Stack} (Function Code Code))) - (.function# code#function self + (.function# 'function# self (.function# _ inputs (.function# _ output (.when# inputs @@ -918,7 +918,7 @@ (code#form (list (code#name [..prelude "function#"]) self head - (code#function (code#name ["" ""]) tail output)))))))) + ('function# (code#name ["" ""]) tail output)))))))) ..private) (.def# function' @@ -929,7 +929,7 @@ body) (.when# (list#as_stack self,arguments) {#Top self arguments} - (meta#in (list (code#function self arguments body))) + (meta#in (list ('function# self arguments body))) else (failure ..wrong_syntax)) @@ -969,8 +969,8 @@ {#Top name arguments} (meta#in (list (code#def name (code#is type - (code#function name arguments - body)) + ('function# name arguments + body)) export_policy))) else @@ -997,6 +997,28 @@ co_domain)))))))) ..private) +(.def# 'Bit + (.is# Code + (code#name [..prelude "Bit"])) + ..private) + +(.def# 'Predicate + (.is# (Function Code Code) + (function' (_ it) + ('Function it 'Bit))) + ..private) + +(.def# Predicate + (.as# (Function Macro' Macro) + (function' (_ tokens) + (.when# tokens + (.list# it) + (meta#in (list ('Predicate it))) + + _ + (failure ..wrong_syntax)))) + ..private) + (.def# 'as# (.is# (Function Code (Function Code Code)) (function' (_ 'coercion 'it) @@ -1005,7 +1027,7 @@ 'it)))) ..private) -(.def# code#macro +(.def# 'macro (.is# (Function Code Code) (function' (_ expression) @@ -1021,7 +1043,7 @@ (.list# {#Form _ name,arguments} body) (.when# (list#as_stack name,arguments) {#Top name arguments} - (meta#in (list (code#macro (code#function name arguments body)))) + (meta#in (list ('macro ('function# name arguments body)))) else (failure ..wrong_syntax)) @@ -1078,17 +1100,6 @@ {#Empty} stack)) -(the' .private (stack#each f xs) - {#Quantification .universal {#Empty} - {#Quantification .universal {#Empty} - (Function (Function {#Parameter ..argument 1} {#Parameter ..argument 0}) - (Function ($ Stack {#Parameter ..argument 1}) - ($ Stack {#Parameter ..argument 0})))}} - (stack#mix (function' (_ head tail) - {#Top (f head) tail}) - {#Empty} - (stack#reversed xs))) - (the' .private (list#mix' mix complete partial) ... (for_any (_ a b) (-> (-> Natural b a a) a (List b) a)) {#Quantification .universal {#Empty} @@ -1452,8 +1463,7 @@ body))) (the' .private (initialized_quantification? lux) - (Function Lux - Bit) + (Predicate Lux) (.when# lux [..#info _ ..#source _ ..#current_module _ ..#modules _ ..#scopes scopes ..#type_context _ @@ -1989,6 +1999,46 @@ Macro') (.as# (-> Spliced_UnQuote Macro') it)) +(the' .private (list#one choice it) + (for_any (_ input output) + (-> (-> input ($ Maybe output)) + (-> ($ List input) ($ Maybe output)))) + (.when# (.list_size# it) + limit + ((.is# (for_any (_ input output) + (-> (-> input ($ Maybe output)) ($ List input) + (-> Natural ($ Maybe output)))) + (function' (_ choice it) + (function' (list#one item) + (if (.int_<# (.as# (-> Natural Integer) limit) + (.as# (-> Natural Integer) item)) + (.when# (choice (.list_item# item it)) + {#None} + (list#one (.i64_+# 1 item)) + + choice + choice) + {#None})))) + choice it 0))) + +(the' .private list#conjoint + (for_any (_ it) + (-> ($ List ($ List it)) + ($ List it))) + (list#mix' (function' (_ _ right left) + (.list_composite# left right)) + (list))) + +(the' .private (list#all choice it) + (for_any (_ input output) + (-> (-> input ($ Maybe output)) + (-> ($ List input) ($ List output)))) + (list#conjoint (list#each (function' (_ it) + (.when# (choice it) + {#None} (list) + {#Some it} (list it))) + it))) + (the' .private (stack#one f xs) (for_any (_ input output) (-> (-> input ($ Maybe output)) ($ Stack input) @@ -2005,12 +2055,6 @@ {#Some y} {#Some y}))) -(the' .private (list#one f xs) - (for_any (_ input output) - (-> (-> input ($ Maybe output)) ($ List input) - ($ Maybe output))) - (stack#one f (list#as_stack xs))) - (the' .private (in_env name state) (-> Text Lux ($ Maybe Type)) @@ -2110,36 +2154,64 @@ #0)) (the' .private (bit#= reference it) - (-> Bit Bit - Bit) + (-> Bit + (Predicate Bit)) (if reference it (not it))) (the' .private (name#= left right) - (-> Name Name - Bit) + (-> Name + (Predicate Name)) (let' [[moduleL properL] left [moduleR properR] right] (all and' (.text_=# moduleL moduleR) (.text_=# properL properR)))) -(the' .private (stack#every? ?) +(the' .private (list#every? ?) (for_any (_ it) - (-> (-> it Bit) - (-> ($ Stack it) Bit))) - (stack#mix (function' (_ _2 _1) + (-> (Predicate it) + (Predicate ($ List it)))) + (list#mix' (function' (_ _ _2 _1) (if _1 (? _2) #0)) #1)) -(the' .private (list#every? ?) +(the' .private (natural#minor left right) + (-> Natural Natural + Natural) + (if (.int_<# (.as# (-> Natural Integer) left) + (.as# (-> Natural Integer) right)) + right + left)) + +(the' .private (list#zipped_2 left right) + (for_any (_ left right) + (-> ($ List left) ($ List right) + ($ List (Tuple left right)))) + (.when# (natural#minor (.list_size# left) (.list_size# right)) + limit + ((.is# (for_any (_ left right) + (-> ($ List left) ($ List right) + (-> Natural ($ Change ($ List (Tuple left right)))))) + (function' (_ left right) + (function' (list#zipped_2 item output) + (if (.int_<# (.as# (-> Natural Integer) limit) + (.as# (-> Natural Integer) item)) + (list#zipped_2 (.i64_+# 1 item) + (.list_composite# output + (list [(.list_item# item left) + (.list_item# item right)]))) + output)))) + left right 0 (list)))) + +(the' .private (stack#every? ?) (for_any (_ it) - (-> (-> it Bit) ($ List it) - Bit)) - (list#mix' (function' (_ _ _2 _1) + (-> (Predicate it) + (Predicate ($ Stack it)))) + (stack#mix (function' (_ _2 _1) (if _1 (? _2) #0)) @@ -2161,15 +2233,9 @@ _ (stack))) -(the' .private (list#zipped_2 xs ys) - (for_any (_ left right) - (-> ($ List left) ($ List right) - ($ List (Tuple left right)))) - (list#of_stack (stack#zipped_2 (list#as_stack xs) (list#as_stack ys)))) - (the' .private (type#= left right) - (-> Type Type - Bit) + (-> Type + (Predicate Type)) (.when# [left right] [{#Nominal nameL parametersL} {#Nominal nameR parametersR}] (all and' @@ -2699,8 +2765,8 @@ (.i64_and# low_mask value)) (the' .private (n#< reference it) - (-> Natural Natural - Bit) + (-> Natural + (Predicate Natural)) (let' [referenceH (high_bits reference) itH (high_bits it)] (if (.int_<# referenceH itH) @@ -2760,14 +2826,6 @@ _ template)) -(the' .private list#conjoint - (for_any (_ it) - (-> ($ List ($ List it)) - ($ List it))) - (list#mix' (function' (_ _ right left) - (.list_composite# left right)) - (list))) - (the' .private with_template Macro (macro (_ tokens) @@ -3920,8 +3978,7 @@ (failure ..wrong_syntax)))) (the' .private (name? code) - (type (-> Code - Bit)) + (Predicate Code) (when code {#Name _ _} #1 @@ -4058,22 +4115,7 @@ _ (failure ..wrong_syntax)))) -(the (text#all_split_by splitter input) - (-> Text Text - (Stack Text)) - (when (.text_index# 0 splitter input) - {#None} - (stack input) - - {#Some idx} - (stack#partial (.text_clip# 0 idx input) - (text#all_split_by splitter - (let [after_offset (.i64_+# 1 idx) - after_length (.i64_-# after_offset - (.text_size# input))] - (.text_clip# after_offset after_length input)))))) - -(the (item idx xs) +(the (stack#item idx xs) (for_any (_ it) (-> Natural (Stack it) (Maybe it))) @@ -4084,12 +4126,12 @@ {#Top x xs'} (if (.i64_=# 0 idx) {#Some x} - (item (.i64_-# 1 idx) xs')))) + (stack#item (.i64_-# 1 idx) xs')))) ... https://en.wikipedia.org/wiki/Lambda_calculus#%CE%B2-reduction (the (reduced env type) - (-> (Stack [Type Type]) Type - Type) + (-> (Stack [Type Type]) + (Change Type)) (when type {#Nominal name parameters} {#Nominal name (list#each (function (_ [polarity it]) @@ -4108,7 +4150,7 @@ type) {#Parameter parameter idx} - (when (item idx env) + (when (stack#item idx env) {#Some [abstraction argument]} (when parameter .abstraction abstraction @@ -4121,8 +4163,7 @@ (reduced env type) _ - type - )) + type)) (the (applied_type param type_fn) (-> Type Type @@ -4221,33 +4262,26 @@ ..#definitions definitions ..#imports _ ..#module_state _] module]] - (in ((is (-> (Stack [Text [Bit Global]]) - (Maybe (List Name))) - (function (again remaining) - (when remaining - {#Top [slot head] tail} - (when head - [exported? {#Definition [type value]}] - (if (and (type#= Slot type) - (or exported? - (.text_=# expected_module actual_module))) - (let [[label actual_record] (as (-> Any Label) value)] - (if (type#= expected_record actual_record) - {#Some (when label - {#Some [lefts right? family]} - family - - {#None} - (list [expected_module slot]))} - (again tail))) - (again tail)) - - _ - (again tail)) + (in (list#one (function (_ [slot head]) + (when head + [exported? {#Definition [type value]}] + (if (and (type#= Slot type) + (or exported? + (.text_=# expected_module actual_module))) + (let [[label actual_record] (as (-> Any Label) value)] + (if (type#= expected_record actual_record) + {#Some (when label + {#Some [lefts right? family]} + family + + {#None} + (list [expected_module slot]))} + {#None})) + {#None}) - {#Empty} - {#None}))) - (list#as_stack definitions))))) + _ + {#None})) + definitions)))) (the (every_slot type) (-> Type @@ -4395,19 +4429,6 @@ (list#conjoint tokens'))] (in (list (code#tuple (list#conjoint members))))))) -(the (text#interposed delimiter parts) - (-> Text (Stack Text) - Text) - (when parts - {#Empty} - "" - - {#Top head tail} - (stack#mix (function (_ right left) - (text left delimiter right)) - head - tail))) - (the ?#case (Projection [Text Code]) (?#variant (?#and ?#local @@ -4509,31 +4530,30 @@ (the (label_definitions module export_policy associated_type label_type family labels) (-> Text Code Code Code Code (List Text) - (Stack Code)) - (when (list#as_stack (list#reversed labels)) - (stack single) - (stack (` (the (, export_policy) (, (code#local single)) - (<| (as (-> Label (, label_type))) - [{#None} (, associated_type)])))) - - (stack#partial right lefts) - (stack#partial - (` (the (, family) - (List Name) - (list (,* (list#each (function (_ it) - (` [(, (code#text module)) (, (code#text it))])) - labels))))) - (` (the (, export_policy) (, (code#local right)) - (<| (as (-> Label (, label_type))) - [{#Some [(, (code#natural (.i64_-# 1 (stack#size lefts)))) #1 (, family)]} (, associated_type)]))) - (list#as_stack (list#each (function (_ [lefts it]) - (` (the (, export_policy) (, (code#local it)) - (<| (as (-> Label (, label_type))) - [{#Some [(, (code#natural lefts)) #0 (, family)]} (, associated_type)])))) - (enumeration (list#reversed (list#of_stack lefts)))))) + (List Code)) + (when (list#split 1 (list#reversed labels)) + [(list single) (list)] + (list (` (the (, export_policy) (, (code#local single)) + (<| (as (-> Label (, label_type))) + [{#None} (, associated_type)])))) + + [(list right) lefts] + (.list_composite# (list (` (the (, family) + (List Name) + (list (,* (list#each (function (_ it) + (` [(, (code#text module)) (, (code#text it))])) + labels))))) + (` (the (, export_policy) (, (code#local right)) + (<| (as (-> Label (, label_type))) + [{#Some [(, (code#natural (.i64_-# 1 (.list_size# lefts)))) #1 (, family)]} (, associated_type)])))) + (list#each (function (_ [lefts it]) + (` (the (, export_policy) (, (code#local it)) + (<| (as (-> Label (, label_type))) + [{#Some [(, (code#natural lefts)) #0 (, family)]} (, associated_type)])))) + (enumeration (list#reversed lefts)))) _ - (stack))) + (list))) ... https://en.wikipedia.org/wiki/List_of_English_determiners (the .public every @@ -4566,13 +4586,13 @@ (, itC)))]] (in (when labels?? {#Some labels} - (list#of_stack (stack#partial type_definition - (when labels - {#Left tags} - (label_definitions module_name export_policy type_name (` Tag) 'cohort tags) - - {#Right slots} - (label_definitions module_name export_policy type_name (` Slot) 'cohort slots)))) + (.list_composite# (list type_definition) + (when labels + {#Left tags} + (label_definitions module_name export_policy type_name (` Tag) 'cohort tags) + + {#Right slots} + (label_definitions module_name export_policy type_name (` Slot) 'cohort slots))) _ (list type_definition)))) @@ -4648,15 +4668,18 @@ Text) (text "[" (natural#as index) "]")) +(the Context_Of_Module + (type (Stack Text))) + (the (module_alias context aliased) - (-> (Stack Text) Text + (-> Context_Of_Module Text Text) - (product#right - (stack#mix (function (_ replacement [index aliased]) - [(.i64_+# 1 index) - (replaced (alias_stand_in index) replacement aliased)]) - [0 aliased] - context))) + (|> context + (stack#mix (function (_ replacement [index aliased]) + [(.i64_+# 1 index) + (replaced (alias_stand_in index) replacement aliased)]) + [0 aliased]) + product#right)) ... https://en.wikipedia.org/wiki/Delimiter (the .public module_delimiter @@ -4729,17 +4752,33 @@ _ (failure ..wrong_syntax))))) -(the (stack#after amount stack) - (for_any (_ it) - (-> Natural (Stack it) - (Stack it))) - (when [amount stack] - (^#or [0 _] - [_ {#Empty}]) - stack +(the (text#interposed delimiter parts) + (-> Text (List Text) + Text) + (when (list#split 1 parts) + [(list head) tail] + (list#mix (function (_ right left) + (text left delimiter right)) + head + tail) + + else + "")) + +(the (text#all_split_by splitter input) + (-> Text Text + (List Text)) + (when (.text_index# 0 splitter input) + {#None} + (list input) - [_ {#Top _ tail}] - (stack#after (.i64_-# 1 amount) tail))) + {#Some idx} + (.list_composite# (list (.text_clip# 0 idx input)) + (text#all_split_by splitter + (let [after_offset (.i64_+# 1 idx) + after_length (.i64_-# after_offset + (.text_size# input))] + (.text_clip# after_offset after_length input)))))) (the (absolute_module_name nested? relative_root module) (-> Bit Text Text @@ -4753,11 +4792,11 @@ relatives (let [parts (text#all_split_by ..module_delimiter relative_root) jumps (.i64_-# 1 relatives)] - (if (n#< (stack#size parts) jumps) + (if (n#< (.list_size# parts) jumps) (let [prefix (|> parts - stack#reversed - (stack#after jumps) - stack#reversed + list#reversed + (list#after jumps) + list#reversed (text#interposed ..module_delimiter)) clean (.text_clip# relatives (|> module .text_size# (.i64_-# relatives)) module) output (when (.text_size# clean) @@ -4769,7 +4808,7 @@ " Relative Root: " relative_root \n)))))) (the (imports_of nested? relative_root context imports) - (-> Bit Text (Stack Text) (List Code) + (-> Bit Text Context_Of_Module (List Code) (Meta (List Importation))) (do meta#monad [imports' (monad#each meta#monad @@ -4874,7 +4913,7 @@ (the (stack#only p xs) (for_any (_ it) - (-> (-> it Bit) + (-> (Predicate it) (Change (Stack it)))) (when xs {#Empty} @@ -4885,18 +4924,9 @@ {#Top x (stack#only p xs')} (stack#only p xs')))) -(the (list#only predicate it) - (for_any (_ it) - (-> (-> it Bit) - (Change (List it)))) - (|> it - list#as_stack - (stack#only predicate) - list#of_stack)) - (the (list#member? whens name) (-> (List Text) - (-> Text Bit)) + (Predicate Text)) (list#mix (function (_ when prev) (or prev (.text_=# when name))) @@ -4956,6 +4986,15 @@ (<| (,* tokens) (, 'arg))))))))) +(the (list#only predicate it) + (for_any (_ it) + (-> (Predicate it) + (Change (List it)))) + (|> it + list#as_stack + (stack#only predicate) + list#of_stack)) + (the .public except (macro (_ tokens) (when (?#value tokens @@ -5022,6 +5061,15 @@ {#None}))) 0))) +(the (stack#each value it) + (for_any (_ cause effect) + (-> (-> cause effect) + (-> (Stack cause) (Stack effect)))) + (stack#mix (function' (_ head tail) + {#Top (value head) tail}) + {#Empty} + (stack#reversed it))) + (the (clean_type variables it) (-> (List [Natural (Maybe Type)]) (Change Type)) @@ -5100,28 +5148,12 @@ _ temp))))) -(the (stack#all choice items) - (for_any (_ input output) - (-> (-> input (Maybe output)) (Stack input) - (Stack output))) - (when items - {#Top head tail} - (when (choice head) - {#Some head} - {#Top head (stack#all choice tail)} - - {#None} - (stack#all choice tail)) - - {#Empty} - {#Empty})) - (every Implementation_Interface [(List Name) (List Type)]) (the (open_layer alias [tags members]) (-> Text Implementation_Interface - (Meta [Code (Stack [Name Implementation_Interface])])) + (Meta [Code (List [Name Implementation_Interface])])) (do meta#monad [pattern (monad#each meta#monad (function (_ [slot slot_type]) @@ -5129,19 +5161,19 @@ [.let [[_ slot_name] slot local ["" (..module_alias (stack slot_name) alias)]] implementation (every_slot slot_type)] - (in [(stack (code#name slot) - (code#name local)) + (in [(list (code#name slot) + (code#name local)) [local implementation]]))) (list#zipped_2 tags members))] (in [(|> pattern - (list#each (|>> product#left list#of_stack)) + (list#each product#left) list#conjoint code#tuple) - (stack#all (function (_ [_ [sub_binding sub_implementation]]) - (do maybe#monad - [sub_implementation sub_implementation] - (in [sub_binding sub_implementation]))) - (list#as_stack pattern))]))) + (list#all (function (_ [_ [sub_binding sub_implementation]]) + (do maybe#monad + [sub_implementation sub_implementation] + (in [sub_binding sub_implementation]))) + pattern)]))) (the (open_layers alias interfaces body) (-> Text (List Implementation_Interface) Code @@ -5150,7 +5182,7 @@ [layer (monad#each meta#monad (open_layer alias) interfaces) .let [pattern (code#tuple (list#each product#left layer)) next (|> layer - (list#each (|>> product#right list#of_stack)) + (list#each product#right) list#conjoint)]] (when next (list) @@ -5201,39 +5233,6 @@ else (failure ..wrong_syntax))))) -(every (Try it) - (Variant - {#Failure Text} - {#Success it})) - -(the .public cannot_access - Error - (provenance#with (provenance#here) - "Cannot synthesize access pattern.")) - -(the (access_pattern '_ 'output lefts right? members) - (-> Code Code Natural Bit (Stack Type) - (Try (Stack Code))) - (when ((is (-> Natural (Stack Type) (Stack Code) - (Stack Code)) - (function (again index input output) - (when input - (stack#partial head tail) - (if (.i64_=# index (if right? - (.i64_+# 1 lefts) - lefts)) - (stack#reversed (stack#partial 'output output)) - (again (.i64_+# 1 index) tail (stack#partial '_ output))) - - (stack) - (stack)))) - 0 members (stack)) - (stack) - {#Failure ..cannot_access} - - pattern - {#Success pattern})) - (the .public its (macro (_ tokens) (when tokens @@ -5368,31 +5367,31 @@ {#Right implementations} (do meta#monad - [pre_defs,implementations (is (Meta [(Stack Code) (Stack Code)]) + [pre_defs,implementations (is (Meta [(List Code) (List Code)]) (monad#mix meta#monad (function (_ it [pre_defs implementations]) (when it {#Name _ _} (in [pre_defs - {#Top it implementations}]) + (.list_composite# (list it) implementations)]) _ (do meta#monad ['implementation (..generated_name "implementation")] - (in [{#Top (` (.def# (, 'implementation) (, it) ..private)) pre_defs} - {#Top 'implementation implementations}])))) - [(stack) (stack)] + (in [(.list_composite# (list (` (.def# (, 'implementation) (, it) ..private))) + pre_defs) + (.list_composite# (list 'implementation) implementations)])))) + [(list) (list)] implementations)) .let [[pre_defs implementations] pre_defs,implementations]] (in (|> pre_defs - {#Top (` (..use - (, (code#text current_module)) - (, (code#text imported_module)) - (, (code#text import_alias)) - (, (code#text alias)) - (,* (list#of_stack implementations))))} - stack#reversed - list#of_stack))))) + (.list_composite# (list (` (..use + (, (code#text current_module)) + (, (code#text imported_module)) + (, (code#text import_alias)) + (, (code#text alias)) + (,* implementations))))) + list#reversed))))) {#None} (failure ..wrong_syntax)))) @@ -5816,7 +5815,7 @@ (the .public (same? expected actual) (for_any (_ it) (-> it - (-> it Bit))) + (Predicate it))) (.is?# expected actual)) (the .public as_expected @@ -6005,33 +6004,35 @@ (function (_ it) (do meta#monad [it (eval Target it)] - (in (as (-> Any Target) it))))) - target_pick (is (-> Text (Stack [Code Code]) (Maybe Code) - (Meta (List Code))) - (function (target_pick target options default) - (when options - {#Empty} - (when default - {#None} - (failure (text "No code for target platform: " target)) - - {#Some default} - (meta#in (list default))) - - {#Top [key pick] options'} - (do meta#monad - [platform (platform_name key)] - (if (.text_=# target platform) - (meta#in (list pick)) - (target_pick target options' default))))))] + (in (as (-> Any Target) it)))))] (macro (_ tokens) (when (?#value tokens (?#and (?#some (?#and ?#any ?#any)) (?#maybe ?#any))) {#Some [options default]} (do meta#monad - [target target] - (target_pick target (list#as_stack options) default)) + [target target + options (monad#each meta#monad + (function (_ [platform pick]) + (do meta#monad + [platform (platform_name platform)] + (in [platform pick]))) + options)] + (when (list#one (function (_ [platform pick]) + (if (.text_=# target platform) + {#Some pick} + {#None})) + options) + {#Some pick} + (meta#in (list pick)) + + {#None} + (when default + {#Some default} + (meta#in (list default)) + + {#None} + (failure (text "No code for target platform: " target))))) {#None} (failure ..wrong_syntax))))) diff --git a/stdlib/source/library/lux/compiler/language/lux/syntax.lux b/stdlib/source/library/lux/compiler/language/lux/syntax.lux index 2e87311509..6fd524f132 100644 --- a/stdlib/source/library/lux/compiler/language/lux/syntax.lux +++ b/stdlib/source/library/lux/compiler/language/lux/syntax.lux @@ -607,7 +607,7 @@ (..failure source' error) (if (same? error) - (..success source' { where (list.of_stack (stack.reversed stack))}) + (..success source' { where (list.reversed (list.of_stack stack))}) (..failure source' error)))))] ... Form and tuple syntax is mostly the same, differing only in the diff --git a/stdlib/source/library/lux/compiler/meta/packager.lux b/stdlib/source/library/lux/compiler/meta/packager.lux index c5e98196fc..79974f39b8 100644 --- a/stdlib/source/library/lux/compiler/meta/packager.lux +++ b/stdlib/source/library/lux/compiler/meta/packager.lux @@ -28,7 +28,7 @@ (every .public Packager (-> (Dictionary file.Path Binary) Archive (Maybe unit.ID) (Try (Either Binary - (Stack [Text Binary]))))) + (List [Text Binary]))))) (every .public Order (List [module.ID (List artifact.ID)])) diff --git a/stdlib/source/library/lux/compiler/meta/packager/ruby.lux b/stdlib/source/library/lux/compiler/meta/packager/ruby.lux index 8be42397a5..7735c2a4f5 100644 --- a/stdlib/source/library/lux/compiler/meta/packager/ruby.lux +++ b/stdlib/source/library/lux/compiler/meta/packager/ruby.lux @@ -18,7 +18,6 @@ [collection ["[0]" sequence] ["[0]" list (.use "[1]#[0]" functor mix monoid)] - ["[0]" stack (.use "[1]#[0]" functor mix)] ["[0]" dictionary (.only Dictionary)] ["[0]" set (.only Set)]]] [math @@ -78,14 +77,16 @@ (in {.#Some bundle}))))) (the module_file - (-> module.ID file.Path) - (|>> %.natural (text.suffix ".rb"))) + (-> module.ID + file.Path) + (|>> %.natural + (text.suffix ".rb"))) (the (write_module mapping necessary_dependencies [module [module_id entry]] sink) (-> (Dictionary descriptor.Module module.ID) (Set unit.ID) [descriptor.Module [module.ID (archive.Entry .Module)]] - (Stack [module.ID [Text Binary]]) - (Try (Stack [module.ID [Text Binary]]))) + (-> (List [module.ID [Text Binary]]) + (Try (List [module.ID [Text Binary]])))) (do [! try.monad] [bundle (is (Try (Maybe _.Statement)) (..bundle_module module module_id necessary_dependencies (its archive.#output entry)))] @@ -99,8 +100,8 @@ (is _.Statement) _.code (by utf8.binary as))] - (in (stack.partial [module_id [(..module_file module_id) entry_content]] - sink)))))) + (in (list#composite (list [module_id [(..module_file module_id) entry_content]]) + sink)))))) (the .public main_file "main.rb") @@ -114,10 +115,10 @@ (the included_modules (for_any (_ it) - (-> (Stack [module.ID it]) + (-> (List [module.ID it]) (Set module.ID))) - (|>> (stack#each product.left) - (stack#mix set.has (set.empty natural.hash)))) + (|>> (list#each product.left) + (set.of_list natural.hash))) (the .public (package host_dependencies archive program) Packager @@ -126,7 +127,8 @@ order (cache/module.load_order $.key archive) entries (list.mix' ! (..write_module (module_id_mapping order) necessary_dependencies) - {.#Empty} + (is (List [module.ID [Text Binary]]) + (list)) order) .let [included_modules (..included_modules entries) imports (|> order @@ -144,6 +146,6 @@ _.code (by utf8.binary as))]] (in (|> entries - (stack#each product.right) - {.#Top [..main_file imports]} + (list#each product.right) + (list#composite (list [..main_file imports])) {.#Right})))) diff --git a/stdlib/source/library/lux/control/pattern.lux b/stdlib/source/library/lux/control/pattern.lux index 10dcf4ba7c..7bf5806b1c 100644 --- a/stdlib/source/library/lux/control/pattern.lux +++ b/stdlib/source/library/lux/control/pattern.lux @@ -125,12 +125,12 @@ (the .public (complex value) Complex - (function (_ then else stack) - (then (..consuming value stack)))) + (function (_ then else focus) + (then (..consuming value focus)))) (the .public failure Body - (function (_ then else stack) + (function (_ then else focus) (else (..empty)))) (the .public (try left right) @@ -138,19 +138,19 @@ (type.let [choice (Body arity_1 arity_0 value)] (-> choice choice choice))) - (function (_ then else stack) + (function (_ then else focus) (left then (function (_ _) - (right then else stack)) - stack))) + (right then else focus)) + focus))) (the .public (composite left right) (for_any (_ arity_0 arity_1 arity_2 value) (-> (Body arity_1 arity_0 value) (Body arity_2 arity_1 value) (Body arity_2 arity_0 value))) - (function (_ then else stack) - (right (left then else) else stack))) + (function (_ then else focus) + (right (left then else) else focus))) ... Pattern (every .public (Pattern composition input outer inner value) @@ -234,8 +234,8 @@ (loop (item [address 0]) (if (natural.< size address) (..try (match (.list_item# address input)) - (function (_ then else stack) - ((item (++ address)) then else stack))) + (function (_ then else focus) + ((item (++ address)) then else focus))) ..failure))))])) (every .public (Static it) @@ -259,8 +259,8 @@ [..same (function (_ input) (if (predicate input) - ..success - ..failure))]) + ..success + ..failure))]) (the .public (constant = expected) (for_any (_ it) diff --git a/stdlib/source/library/lux/data/collection/stream.lux b/stdlib/source/library/lux/data/collection/stream.lux index 3a36da87a3..82ae071985 100644 --- a/stdlib/source/library/lux/data/collection/stream.lux +++ b/stdlib/source/library/lux/data/collection/stream.lux @@ -11,12 +11,11 @@ [control ["//" continuation (.only Cont)]] [function - ["[0]" predicate]] + ["[0]" predicate (.only Predicate)]] [data [collection ["[0]" list (.use "[1]#[0]" monad monoid) - ["?[1]" \\projection]] - ["[0]" stack (.use "[1]#[0]" monad)]]] + ["?[1]" \\projection]]]] [math [number ["n" natural]]] @@ -27,95 +26,118 @@ ["[0]" code (.only) ["<[1]>" \\projection]]]]]) -(every .public (Stream a) - (Cont [a (Stream a)])) +(every .public (Stream it) + (Cont [it (Stream it)])) (the .public (iterations step init) - (for_any (_ a b) - (-> (-> a [a b]) a (Stream b))) + (for_any (_ state it) + (-> (-> state [state it]) + (-> state (Stream it)))) (let [[next x] (step init)] (//.pending [x (iterations step next)]))) -(the .public (repeated x) - (for_any (_ a) - (-> a (Stream a))) - (//.pending [x (repeated x)])) +(the .public (repeated it) + (for_any (_ it) + (-> it + (Stream it))) + (//.pending [it (repeated it)])) (the .public (cycle [start next]) - (for_any (_ a) - (-> [a (Stack a)] (Stream a))) - (loop (again [head start - tail next]) - (//.pending [head (when tail - {.#Empty} - (again start next) - - {.#Top head' tail'} - (again head' tail'))]))) + (for_any (_ it) + (-> [it (List it)] + (Stream it))) + (let [limit (list.size next)] + (loop (cycle [head start + tail limit]) + (//.pending [head (if (n.= limit tail) + (cycle start 0) + (cycle (.list_item# tail next) (++ tail)))])))) (template.with [ ] [(the .public ( stream) - (for_any (_ a) (-> (Stream a) )) + (for_any (_ it) + (-> (Stream it) + )) (let [[head tail] (//.value stream)] ))] - [head a] - [tail (Stream a)] + [head it] + [tail (Stream it)] ) (the .public (item idx stream) - (for_any (_ a) (-> Natural (Stream a) a)) + (for_any (_ it) + (-> Natural (Stream it) + it)) (let [[head tail] (//.value stream)] (when idx 0 head _ (item (-- idx) tail)))) -(template.with [ ] - [(the .public ( pred xs) - (for_any (_ a) - (-> (Stream a) (Stack a))) - (let [[x xs'] (//.value xs)] - (if ( ) - (stack.partial x ( xs')) - (stack)))) - - (the .public ( pred xs) - (for_any (_ a) - (-> (Stream a) (Stream a))) - (let [[x xs'] (//.value xs)] - (if ( ) - ( xs') - xs)))] - - [while until (-> a Bit) (pred x) pred |>] - [first after Natural (n.= 0 pred) (-- pred) not] - ) - -(template.with [ ] - [(the .public ( pred xs) - (for_any (_ a) - (-> (Stream a) [(Stack a) (Stream a)])) - (let [[x xs'] (//.value xs)] - (if - [(stack) xs] - (let [[tail next] ( xs')] - [{.#Top [x tail]} next]))))] - - [split_when (-> a Bit) (pred x) pred] - [split_at Natural (n.= 0 pred) (-- pred)] - ) +(the .public (split_when ? it) + (for_any (_ it) + (-> (Predicate it) (Stream it) + [(List it) (Stream it)])) + (let [[stream list] (list.dynamic (function (_ it) + (let [[head tail] (//.value it)] + (if (? head) + {.#None} + {.#Some [tail head]}))) + it)] + [list stream])) + +(the .public (while ? it) + (for_any (_ it) + (-> (Predicate it) (Stream it) + (List it))) + (let [[list stream] (split_when (predicate.not ?) it)] + list)) + +(the .public (until ? it) + (for_any (_ it) + (-> (Predicate it) + (Change (Stream it)))) + (let [[list stream] (split_when ? it)] + stream)) + +(the .public (split_at amount it) + (for_any (_ it) + (-> Natural (Stream it) + [(List it) (Stream it)])) + (let [[stream list] (list.static amount + (function (_ it) + (let [[head tail] (//.value it)] + [tail head])) + it)] + [list stream])) + +(the .public (first amount it) + (for_any (_ it) + (-> Natural (Stream it) + (List it))) + (let [[list stream] (split_at amount it)] + list)) + +(the .public (after amount it) + (for_any (_ it) + (-> Natural + (Change (Stream it)))) + (let [[list stream] (split_at amount it)] + stream)) (the .public (only predicate stream) - (for_any (_ a) (-> (-> a Bit) (Stream a) (Stream a))) + (for_any (_ it) + (-> (Predicate it) + (Change (Stream it)))) (let [[head tail] (//.value stream)] (if (predicate head) (//.pending [head (only predicate tail)]) (only predicate tail)))) (the .public (partition left? xs) - (for_any (_ a) - (-> (-> a Bit) (Stream a) - [(Stream a) (Stream a)])) + (for_any (_ it) + (-> (Predicate it) (Stream it) + [(Stream it) (Stream it)])) [(..only left? xs) (..only (predicate.complement left?) xs)]) diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 92aad438eb..6441db46d1 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -224,12 +224,6 @@ {#Class} {#Interface})) -(.every StackFrame - (.Nominal "java/lang/StackTraceElement")) - -(.every StackTrace - (.Array StackFrame)) - (.every Annotation_Parameter [Text Code]) diff --git a/stdlib/source/library/lux/ffi.lux b/stdlib/source/library/lux/ffi.lux index 2bff4b40a5..c164a14e22 100644 --- a/stdlib/source/library/lux/ffi.lux +++ b/stdlib/source/library/lux/ffi.lux @@ -18,8 +18,7 @@ ["[0]" text (.only) ["%" \\injection]] [collection - ["[0]" stack] - ["[0]" list (.use "[1]#[0]" monoid monad mix) + ["[0]" list (.use "[1]#[0]" monoid monad) ["?[1]" \\projection]]]] ["[0]" macro (.only with_names) ["[0]" syntax] @@ -761,16 +760,16 @@ (` ( (, (code.text (text.replaced .module_delimiter "." class))))) ... else - (when (list.as_stack (text.all_split_by .module_delimiter class)) - {.#Top head tail} - (stack.mix (.function (_ sub super) - (` ( (, (code.text sub)) - (.as (-> Any (..Object .Any)) - (, super))))) - (` ( (, (code.text head)))) - tail) + (when (list.split 1 (text.all_split_by .module_delimiter class)) + [(list head) tail] + (list.mix (.function (_ sub super) + (` ( (, (code.text sub)) + (.as (-> Any (..Object .Any)) + (, super))))) + (` ( (, (code.text head)))) + tail) - {.#Empty} + else (` ( (, (code.text class)))))))) (the (global_definition import! it) diff --git a/stdlib/source/library/lux/ffi/export.js.lux b/stdlib/source/library/lux/ffi/export.js.lux index ee21a8a03a..59d1b5eb0c 100644 --- a/stdlib/source/library/lux/ffi/export.js.lux +++ b/stdlib/source/library/lux/ffi/export.js.lux @@ -11,9 +11,8 @@ [text ["%" \\injection]] [collection - ["[0]" stack (.use "[1]#[0]" monad mix)] ["[0]" set] - ["[0]" list + ["[0]" list (.use "[1]#[0]" monad mix) ["?[1]" \\projection]]]] [macro ["[0]" syntax] @@ -39,7 +38,7 @@ (the definition (-> Code (Meta [Text Code])) - (|>> (stack) + (|>> (list) (?list.value (<| .form (<>.after (.this_name (name .def#))) (<>.before ?list.any) @@ -72,7 +71,7 @@ _ (declaration.of_translation (do ! - [@self (translation.learn_custom name (stack#mix set.has dependencies interim_artifacts)) + [@self (translation.learn_custom name (list#mix set.has dependencies interim_artifacts)) .let [$module (/.var "module") $exports (/.its "exports" $module) definition (/.define (/.var name) term) @@ -89,9 +88,9 @@ (syntax.macro (_ [exports (<>.many ?list.any)]) (let [! meta.monad] (|> exports - (stack.each' ! expansion.complete) - (by ! each (|>> stack#conjoint - (stack.each' ! ..definition))) + (list.each' ! expansion.complete) + (by ! each (|>> list#conjoint + (list.each' ! ..definition))) (by ! conjoint) - (by ! each (stack#each (function (_ [name term]) - (` (..export_one (, (code.text name)) (, term)))))))))) + (by ! each (list#each (function (_ [name term]) + (` (..export_one (, (code.text name)) (, term)))))))))) diff --git a/stdlib/source/library/lux/ffi/export.rb.lux b/stdlib/source/library/lux/ffi/export.rb.lux index 1c739732bc..09ce4052d6 100644 --- a/stdlib/source/library/lux/ffi/export.rb.lux +++ b/stdlib/source/library/lux/ffi/export.rb.lux @@ -13,7 +13,6 @@ ["%" \\injection] ["<[1]>" \\projection (.only Projection)]] [collection - ["[0]" stack (.use "[1]#[0]" monad mix)] ["[0]" set] ["[0]" sequence] ["[0]" list (.use "[1]#[0]" monad mix) diff --git a/stdlib/source/library/lux/web/html.lux b/stdlib/source/library/lux/web/html.lux index f3f36e9ab1..3918a6a873 100644 --- a/stdlib/source/library/lux/web/html.lux +++ b/stdlib/source/library/lux/web/html.lux @@ -13,8 +13,7 @@ ["[0]" text (.only Injection) ["%" \\injection]] [collection - ["[0]" list (.use "[1]#[0]" monad mix monoid)] - ["[0]" stack]] + ["[0]" list (.use "[1]#[0]" monad mix monoid)]] [format ["[0]" xml (.only XML)]]] [macro @@ -344,15 +343,15 @@ (Change Image)) (all ..and for - (when (list.as_stack (list#each (product.uncurried ..area) areas)) - {.#Empty} - (..empty_tag tag.map - attributes) - - {.#Top head tail} + (when (list.split 1 (list#each (product.uncurried ..area) areas)) + [(list head) tail] (..tag tag.map attributes - (stack.mix (function.flipped ..and) head tail))))) + (list.mix (function.flipped ..and) head tail)) + + else + (..empty_tag tag.map + attributes)))) (template.with [ ] [(the .public @@ -530,19 +529,19 @@ (the .public (description_list attributes descriptions) (-> Attributes (List [Content Element]) Element) - (when (list.as_stack (list#each (function (_ [term description]) - (all ..and - (..term term) - (..description description))) - descriptions)) - {.#Empty} - (..empty_tag tag.description_list - attributes) - - {.#Top head tail} + (when (list.split 1 (list#each (function (_ [term description]) + (all ..and + (..term term) + (..description description))) + descriptions)) + [(list head) tail] (..tag tag.description_list attributes - (stack.mix (function.flipped ..and) head tail)))) + (list.mix (function.flipped ..and) head tail)) + + else + (..empty_tag tag.description_list + attributes))) (the .public p ..paragraph) @@ -600,13 +599,13 @@ (-> Attributes (Maybe Content) (Maybe Column) Header (List Cell) (Maybe Cell) Element) (let [head (..table_head (..table_row headers)) - content (when (list.as_stack (list#each table_row rows)) - {.#Empty} - head - - {.#Top first rest} + content (when (list.split 1 (list#each table_row rows)) + [(list first) rest] (..and head - (..table_body (stack.mix (function.flipped ..and) first rest)))) + (..table_body (list.mix (function.flipped ..and) first rest))) + + else + head) content (when footer {.#None} content diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index a2e3e0c1d1..a646c40734 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -23,8 +23,7 @@ [collection ["[0]" dictionary (.only Dictionary)] ["[0]" sequence (.use "[1]#[0]" monoid mix)] - ["[0]" list (.use "[1]#[0]" mix)] - ["[0]" stack (.use "[1]#[0]" mix)]] + ["[0]" list (.use "[1]#[0]" mix)]] [format ["[0]" tar (.only Tar)]]] [type (.only sharing)] @@ -123,7 +122,7 @@ {.#Right content} (do [! (try.with future.monad)] [_ (by fs make_directory package) - _ (stack.each' ! (function (_ [name content]) + _ (list.each' ! (function (_ [name content]) (by fs write (file.rooted fs package name) content)) content)] (in []))) @@ -134,20 +133,13 @@ (the (load_host_dependencies fs host_dependencies) (-> (file.System Future) (List file.Path) (Future (Try (Dictionary file.Path Binary)))) - (do [! (try.with future.monad)] - [] - (loop (again [pending (list.as_stack host_dependencies) - output (is (Dictionary file.Path Binary) - (dictionary.empty text.hash))]) - (when pending - {.#Empty} - (in output) - - {.#Top head tail} - (do ! - [content (by fs read head)] - (again tail - (dictionary.has head content output))))))) + (let [! (try.with future.monad)] + (|> host_dependencies + (list.each' ! (function (_ head) + (do ! + [content (by fs read head)] + (in [head content])))) + (by ! each (dictionary.of_list text.hash))))) (the (hybrid_fs cache host) (-> (file.System Future) (file.System Future) diff --git a/stdlib/source/projection/lux/data/text.lux b/stdlib/source/projection/lux/data/text.lux index 2284868b4a..6cf886c9d0 100644 --- a/stdlib/source/projection/lux/data/text.lux +++ b/stdlib/source/projection/lux/data/text.lux @@ -18,8 +18,7 @@ [character (.only Character)]] ["[0]" product] [collection - ["[0]" list (.use "[1]#[0]" mix)] - ["[0]" stack (.use "[1]#[0]" mix)]]] + ["[0]" list (.use "[1]#[0]" mix)]]] [math [number ["n" natural (.use "[1]#[0]" base_10)]]] @@ -88,8 +87,8 @@ {try.#Success [[end_offset _] output]} (if (n.= end_offset (/.size input)) - {try.#Success output} - (exception.except ..unconsumed_input [end_offset input])))) + {try.#Success output} + (exception.except ..unconsumed_input [end_offset input])))) (the .public offset (Projection Offset) @@ -160,9 +159,9 @@ (when (/.index_since offset reference tape) {.#Some where} (if (n.= offset where) - {try.#Success [[(.i64_+# (/.size reference) offset) tape] - []]} - (exception.except ..cannot_match [reference])) + {try.#Success [[(.i64_+# (/.size reference) offset) tape] + []]} + (exception.except ..cannot_match [reference])) _ (exception.except ..cannot_match [reference])))) @@ -171,8 +170,8 @@ (Projection Any) (function (_ (^.let input [offset tape])) (if (n.= offset (/.size tape)) - {try.#Success [input []]} - (exception.except ..unconsumed_input input)))) + {try.#Success [input []]} + (exception.except ..unconsumed_input input)))) (the .public next (Projection Text) @@ -267,8 +266,8 @@ {.#Some output} (let [output' (/.of_character output)] (if ( (/.contains? output' options)) - {try.#Success [[(.i64_+# 1 offset) tape] output']} - (exception.except [options output]))) + {try.#Success [[(.i64_+# 1 offset) tape] output']} + (exception.except [options output]))) _ (exception.except ..cannot_parse []))))] @@ -286,10 +285,10 @@ {.#Some output} (let [output' (/.of_character output)] (if ( (/.contains? output' options)) - {try.#Success [[(.i64_+# 1 offset) tape] - [#basis offset - #distance 1]]} - (exception.except [options output]))) + {try.#Success [[(.i64_+# 1 offset) tape] + [#basis offset + #distance 1]]} + (exception.except [options output]))) _ (exception.except ..cannot_slice []))))] @@ -310,8 +309,8 @@ (when (/.character offset tape) {.#Some output} (if (projection output) - {try.#Success [[(.i64_+# 1 offset) tape] (/.of_character output)]} - (exception.except ..character_does_not_satisfy_predicate [output])) + {try.#Success [[(.i64_+# 1 offset) tape] (/.of_character output)]} + (exception.except ..character_does_not_satisfy_predicate [output])) _ (exception.except ..cannot_parse [])))) @@ -323,9 +322,9 @@ (when (/.character offset tape) {.#Some output} (if (projection output) - {try.#Success [[(.i64_+# 1 offset) tape] - [#basis offset #distance 1]]} - (exception.except ..character_does_not_satisfy_predicate [output])) + {try.#Success [[(.i64_+# 1 offset) tape] + [#basis offset #distance 1]]} + (exception.except ..character_does_not_satisfy_predicate [output])) _ (exception.except ..cannot_parse [])))) diff --git a/stdlib/source/test/lux/abstract/comonad/free.lux b/stdlib/source/test/lux/abstract/comonad/free.lux index 78159c74df..54bccf974f 100644 --- a/stdlib/source/test/lux/abstract/comonad/free.lux +++ b/stdlib/source/test/lux/abstract/comonad/free.lux @@ -14,7 +14,7 @@ ["//" continuation]] [data [collection - ["[0]" stack] + ["[0]" list] ["[0]" stream (.only Stream) (.use "[1]#[0]" comonad)]]] [math ["[0]" random]] @@ -39,7 +39,7 @@ (the comparison (Comparison (/.Free Stream)) (function (_ == left right) - (by (stack.equivalence ==) = + (by (list.equivalence ==) = (stream.first 100 (..interpret left)) (stream.first 100 (..interpret right))))) diff --git a/stdlib/source/test/lux/color/terminal.lux b/stdlib/source/test/lux/color/terminal.lux index 70ebe94425..f2ba1514c6 100644 --- a/stdlib/source/test/lux/color/terminal.lux +++ b/stdlib/source/test/lux/color/terminal.lux @@ -11,7 +11,7 @@ [data ["[0]" text] [collection - ["[0]" stack]]] + ["[0]" list]]] [math ["[0]" random (.only Random) (.use "[1]#[0]" monad)]] [macro @@ -98,13 +98,13 @@ [] ))] - (loop (again [commands (stack )]) - (when commands - {.#Empty} - true + (loop (again [commands (list )]) + (when (list.split 1 commands) + [(list head) tail] + (and (list.every? (|>> (by /.equivalence = head) not) tail) + (again tail)) - {.#Top head tail} - (and (stack.every? (|>> (by /.equivalence = head) not) tail) - (again tail)))))) + else + true)))) )))) ) diff --git a/stdlib/source/test/lux/data/collection/stream.lux b/stdlib/source/test/lux/data/collection/stream.lux index 970c1675f2..77c9bf84f3 100644 --- a/stdlib/source/test/lux/data/collection/stream.lux +++ b/stdlib/source/test/lux/data/collection/stream.lux @@ -16,8 +16,7 @@ ["[0]" text (.only) ["%" \\injection]] [collection - ["[0]" stack (.use "[1]#[0]" functor)] - ["[0]" list (.use "[1]#[0]" functor)]]] + ["[0]" list (.use "[1]#[0]" monad monoid)]]] [math ["[0]" random] [number @@ -28,19 +27,19 @@ ["[0]" /]]) (the (equivalence super) - (for_any (_ a) - (-> (Equivalence a) - (Equivalence (/.Stream a)))) + (for_any (_ it) + (-> (Equivalence it) + (Equivalence (/.Stream it)))) (implementation (the (= expected actual) - (by (stack.equivalence super) = + (by (list.equivalence super) = (/.first 100 expected) (/.first 100 actual))))) (the (iterations step) - (for_any (_ a) - (-> (-> a a) - (-> a (/.Stream a)))) + (for_any (_ it) + (-> (-> it it) + (-> it (/.Stream it)))) (/.iterations (function (_ state) (let [state' (step state)] @@ -50,14 +49,14 @@ Test (<| (_.covering /._) (_.for [/.Stream]) - (let [(open "stack#[0]") (stack.equivalence n.equivalence)]) + (let [(open "list#[0]") (list.equivalence n.equivalence)]) (do [! random.monad] [repeated random.natural index (by ! each (n.% 100) random.natural) size (by ! each (|>> (n.% 10) ++) random.natural) offset (by ! each (n.% 100) random.natural) cycle_start random.natural - cycle_next (random.stack size random.natural)] + cycle_next (random.list size random.natural)] (all _.and (_.for [/.functor] (functorT.spec /.repeated ..equivalence /.functor)) @@ -71,39 +70,39 @@ (n.= repeated (/.item index (/.repeated repeated)))) (_.coverage [/.first] - (stack#= (list.as_stack (enum.range n.enum offset (-- (n.+ size offset)))) - (/.first size (..iterations ++ offset)))) + (list#= (enum.range n.enum offset (-- (n.+ size offset))) + (/.first size (..iterations ++ offset)))) (_.coverage [/.after] - (stack#= (list.as_stack (enum.range n.enum offset (-- (n.+ size offset)))) - (/.first size (/.after offset (..iterations ++ 0))))) + (list#= (enum.range n.enum offset (-- (n.+ size offset))) + (/.first size (/.after offset (..iterations ++ 0))))) (_.coverage [/.split_at] (let [[drops takes] (/.split_at size (..iterations ++ 0))] - (and (stack#= (list.as_stack (enum.range n.enum 0 (-- size))) - drops) - (stack#= (list.as_stack (enum.range n.enum size (-- (n.* 2 size)))) - (/.first size takes))))) + (and (list#= (enum.range n.enum 0 (-- size)) + drops) + (list#= (enum.range n.enum size (-- (n.* 2 size))) + (/.first size takes))))) (_.coverage [/.while] - (stack#= (list.as_stack (enum.range n.enum 0 (-- size))) - (/.while (n.< size) (..iterations ++ 0)))) + (list#= (enum.range n.enum 0 (-- size)) + (/.while (n.< size) (..iterations ++ 0)))) (_.coverage [/.until] - (stack#= (list.as_stack (enum.range n.enum offset (-- (n.+ size offset)))) - (/.while (n.< (n.+ size offset)) - (/.until (n.< offset) (..iterations ++ 0))))) + (list#= (enum.range n.enum offset (-- (n.+ size offset))) + (/.while (n.< (n.+ size offset)) + (/.until (n.< offset) (..iterations ++ 0))))) (_.coverage [/.split_when] (let [[drops takes] (/.split_when (n.= size) (..iterations ++ 0))] - (and (stack#= (list.as_stack (enum.range n.enum 0 (-- size))) - drops) - (stack#= (list.as_stack (enum.range n.enum size (-- (n.* 2 size)))) - (/.while (n.< (n.* 2 size)) takes))))) + (and (list#= (enum.range n.enum 0 (-- size)) + drops) + (list#= (enum.range n.enum size (-- (n.* 2 size))) + (/.while (n.< (n.* 2 size)) takes))))) (_.coverage [/.head] (n.= offset (/.head (..iterations ++ offset)))) (_.coverage [/.tail] - (stack#= (list.as_stack (enum.range n.enum (++ offset) (n.+ size offset))) - (/.first size (/.tail (..iterations ++ offset))))) + (list#= (enum.range n.enum (++ offset) (n.+ size offset)) + (/.first size (/.tail (..iterations ++ offset))))) (_.coverage [/.only] - (stack#= (list.as_stack (list#each (n.* 2) (enum.range n.enum 0 (-- size)))) - (/.first size (/.only n.even? (..iterations ++ 0))))) + (list#= (list#each (n.* 2) (enum.range n.enum 0 (-- size))) + (/.first size (/.only n.even? (..iterations ++ 0))))) (_.coverage [/.partition] (let [[evens odds] (/.partition n.even? (..iterations ++ 0))] (and (n.= (n.* 2 offset) @@ -112,17 +111,17 @@ (/.item offset odds))))) (_.coverage [/.iterations] (let [(open "/#[0]") /.functor - (open "stack#[0]") (stack.equivalence text.equivalence)] - (stack#= (/.first size - (/#each %.natural (..iterations ++ offset))) - (/.first size - (/.iterations (function (_ n) [(++ n) (%.natural n)]) - offset))))) + (open "list#[0]") (list.equivalence text.equivalence)] + (list#= (/.first size + (/#each %.natural (..iterations ++ offset))) + (/.first size + (/.iterations (function (_ n) [(++ n) (%.natural n)]) + offset))))) (_.coverage [/.cycle] - (let [cycle (stack.partial cycle_start cycle_next)] - (stack#= (stack.together (stack.repeated size cycle)) - (/.first (n.* size (stack.size cycle)) - (/.cycle [cycle_start cycle_next]))))) + (let [cycle (list#composite (list cycle_start) cycle_next)] + (list#= (list#conjoint (list.repeated size cycle)) + (/.first (n.* size (list.size cycle)) + (/.cycle [cycle_start cycle_next]))))) (_.coverage [/.pattern] (let [(/.pattern first second third next) (..iterations ++ offset)] (and (n.= offset first) diff --git a/stdlib/source/test/lux/music/chord.lux b/stdlib/source/test/lux/music/chord.lux index 9abda2f092..bab750fab3 100644 --- a/stdlib/source/test/lux/music/chord.lux +++ b/stdlib/source/test/lux/music/chord.lux @@ -15,7 +15,6 @@ ["[0]" text] [collection ["[0]" list] - ["[0]" stack] ["[0]" sequence (.only sequence)] ["[0]" set]]] [math @@ -86,14 +85,14 @@ (n.= 2 (/.size /.power))) (,, (template.with [ ] [(_.coverage - (loop (next [options (`` (stack (,, (template.spliced ))))]) - (when options - (stack.partial head tail) + (loop (next [options (`` (list (,, (template.spliced ))))]) + (when (list.split 1 options) + [(list head) tail] (and (n.= (/.size head)) - (stack.every? (|>> (by /.equivalence = head) not) tail) + (list.every? (|>> (by /.equivalence = head) not) tail) (next tail)) - (stack) + else true)))] [3 [/.major_triad /.minor_triad diff --git a/stdlib/source/test/lux/type/implicit.lux b/stdlib/source/test/lux/type/implicit.lux index 1807e6ea34..76d7db65ae 100644 --- a/stdlib/source/test/lux/type/implicit.lux +++ b/stdlib/source/test/lux/type/implicit.lux @@ -13,7 +13,7 @@ [data ["[0]" bit] [collection - ["[0]" stack]]] + ["[0]" list]]] [math ["[0]" random (.only Random)] [number @@ -40,10 +40,10 @@ (all _.and ... (_.coverage [/.any] ... (let [first_order! - ... (let [(open "stack#[0]") (stack.equivalence n.equivalence)] + ... (let [(open "list#[0]") (list.equivalence n.equivalence)] ... (and (bit.= (by n.equivalence = left right) ... (/.any = left right)) - ... (stack#= (by stack.functor each ++ (enum.range n.enum start end)) + ... (list#= (by list.functor each ++ (enum.range n.enum start end)) ... (/.any each ++ (enum.range n.enum start end))))) ... second_order! diff --git a/stdlib/source/test/lux/world/net/http/cookie.lux b/stdlib/source/test/lux/world/net/http/cookie.lux index 79ba4d6938..bd6a96897d 100644 --- a/stdlib/source/test/lux/world/net/http/cookie.lux +++ b/stdlib/source/test/lux/world/net/http/cookie.lux @@ -16,7 +16,7 @@ ["[0]" text] [collection ["[0]" dictionary] - ["[0]" stack]]] + ["[0]" list]]] [math ["[0]" random (.only Random) (.use "[1]#[0]" monad)]] [macro @@ -29,18 +29,19 @@ [\\library ["[0]" /]]) -(the .public (random cookies) - (-> (Stack (for_some (_ it) [(/.Cookie it) (Random it)])) +(the .public random + (-> (List (for_some (_ it) [(/.Cookie it) (Random it)])) (Random /.Jar)) - (when cookies - (stack.partial [cookie random_value] tail) - (do random.monad - [value random_value - jar (random tail)] - (in (/.has cookie value jar))) - - (stack) - (random#in /.empty))) + (let [! random.monad] + (|>> (list.each' ! (is (-> (for_some (_ it) [(/.Cookie it) (Random it)]) + (for_some (_ it) (Random [(/.Cookie it) it]))) + (function (_ [cookie random_value]) + (do ! + [value random_value] + (in [cookie value]))))) + (by ! each (list.mix (function (_ [cookie value] jar) + (/.has cookie value jar)) + /.empty))))) (the .public test Test @@ -66,7 +67,7 @@ /.#name /.#in /.#out]) (all _.and (_.for [/.equivalence] - (equivalenceT.spec /.equivalence (..random (stack [cookie (random.lower_cased 1)])))) + (equivalenceT.spec /.equivalence (..random (list [cookie (random.lower_cased 1)])))) (_.for [/.Jar] (all _.and (_.coverage [/.empty]