diff --git a/lux-mode/lux-mode.el b/lux-mode/lux-mode.el index 0ecaf92a48..623da9201e 100644 --- a/lux-mode/lux-mode.el +++ b/lux-mode/lux-mode.el @@ -393,7 +393,7 @@ Called by `imenu--generic-function'." (jvm-host (altRE "import" "export" "class" "interface" "object" "synchronized" "class_for")) (alternative-format (altRE "char" "bin" "oct" "hex")) (documentation (altRE "comment")) - (function-application (altRE "|>" "<|" "left" "right" "all")) + (function-application (altRE "|>" "<|" "all")) (function-definition (altRE "function" "|>>" "<<|" "program")) (remember (altRE "remember" "to_do" "fix_me")) diff --git a/stdlib/source/injection/lux/data/text.lux b/stdlib/source/injection/lux/data/text.lux index 47776b6cf4..a34b8d7568 100644 --- a/stdlib/source/injection/lux/data/text.lux +++ b/stdlib/source/injection/lux/data/text.lux @@ -32,13 +32,7 @@ ["<[1]>" \\projection]] [macro ["[0]" syntax] - ["[0]" template]]] - [world - ["[0]" time (.only) - ["[0]" duration] - ["[0]" date] - ["[0]" day] - ["[0]" month]]]]]) + ["[0]" template]]]]]) ... https://en.wikipedia.org/wiki/Message (the .public message @@ -64,12 +58,6 @@ [location Location location.injection] [code Code code.absolute] [type Type type.absolute_injection] - - [duration duration.Duration (of duration.format injection)] - [date date.Date (of date.format injection)] - [time time.Time (of time.format injection)] - [day day.Day (of day.format injection)] - [month month.Month (of month.format injection)] ) (template.with [] diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index 727fa07b26..31a6f1391a 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -1698,7 +1698,8 @@ (function' [right left] (func left right))) -(def' .public left +... https://en.wikipedia.org/wiki/Operator_associativity +(def' .public left_associative Macro (macro (_ tokens) (.when# {{#Item op tokens'} @@ -1713,7 +1714,7 @@ (failure ..wrong_syntax)} tokens))) -(def' .public right +(def' .public right_associative Macro (macro (_ tokens) (.when# {{#Item op tokens'} @@ -1728,7 +1729,7 @@ (failure ..wrong_syntax)} tokens))) -(def' .public all Macro ..right) +(def' .public all Macro ..right_associative) ... (every (Monad m) ... (Interface diff --git a/stdlib/source/library/lux/abstract/functor.lux b/stdlib/source/library/lux/abstract/functor.lux index 6adab89bbb..8f68867470 100644 --- a/stdlib/source/library/lux/abstract/functor.lux +++ b/stdlib/source/library/lux/abstract/functor.lux @@ -3,8 +3,7 @@ (.require [library - [lux (.except left right - function) + [lux (.except function) ["//" algorithm]]]) (every .public (Functor !) diff --git a/stdlib/source/library/lux/control/aspect.lux b/stdlib/source/library/lux/control/aspect.lux index c4f3277508..8e6ee1e03f 100644 --- a/stdlib/source/library/lux/control/aspect.lux +++ b/stdlib/source/library/lux/control/aspect.lux @@ -22,6 +22,7 @@ ["[0]" property]]]] ["[0]" meta (.only) [extension (.only analysis declaration)] + ["[0]" binding] ["[0]" code (.only) ["?[1]" \\projection]] ["[0]" macro (.only) @@ -127,7 +128,7 @@ (-> Symbol (Meta [Bit .Global])) (do meta.monad - [name (meta.normal name) + [name (binding.normal name) current_module_name meta.current_module_name lux meta.compiler_state] (loop (again [[normal_module normal_short] name]) diff --git a/stdlib/source/library/lux/control/concatenative.lux b/stdlib/source/library/lux/control/concatenative.lux index 65943a8334..069bedfc41 100644 --- a/stdlib/source/library/lux/control/concatenative.lux +++ b/stdlib/source/library/lux/control/concatenative.lux @@ -4,7 +4,7 @@ (.require [library [lux (.except Alias - if loop left right) + if loop) [abstract ["[0]" monad]] [control diff --git a/stdlib/source/library/lux/control/function/polymorphism/subject.lux b/stdlib/source/library/lux/control/function/polymorphism/subject.lux index e3d073fee6..70defdb350 100644 --- a/stdlib/source/library/lux/control/function/polymorphism/subject.lux +++ b/stdlib/source/library/lux/control/function/polymorphism/subject.lux @@ -17,6 +17,7 @@ ["[0]" dictionary (.only Dictionary)] ["[0]" list (.use "[1]#[0]" mix)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" type (.only) ["[0]" nominal]] @@ -87,7 +88,7 @@ (do [! meta.monad] [bindings (monad.each ! (function (_ [name value]) (do ! - [name (meta.normal name)] + [name (binding.normal name)] (in [name value]))) bindings)] (in (list (list#mix (function (_ [name value] term) diff --git a/stdlib/source/library/lux/control/pattern.lux b/stdlib/source/library/lux/control/pattern.lux index 73bcfb2029..a40c68728f 100644 --- a/stdlib/source/library/lux/control/pattern.lux +++ b/stdlib/source/library/lux/control/pattern.lux @@ -8,7 +8,6 @@ nat int rev or and is has - left right try with when) [abstract [equivalence (.only Equivalence)]] diff --git a/stdlib/source/library/lux/control/scope/dynamic.lux b/stdlib/source/library/lux/control/scope/dynamic.lux index ddcc80b224..9b6a526fa6 100644 --- a/stdlib/source/library/lux/control/scope/dynamic.lux +++ b/stdlib/source/library/lux/control/scope/dynamic.lux @@ -18,6 +18,7 @@ ["[0]" dictionary (.only Dictionary)] ["[0]" list (.use "[1]#[0]" mix)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" code (.only) ["?[1]" \\projection]] @@ -78,7 +79,7 @@ (do [! meta.monad] [bindings (monad.each ! (function (_ [name value]) (do ! - [name (meta.normal name)] + [name (binding.normal name)] (in [name value]))) bindings)] (in (list (list#mix (function (_ [name value] term) diff --git a/stdlib/source/library/lux/data/collection/tree/zipper.lux b/stdlib/source/library/lux/data/collection/tree/zipper.lux index ecf856212b..ca2a30ec83 100644 --- a/stdlib/source/library/lux/data/collection/tree/zipper.lux +++ b/stdlib/source/library/lux/data/collection/tree/zipper.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right) + [lux (.except) [abstract [functor (.only Functor)] [comonad (.only CoMonad)] diff --git a/stdlib/source/library/lux/data/product.lux b/stdlib/source/library/lux/data/product.lux index 8c812f5320..1e1ffc2cca 100644 --- a/stdlib/source/library/lux/data/product.lux +++ b/stdlib/source/library/lux/data/product.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right) + [lux (.except) [abstract [equivalence (.only Equivalence)] [hash (.only Hash)] diff --git a/stdlib/source/library/lux/data/sum.lux b/stdlib/source/library/lux/data/sum.lux index d43a63c033..d523986934 100644 --- a/stdlib/source/library/lux/data/sum.lux +++ b/stdlib/source/library/lux/data/sum.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right) + [lux (.except) [abstract [equivalence (.only Equivalence)] [hash (.only Hash)]] diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index 26e3236db5..fc945a8253 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -28,6 +28,7 @@ ["n" nat] ["i" int]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection]] [macro @@ -557,7 +558,7 @@ (<>.else (list))))]) (do [! meta.monad] [location meta.location - locals meta.locals + locals binding.locals .let [environment (|> locals list.together ... The list is reversed to make sure that, when building the dictionary, diff --git a/stdlib/source/library/lux/documentation.lux b/stdlib/source/library/lux/documentation.lux index 13428fbd69..15a6e029fe 100644 --- a/stdlib/source/library/lux/documentation.lux +++ b/stdlib/source/library/lux/documentation.lux @@ -31,6 +31,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" label] ["[0]" type (.use "[1]#[0]" equivalence)] @@ -515,7 +516,7 @@ (syntax.macro (_ [[name parameters] ..declaration]) (do meta.monad [.let [g!module (code.text (product.left name))] - [def_type def_value] (meta.export name) + [def_type def_value] (binding.export name) tags (meta.try (meta.either (label.tags name) (label.slots name)))] @@ -555,7 +556,7 @@ (the alias_documentation (syntax.macro (_ [name ..qualified_symbol]) (do meta.monad - [original (meta.alias name)] + [original (binding.alias name)] (in (list (` (all md.then ... Name (md.heading/4 (md.and (md.anchor (, (let [[module short] name] @@ -694,7 +695,7 @@ (syntax.macro (_ [[name _] ..qualified_symbol description .any]) (do [! meta.monad] - [coverage (|> (meta.globals name) + [coverage (|> (binding.globals name) (of ! each (|>> (list.only exported_non_default?) (list#each product.left)))) dependees (import.all name)] diff --git a/stdlib/source/library/lux/documentation/remember.lux b/stdlib/source/library/lux/documentation/remember.lux index bbb837d873..6f0a64b6fc 100644 --- a/stdlib/source/library/lux/documentation/remember.lux +++ b/stdlib/source/library/lux/documentation/remember.lux @@ -28,8 +28,8 @@ (exception.the .public (must_remember [deadline today message focus]) (Exception [Date Date Text (Maybe Code)]) (exception.report - (list ["Deadline" (%.date deadline)] - ["Today" (%.date today)] + (list ["Deadline" (date.as_text deadline)] + ["Today" (date.as_text today)] ["Message" message] ["Code" (when focus {.#Some focus} @@ -72,7 +72,7 @@ (syntax.macro (_ [deadline ..deadline message .text focus (<>.maybe .any)]) - (in (list (` (..remember (, (code.text (%.date deadline))) + (in (list (` (..remember (, (code.text (date.as_text deadline))) (, (code.text (%.message " " message))) (,* (when focus {.#Some focus} diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 033b88660b..8e51c5e99e 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -26,6 +26,7 @@ [number ["n" nat]]] ["[0]" meta (.use "[1]#[0]" monad) + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection(.only Projection)]] [macro (.only with_symbols) @@ -2008,7 +2009,7 @@ (when array [_ {.#Symbol array_name}] (do meta.monad - [array_type (meta.type array_name) + [array_type (binding.type array_name) context meta.type_context array_jvm_type (lux_type->jvm_type context array_type) .let [g!extension (`` (cond (,, (template.with [ ] @@ -2045,7 +2046,7 @@ (when array [_ {.#Symbol array_name}] (do meta.monad - [array_type (meta.type array_name) + [array_type (binding.type array_name) context meta.type_context array_jvm_type (lux_type->jvm_type context array_type) .let [g!idx (` (.|> (, idx) @@ -2085,7 +2086,7 @@ (when array [_ {.#Symbol array_name}] (do meta.monad - [array_type (meta.type array_name) + [array_type (binding.type array_name) context meta.type_context array_jvm_type (lux_type->jvm_type context array_type) .let [g!idx (` (.|> (, idx) diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index 59bc551a23..3cfd65eba0 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -23,6 +23,7 @@ ["[0]" array (.only Array)] ["[0]" list (.use "[1]#[0]" monad mix monoid)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" type (.use "[1]#[0]" equivalence)] ["[0]" code (.only) ["<[1]>" \\projection (.only Projection)]] @@ -1720,7 +1721,7 @@ (when array [_ {.#Symbol array_name}] (do meta.monad - [array_type (meta.type array_name) + [array_type (binding.type array_name) array_jvm_type (type_class_name array_type)] (`` (when array_jvm_type (,, (template.with [ ] @@ -1751,7 +1752,7 @@ (when array [_ {.#Symbol array_name}] (do meta.monad - [array_type (meta.type array_name) + [array_type (binding.type array_name) array_jvm_type (type_class_name array_type)] (`` (when array_jvm_type (,, (template.with [ ] diff --git a/stdlib/source/library/lux/math/random.lux b/stdlib/source/library/lux/math/random.lux index 84a0682f24..4b01fec11e 100644 --- a/stdlib/source/library/lux/math/random.lux +++ b/stdlib/source/library/lux/math/random.lux @@ -43,10 +43,8 @@ ["[0]" template]]] [world ["[0]" time (.only Time) - ["[0]" date (.only Date)] ["[0]" duration (.only Duration)] - ["[0]" month (.only Month)] - ["[0]" day (.only Day)]]]]]) + ["[0]" month (.only Month)]]]]]) (for .old (every .public PRNG @@ -361,17 +359,6 @@ (..either (/#in {month.#November}) (/#in {month.#December}))))))) -(the .public day - (Random Day) - (let [(open "/#[0]") ..monad] - (..either (..either (/#in {day.#Sunday}) - (..either (/#in {day.#Monday}) - (/#in {day.#Tuesday}))) - (..either (..either (/#in {day.#Wednesday}) - (/#in {day.#Thursday})) - (..either (/#in {day.#Friday}) - (/#in {day.#Saturday})))))) - (for .old (the .public (value prng seed it) (for_any (_ seed of) diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index c663a50c84..ba0e633400 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except try macro type local alias or and) + [lux (.except try or and) [abstract [functor (.only Functor)] [apply (.only Apply)] @@ -186,66 +186,6 @@ (/#each ..module) /#conjoint))) -(the (macro_type? type) - (-> Type - Bit) - (when type - {.#Named [.prelude "Macro"] - {.#Nominal "#Macro" {.#End}}} - true - - _ - false)) - -(the .public (normal name) - (-> Symbol - (Meta Symbol)) - (when name - ["" name] - (do ..monad - [module_name ..current_module_name] - (in [module_name name])) - - _ - (of ..monad in name))) - -(the .public not_a_macro - Error - (location.with (location.here) - "Not a macro.")) - -(the .public (macro full_name) - (-> Symbol - (Meta Macro)) - (do ..monad - [full_name (..normal full_name)] - (is (Meta Macro) - (function (_ lux) - (when (..current_module_name lux) - {try.#Success [_ this_module]} - (let [modules (its .#modules lux)] - (loop (macro [[module name] full_name]) - (do try.monad - [$module (property.value module modules) - [exported? definition] (|> $module - (is Module) - (its .#definitions) - (property.value name))] - (when definition - {.#Alias de_aliased} - (macro de_aliased) - - {.#Definition [def_type def_value]} - (if (macro_type? def_type) - {try.#Success [lux (as Macro def_value)]} - {try.#Failure ..not_a_macro}) - - {.#Default _} - {try.#Failure ..not_a_macro})))) - - {try.#Failure error} - {try.#Failure error}))))) - (the .public seed (Meta Nat) (function (_ lux) @@ -263,230 +203,6 @@ failure false)]})) -(the (type_variable idx bindings) - (-> Nat (List [Nat (Maybe Type)]) - (Maybe Type)) - (when bindings - {.#End} - {.#None} - - {.#Item [var bound] bindings'} - (if (n.= idx var) - bound - (type_variable idx bindings')))) - -(`` (the (clean_type type) - (-> Type - (Meta Type)) - (when type - {.#Var var} - (function (_ lux) - (when (|> lux - (its [.#type_context .#var_bindings]) - (type_variable var)) - (,, (with_template' [] - [ - {try.#Success [lux type]}] - - [{.#None}] - [{.#Some {.#Var _}}])) - - - {.#Some type'} - {try.#Success [lux type']})) - - _ - (of ..monad in type)))) - -(the (on_either f x1 x2) - (for_any (_ input output) - (-> (-> input (Maybe output)) input input - (Maybe output))) - (when (f x1) - {.#None} - (f x2) - - some - some)) - -(the .public (var_type name) - (-> Text - (Meta Type)) - (function (_ lux) - (let [test (is (-> [Text [Type Any]] Bit) - (|>> product.left (text#= name)))] - (when (do maybe.monad - [scope (list.example (function (_ env) - (.or (list.any? test (is (List [Text [Type Any]]) - (its [.#locals .#mappings] env))) - (list.any? test (is (List [Text [Type Any]]) - (its [.#captured .#mappings] env))))) - (its .#scopes lux)) - [_ [type _]] (on_either (list.example test) - (is (List [Text [Type Any]]) - (its [.#locals .#mappings] scope)) - (is (List [Text [Type Any]]) - (its [.#captured .#mappings] scope)))] - (in type)) - {.#Some var_type} - ((clean_type var_type) lux) - - {.#None} - {try.#Failure (all text#composite "Unknown variable: " name)})))) - -(the without_lux_runtime - (-> (List Text) - (List Text)) - ... The Lux runtime shows up as "" - ... so I'm excluding it. - (list.only (|>> text.empty? not))) - -(the listing_separator - Text - (all text#composite text.new_line " ")) - -(the module_listing - (-> (List Text) - Text) - (|>> ..without_lux_runtime - (list.sorted text#<) - (text.interposed ..listing_separator))) - -(with_template' [ ] - [(the .public ( name) - (-> Symbol - (Meta [Bit Global])) - (do ..monad - [name (..normal name) - .let [[normal_module normal_short] name]] - (function (_ lux) - (when (is (Maybe [Bit Global]) - (do maybe.monad - [(open "[0]") (|> lux - (its .#modules) - (property.value normal_module))] - (property.value normal_short #definitions))) - {.#Some exported?,definition} - {try.#Success [lux exported?,definition]} - - _ - (let [current_module (|> lux (its .#current_module) (maybe.else "???")) - all_known_modules (|> lux - (its .#modules) - (list#each product.left) - ..module_listing)] - {try.#Failure (all text#composite - " All known modules: " all_known_modules text.new_line - (when (property.value current_module (its .#modules lux)) - {try.#Success this_module} - (let [candidates (|> lux - (its .#modules) - (list#each (function (_ [module_name module]) - (|> module - (its .#definitions) - (list.all (function (_ [def_name [exported? global]]) - (`` (when global - { _} - (if (.and exported? - (text#= normal_short def_name)) - {.#Some (symbol#injection [module_name def_name])} - {.#None}) - - _ - {.#None}))))))) - list.together - (list.sorted text#<) - (text.interposed ..listing_separator)) - imports (|> this_module - (its .#imports) - ..module_listing) - aliases (|> this_module - (its .#module_aliases) - (list#each (function (_ [alias real]) (all text#composite alias " => " real))) - (list.sorted text#<) - (text.interposed ..listing_separator))] - (all text#composite - " Aliases: " aliases text.new_line - " Imports: " imports text.new_line - " Candidates: " candidates text.new_line)) - - failure - "") - " Current module: " current_module text.new_line - "Unknown definition: " (symbol#injection name) text.new_line - )})))))] - - [definition .#Definition] - [default' .#Default] - [alias' .#Alias] - ) - -(the .public (export name) - (-> Symbol - (Meta Definition)) - (do [! ..monad] - [name (..normal name) - .let [[expected _] name] - [exported? definition] (..definition name) - actual ..current_module_name] - (when definition - {.#Definition it} - (if (.or exported? - (text#= expected actual)) - (in it) - (failure (all text#composite "Definition is not an export: " (symbol#injection name)))) - - {.#Alias it} - (if (.or exported? - (text#= expected actual)) - (export it) - (failure (all text#composite "Alias is not an export: " (symbol#injection name)))) - - {.#Default _} - (failure (all text#composite - "Defaults are not considered exports: " - (symbol#injection name)))))) - -(the .public (default name) - (-> Symbol - (Meta Default)) - (do [! ..monad] - [name (..normal name) - [exported? definition] (..default' name)] - (when definition - {.#Definition _} - (failure (all text#composite - "Definitions are not considered defaults: " - (symbol#injection name))) - - {.#Alias de_aliased} - (failure (all text#composite - "Aliases are not considered defaults: " - (symbol#injection name))) - - {.#Default it} - (if exported? - (in it) - (do ! - [.let [[expected _] name] - actual ..current_module_name] - (if (text#= expected actual) - (in it) - (failure (all text#composite "Default is not an export: " (symbol#injection name))))))))) - -(the .public (alias name) - (-> Symbol - (Meta Symbol)) - (do [! ..monad] - [name (..normal name) - [exported? it] (..alias' name)] - (when it - {.#Alias it} - (in it) - - _ - (undefined)))) - (with_template' [ ] [(the .public (Meta ) @@ -502,152 +218,6 @@ [configuration [.#info .#configuration] (List [Text Text])] ) -(the .public (definition_type name) - (-> Symbol - (Meta Type)) - (do ..monad - [[exported? definition] (definition name)] - (when definition - {.#Alias de_aliased} - (definition_type de_aliased) - - {.#Definition [def_type def_value]} - (clean_type def_type) - - {.#Default _} - (failure (all text#composite - "Defaults are not considered definitions: " - (symbol#injection name)))))) - -(the .public (type name) - (-> Symbol - (Meta Type)) - (when name - ["" _name] - (either (var_type _name) - (definition_type name)) - - _ - (definition_type name))) - -(the .public (type_definition name) - (-> Symbol - (Meta Type)) - (do ..monad - [[exported? definition] (definition name)] - (when definition - {.#Alias de_aliased} - (type_definition de_aliased) - - {.#Definition [def_type def_value]} - (let [type_code (.in_module# .prelude .type_code)] - (if (.or (same? .Type def_type) - (of code.equivalence = - (type_code .Type) - (type_code def_type))) - (in (as Type def_value)) - (..failure (all text#composite "Definition is not a type: " (symbol#injection name))))) - - {.#Default _} - (..failure (all text#composite "Default is not a type: " (symbol#injection name)))))) - -(the .public (globals module) - (-> Text - (Meta (List [Text [Bit Global]]))) - (function (_ lux) - (when (property.value module (its .#modules lux)) - {try.#Success module} - {try.#Success [lux (its .#definitions module)]} - - failure - {try.#Failure (all text#composite "Unknown module: " module)}))) - -(the .public (definitions module) - (-> Text - (Meta (List [Text [Bit Definition]]))) - (of ..monad each - (list.all (function (_ [name [exported? global]]) - (when global - {.#Alias de_aliased} - {.#None} - - {.#Definition definition} - {.#Some [name [exported? definition]]} - - {.#Default _} - {.#None}))) - (..globals module))) - -(the .public cannot_de-alias_a_default - Error - (location.with (location.here) - "Cannot de-alias a default global.")) - -(the .public (resolved_globals module) - (-> Text - (Meta (List [Text [Bit Definition]]))) - (do [! ..monad] - [it (..globals module) - .let [input (is (List [Text Bit (Either Symbol Definition)]) - (list.all (function (_ [name [exported? global]]) - (when global - {.#Alias de_aliased} - {.#Some [name exported? {.#Left de_aliased}]} - - {.#Definition definition} - {.#Some [name exported? {.#Right definition}]} - - {.#Default _} - {.#None})) - it))]] - (function (_ lux) - (loop (next [input input - output (is (List [Text [Bit Definition]]) - (list))]) - (when input - (list) - {try.#Success [lux output]} - - (list.partial [name exported? it] input) - (let [real_definition (is (Try Definition) - (loop (again [it it]) - (when it - {.#Left de_aliased} - (when (..definition de_aliased lux) - {try.#Success [_ [_ definition]]} - (when definition - {.#Alias de_aliased} - (again {.#Left de_aliased}) - - {.#Definition definition} - {try.#Success definition} - - {.#Default _} - {try.#Failure ..cannot_de-alias_a_default}) - - {try.#Failure error} - {try.#Failure error}) - - {.#Right definition} - {try.#Success definition})))] - (when real_definition - {try.#Success it} - (next input (list.partial [name [exported? it]] output)) - - {try.#Failure error} - {try.#Failure error}))))))) - -(the .public (exports module_name) - (-> Text - (Meta (List [Text Definition]))) - (do ..monad - [constants (..definitions module_name)] - (in (do list.monad - [[name [exported? [def_type def_value]]] constants] - (if exported? - (in [name [def_type def_value]]) - (list)))))) - (the .public modules (Meta (List [Text Module])) (function (_ lux) @@ -715,40 +285,6 @@ (list)) (its .#definitions =module)))))) -(the .public no_local_environment - Error - (location.with (location.here) - "No local environment.")) - -(the .public locals - (Meta (List (List [Text Type]))) - (function (_ lux) - (when (list.inits (its .#scopes lux)) - {try.#Success scopes} - {try.#Success [lux - (list#each (|>> (its [.#locals .#mappings]) - (list#each (function (_ [name [type _]]) - [name type]))) - scopes)]} - - {try.#Failure error} - {try.#Failure ..no_local_environment}))) - -(the .public (de_aliased def_name) - (-> Symbol - (Meta Symbol)) - (do ..monad - [[exported? constant] (..definition def_name)] - (in (when constant - {.#Alias real_def_name} - real_def_name - - {.#Definition _} - def_name - - {.#Default _} - def_name)))) - (the .public (of_try it) (for_any (_ of) (-> (Try of) diff --git a/stdlib/source/library/lux/meta/binding.lux b/stdlib/source/library/lux/meta/binding.lux new file mode 100644 index 0000000000..69bf29ca7b --- /dev/null +++ b/stdlib/source/library/lux/meta/binding.lux @@ -0,0 +1,490 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.require + [library + [lux (.except type alias macro) + [abstract + [monad (.only do)]] + [control + ["[0]" maybe] + ["[0]" try (.only Try)]] + [data + ["[0]" product] + ["[0]" text (.use "[1]#[0]" monoid order)] + [collection + ["[0]" list (.use "[1]#[0]" functor) + ["[0]" property]]]] + [math + [number + ["n" nat]]]]] + ["[0]" // (.only) + ["[0]" location] + ["[0]" symbol (.use "[1]#[0]" absolute)] + ["[0]" code]]) + +(the with_template' (.in_module# .prelude .with_template)) + +(the .public (normal name) + (-> Symbol + (Meta Symbol)) + (when name + ["" name] + (do //.monad + [module_name //.current_module_name] + (in [module_name name])) + + _ + (of //.monad in name))) + +(the (type_variable idx bindings) + (-> Nat (List [Nat (Maybe Type)]) + (Maybe Type)) + (when bindings + {.#End} + {.#None} + + {.#Item [var bound] bindings'} + (if (n.= idx var) + bound + (type_variable idx bindings')))) + +(`` (the (clean_type type) + (-> Type + (Meta Type)) + (when type + {.#Var var} + (function (_ lux) + (when (|> lux + (its [.#type_context .#var_bindings]) + (type_variable var)) + (,, (with_template' [] + [ + {try.#Success [lux type]}] + + [{.#None}] + [{.#Some {.#Var _}}])) + + + {.#Some type'} + {try.#Success [lux type']})) + + _ + (of //.monad in type)))) + +(the (on_either f x1 x2) + (for_any (_ input output) + (-> (-> input (Maybe output)) input input + (Maybe output))) + (when (f x1) + {.#None} + (f x2) + + some + some)) + +(the .public (var_type name) + (-> Text + (Meta Type)) + (function (_ lux) + (let [test (is (-> [Text [Type Any]] Bit) + (|>> product.left (text#= name)))] + (when (do maybe.monad + [scope (list.example (function (_ env) + (.or (list.any? test (is (List [Text [Type Any]]) + (its [.#locals .#mappings] env))) + (list.any? test (is (List [Text [Type Any]]) + (its [.#captured .#mappings] env))))) + (its .#scopes lux)) + [_ [type _]] (on_either (list.example test) + (is (List [Text [Type Any]]) + (its [.#locals .#mappings] scope)) + (is (List [Text [Type Any]]) + (its [.#captured .#mappings] scope)))] + (in type)) + {.#Some var_type} + ((clean_type var_type) lux) + + {.#None} + {try.#Failure (all text#composite "Unknown variable: " name)})))) + +(the without_lux_runtime + (-> (List Text) + (List Text)) + ... The Lux runtime shows up as "" + ... so I'm excluding it. + (list.only (|>> text.empty? not))) + +(the listing_separator + Text + (all text#composite text.new_line " ")) + +(the module_listing + (-> (List Text) + Text) + (|>> ..without_lux_runtime + (list.sorted text#<) + (text.interposed ..listing_separator))) + +(with_template' [ ] + [(the .public ( name) + (-> Symbol + (Meta [Bit Global])) + (do //.monad + [name (..normal name) + .let [[normal_module normal_short] name]] + (function (_ lux) + (when (is (Maybe [Bit Global]) + (do maybe.monad + [(open "[0]") (|> lux + (its .#modules) + (property.value normal_module))] + (property.value normal_short #definitions))) + {.#Some exported?,definition} + {try.#Success [lux exported?,definition]} + + _ + (let [current_module (|> lux (its .#current_module) (maybe.else "???")) + all_known_modules (|> lux + (its .#modules) + (list#each product.left) + ..module_listing)] + {try.#Failure (all text#composite + " All known modules: " all_known_modules text.new_line + (when (property.value current_module (its .#modules lux)) + {try.#Success this_module} + (let [candidates (|> lux + (its .#modules) + (list#each (function (_ [module_name module]) + (|> module + (its .#definitions) + (list.all (function (_ [def_name [exported? global]]) + (`` (when global + { _} + (if (.and exported? + (text#= normal_short def_name)) + {.#Some (symbol#injection [module_name def_name])} + {.#None}) + + _ + {.#None}))))))) + list.together + (list.sorted text#<) + (text.interposed ..listing_separator)) + imports (|> this_module + (its .#imports) + ..module_listing) + aliases (|> this_module + (its .#module_aliases) + (list#each (function (_ [alias real]) (all text#composite alias " => " real))) + (list.sorted text#<) + (text.interposed ..listing_separator))] + (all text#composite + " Aliases: " aliases text.new_line + " Imports: " imports text.new_line + " Candidates: " candidates text.new_line)) + + failure + "") + " Current module: " current_module text.new_line + "Unknown definition: " (symbol#injection name) text.new_line + )})))))] + + [definition .#Definition] + [default' .#Default] + [alias' .#Alias] + ) + +(the .public (export name) + (-> Symbol + (Meta Definition)) + (do [! //.monad] + [name (..normal name) + .let [[expected _] name] + [exported? definition] (..definition name) + actual //.current_module_name] + (when definition + {.#Definition it} + (if (.or exported? + (text#= expected actual)) + (in it) + (//.failure (all text#composite "Definition is not an export: " (symbol#injection name)))) + + {.#Alias it} + (if (.or exported? + (text#= expected actual)) + (export it) + (//.failure (all text#composite "Alias is not an export: " (symbol#injection name)))) + + {.#Default _} + (//.failure (all text#composite + "Defaults are not considered exports: " + (symbol#injection name)))))) + +(the .public (default name) + (-> Symbol + (Meta Default)) + (do [! //.monad] + [name (..normal name) + [exported? definition] (..default' name)] + (when definition + {.#Definition _} + (//.failure (all text#composite + "Definitions are not considered defaults: " + (symbol#injection name))) + + {.#Alias de_aliased} + (//.failure (all text#composite + "Aliases are not considered defaults: " + (symbol#injection name))) + + {.#Default it} + (if exported? + (in it) + (do ! + [.let [[expected _] name] + actual //.current_module_name] + (if (text#= expected actual) + (in it) + (//.failure (all text#composite "Default is not an export: " (symbol#injection name))))))))) + +(the .public (alias name) + (-> Symbol + (Meta Symbol)) + (do [! //.monad] + [name (..normal name) + [exported? it] (..alias' name)] + (when it + {.#Alias it} + (in it) + + _ + (undefined)))) + +(the .public (definition_type name) + (-> Symbol + (Meta Type)) + (do //.monad + [[exported? definition] (definition name)] + (when definition + {.#Alias de_aliased} + (definition_type de_aliased) + + {.#Definition [def_type def_value]} + (clean_type def_type) + + {.#Default _} + (//.failure (all text#composite + "Defaults are not considered definitions: " + (symbol#injection name)))))) + +(the .public (type name) + (-> Symbol + (Meta Type)) + (when name + ["" _name] + (//.either (var_type _name) + (definition_type name)) + + _ + (definition_type name))) + +(the .public (type_definition name) + (-> Symbol + (Meta Type)) + (do //.monad + [[exported? definition] (definition name)] + (when definition + {.#Alias de_aliased} + (type_definition de_aliased) + + {.#Definition [def_type def_value]} + (let [type_code (.in_module# .prelude .type_code)] + (if (.or (same? .Type def_type) + (of code.equivalence = + (type_code .Type) + (type_code def_type))) + (in (as Type def_value)) + (//.failure (all text#composite "Definition is not a type: " (symbol#injection name))))) + + {.#Default _} + (//.failure (all text#composite "Default is not a type: " (symbol#injection name)))))) + +(the .public (globals module) + (-> Text + (Meta (List [Text [Bit Global]]))) + (function (_ lux) + (when (property.value module (its .#modules lux)) + {try.#Success module} + {try.#Success [lux (its .#definitions module)]} + + failure + {try.#Failure (all text#composite "Unknown module: " module)}))) + +(the .public (definitions module) + (-> Text + (Meta (List [Text [Bit Definition]]))) + (of //.monad each + (list.all (function (_ [name [exported? global]]) + (when global + {.#Alias de_aliased} + {.#None} + + {.#Definition definition} + {.#Some [name [exported? definition]]} + + {.#Default _} + {.#None}))) + (..globals module))) + +(the .public cannot_de-alias_a_default + Error + (location.with (location.here) + "Cannot de-alias a default global.")) + +(the .public (resolved_globals module) + (-> Text + (Meta (List [Text [Bit Definition]]))) + (do [! //.monad] + [it (..globals module) + .let [input (is (List [Text Bit (Either Symbol Definition)]) + (list.all (function (_ [name [exported? global]]) + (when global + {.#Alias de_aliased} + {.#Some [name exported? {.#Left de_aliased}]} + + {.#Definition definition} + {.#Some [name exported? {.#Right definition}]} + + {.#Default _} + {.#None})) + it))]] + (function (_ lux) + (loop (next [input input + output (is (List [Text [Bit Definition]]) + (list))]) + (when input + (list) + {try.#Success [lux output]} + + (list.partial [name exported? it] input) + (let [real_definition (is (Try Definition) + (loop (again [it it]) + (when it + {.#Left de_aliased} + (when (..definition de_aliased lux) + {try.#Success [_ [_ definition]]} + (when definition + {.#Alias de_aliased} + (again {.#Left de_aliased}) + + {.#Definition definition} + {try.#Success definition} + + {.#Default _} + {try.#Failure ..cannot_de-alias_a_default}) + + {try.#Failure error} + {try.#Failure error}) + + {.#Right definition} + {try.#Success definition})))] + (when real_definition + {try.#Success it} + (next input (list.partial [name [exported? it]] output)) + + {try.#Failure error} + {try.#Failure error}))))))) + +(the .public (exports module_name) + (-> Text + (Meta (List [Text Definition]))) + (do //.monad + [constants (..definitions module_name)] + (in (do list.monad + [[name [exported? [def_type def_value]]] constants] + (if exported? + (in [name [def_type def_value]]) + (list)))))) + +(the .public no_local_environment + Error + (location.with (location.here) + "No local environment.")) + +(the .public locals + (Meta (List (List [Text Type]))) + (function (_ lux) + (when (list.inits (its .#scopes lux)) + {try.#Success scopes} + {try.#Success [lux + (list#each (|>> (its [.#locals .#mappings]) + (list#each (function (_ [name [type _]]) + [name type]))) + scopes)]} + + {try.#Failure error} + {try.#Failure ..no_local_environment}))) + +(the .public (de_aliased def_name) + (-> Symbol + (Meta Symbol)) + (do //.monad + [[exported? constant] (..definition def_name)] + (in (when constant + {.#Alias real_def_name} + real_def_name + + {.#Definition _} + def_name + + {.#Default _} + def_name)))) + +(the (macro_type? type) + (-> Type + Bit) + (when type + {.#Named [.prelude "Macro"] + {.#Nominal "#Macro" {.#End}}} + true + + _ + false)) + +(the .public not_a_macro + Error + (location.with (location.here) + "Not a macro.")) + +(the .public (macro full_name) + (-> Symbol + (Meta Macro)) + (do //.monad + [full_name (..normal full_name)] + (is (Meta Macro) + (function (_ lux) + (when (//.current_module_name lux) + {try.#Success [_ this_module]} + (let [modules (its .#modules lux)] + (loop (macro [[module name] full_name]) + (do try.monad + [$module (property.value module modules) + [exported? definition] (|> $module + (is Module) + (its .#definitions) + (property.value name))] + (when definition + {.#Alias de_aliased} + (macro de_aliased) + + {.#Definition [def_type def_value]} + (if (macro_type? def_type) + {try.#Success [lux (as Macro def_value)]} + {try.#Failure ..not_a_macro}) + + {.#Default _} + {try.#Failure ..not_a_macro})))) + + {try.#Failure error} + {try.#Failure error}))))) diff --git a/stdlib/source/library/lux/meta/compiler/default/platform.lux b/stdlib/source/library/lux/meta/compiler/default/platform.lux index ae0038b69e..a131c30f2c 100644 --- a/stdlib/source/library/lux/meta/compiler/default/platform.lux +++ b/stdlib/source/library/lux/meta/compiler/default/platform.lux @@ -30,6 +30,7 @@ ["[0]" set (.only Set)] ["[0]" list (.use "[1]#[0]" monoid functor mix)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" static] ["[0]" configuration (.only Configuration)] [type (.only sharing) @@ -808,7 +809,7 @@ ///declaration.#state] state)] [/#type /#value] (|> /#definition - meta.export + binding.export (meta.value meta_state) async#in)] (async#in (if (check.subsumed? ..Custom /#type) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis.lux index 1f644a6695..8616f68183 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis.lux @@ -18,6 +18,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" location] ["[0]" code] [macro @@ -90,7 +91,7 @@ (when it (/.constant @ name) (do [! //.monad] - [it (meta.macro name)] + [it (binding.macro name)] (in {#Macro name it})) _ diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux index b1e428ab4a..0d45ceb4c4 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/complex.lux @@ -23,6 +23,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" code] ["[0]" label] @@ -176,7 +177,7 @@ (-> Phase Symbol Phase) (do [! phase.monad] - [tag (meta.normal tag) + [tag (binding.normal tag) [lefts,right? variantT] (label.tag tag) [lefts right?] (when lefts,right? {.#Some [lefts right? family]} @@ -319,12 +320,12 @@ (if pattern_matching? (phase#in {.#None}) (do phase.monad - [slotH (meta.normal ["" slotH])] + [slotH (binding.normal ["" slotH])] (again tail {.#Item [slotH valueH] output}))) (list.partial [_ {.#Symbol slotH}] valueH tail) (do phase.monad - [slotH (meta.normal slotH)] + [slotH (binding.normal slotH)] (again tail {.#Item [slotH valueH] output})) {.#End} @@ -338,13 +339,13 @@ (Meta Bit)) (of meta.monad each (list.any? (list.any? (|>> product.left (text#= name)))) - meta.locals)) + binding.locals)) (the (slot it) (-> Symbol (Meta Label)) (do meta.monad - [it (meta.normal it)] + [it (binding.normal it)] (label.slot it))) (the (slot_type [[_ it] _]) @@ -462,7 +463,7 @@ (list [_ {.#Symbol pseudo_slot}] singletonC) (do [! phase.monad] - [head_k (meta.normal pseudo_slot) + [head_k (binding.normal pseudo_slot) slot (meta.try (label.slot head_k))] (when slot {try.#Success [lefts,right? recordT]} diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/when.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/when.lux index 5f8b34f27e..b3bc04b3b9 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/when.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/analysis/when.lux @@ -21,6 +21,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code] ["[0]" label] [macro @@ -355,7 +356,7 @@ [location {.#Variant (list.partial [_ {.#Symbol tag}] values)}] (/.with_location location (do phase.monad - [tag (meta.normal tag) + [tag (binding.normal tag) [lefts,right? variantT] (label.tag tag) [lefts right?] (in (.when lefts,right? {.#Some [lefts right? family]} diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux index 99b0b3d5db..4acaec3aa3 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/declaration.lux @@ -14,6 +14,7 @@ [collection ["[0]" list (.use "[1]#[0]" mix monoid)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code] [macro ["^" pattern] @@ -123,7 +124,7 @@ (function (_ _) {.#Some (/.of_analysis (do ! - [macro (meta.macro macro|extension) + [macro (binding.macro macro|extension) expansion (analysis/macro.expansion expander macro|extension macro inputs)] (in {#More expansion})))}))] (when expansion|requirements diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension.lux index 4bc4152f44..10281c40e2 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension.lux @@ -21,6 +21,7 @@ ["[0]" property]] ["[0]" dictionary (.only Dictionary)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] [type (.only sharing) ["[0]" check]]]]] @@ -84,7 +85,7 @@ (-> Symbol (Meta Global)) (do meta.monad - [name (meta.normal name) + [name (binding.normal name) lux meta.compiler_state] (loop (again [[normal_module normal_short] name]) (when (is (Maybe [Bit Global]) diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux index 37be226a03..ad35ffba6d 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/extension/analysis/lux.lux @@ -22,6 +22,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] [module ["[0]" import]] ["[0]" code @@ -287,8 +288,8 @@ (loop (de_aliased [validated_access? false def_name def_name]) (do [! phase.monad] - [(^.let def_name [::module ::name]) (meta.normal def_name) - [exported? constant] (meta.definition def_name) + [(^.let def_name [::module ::name]) (binding.normal def_name) + [exported? constant] (binding.definition def_name) current meta.current_module_name .let [expected (..expected_module current quoted_module)] imported! (import.by? ::module expected)] diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux index 2536ae2060..edce6aba36 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/js/runtime.lux @@ -4,7 +4,7 @@ (.require [library [lux (.except Declaration - i64 left right variant) + i64 variant) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux index e10883de4a..3e20f4652b 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/lua/runtime.lux @@ -4,7 +4,7 @@ (.require [library [lux (.except Label Location Declaration - left right variant) + variant) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux index 45dddfa922..af09f98de4 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/python/runtime.lux @@ -4,7 +4,7 @@ (.require [library [lux (.except Declaration - ++ left right variant) + ++ variant) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux index 1a5bbdd566..e419f1b798 100644 --- a/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux +++ b/stdlib/source/library/lux/meta/compiler/language/lux/phase/translation/ruby/runtime.lux @@ -4,7 +4,7 @@ (.require [library [lux (.except Declaration - i64 left right variant) + i64 variant) [abstract ["[0]" monad (.only do)]] [control diff --git a/stdlib/source/library/lux/meta/label.lux b/stdlib/source/library/lux/meta/label.lux index 94ae153ed1..51de66a6b8 100644 --- a/stdlib/source/library/lux/meta/label.lux +++ b/stdlib/source/library/lux/meta/label.lux @@ -15,6 +15,7 @@ [list ["[0]" property]]]]]] ["[0]" // (.only) + ["[0]" binding] ["[0]" symbol (.use "[1]#[0]" equivalence absolute)] ["[0]" type (.use "[1]#[0]" equivalence)] [macro @@ -48,7 +49,7 @@ (-> Symbol (Meta Label)) (do //.monad - [it (//.normal it) + [it (binding.normal it) module (//.module (symbol.module it)) this_module_name //.current_module_name] (when (property.value (symbol.short it) (its .#definitions module)) @@ -72,7 +73,7 @@ (-> Symbol (Meta (List Symbol))) (do //.monad - [type_name (//.normal type_name) + [type_name (binding.normal type_name) module (//.module (symbol.module type_name))] (loop (,plural [definitions (its .#definitions module)]) (when definitions diff --git a/stdlib/source/library/lux/meta/macro/context.lux b/stdlib/source/library/lux/meta/macro/context.lux index f2b2ca8469..4758f01d14 100644 --- a/stdlib/source/library/lux/meta/macro/context.lux +++ b/stdlib/source/library/lux/meta/macro/context.lux @@ -20,6 +20,7 @@ ["[0]" meta (.only) [type (.only sharing by_example)] ["[0]" symbol (.use "[1]#[0]" absolute)] + ["[0]" binding] ["[0]" code (.only) ["?[1]" \\projection]]]]] ["[0]" // (.only) @@ -54,7 +55,7 @@ (Meta Any)) (do meta.monad [.let [[@ expected_name] it] - defs (meta.definitions @)] + defs (binding.definitions @)] (when (list.one (function (_ [actual_name [exported? [type value]]]) (if (text#= expected_name actual_name) {.#Some value} diff --git a/stdlib/source/library/lux/meta/macro/expansion.lux b/stdlib/source/library/lux/meta/macro/expansion.lux index 44e6deac51..f487a851fb 100644 --- a/stdlib/source/library/lux/meta/macro/expansion.lux +++ b/stdlib/source/library/lux/meta/macro/expansion.lux @@ -15,7 +15,8 @@ ["[0]" /// (.only) ["[0]" code] ["[0]" location] - ["[0]" symbol (.use "[1]#[0]" absolute)]]) + ["[0]" symbol (.use "[1]#[0]" absolute)] + ["[0]" binding]]) (the with_template' (.in_module# .prelude .with_template)) @@ -25,7 +26,7 @@ (when syntax [_ {.#Form {.#Item [[_ {.#Symbol name}] args]}}] (do ///.monad - [?macro (///.try (///.macro name))] + [?macro (///.try (binding.macro name))] (when ?macro {try.#Success macro} ((as Macro' macro) args) @@ -42,7 +43,7 @@ (when syntax [_ {.#Form {.#Item [[_ {.#Symbol name}] args]}}] (do ///.monad - [?macro (///.try (///.macro name))] + [?macro (///.try (binding.macro name))] (when ?macro {try.#Success macro} (do [! ///.monad] @@ -63,7 +64,7 @@ (when syntax [_ {.#Form {.#Item [[_ {.#Symbol name}] args]}}] (do ///.monad - [?macro (///.try (///.macro name))] + [?macro (///.try (binding.macro name))] (when ?macro {try.#Success macro} (do ///.monad diff --git a/stdlib/source/library/lux/meta/macro/local.lux b/stdlib/source/library/lux/meta/macro/local.lux index d4789fe424..ae8c3b227f 100644 --- a/stdlib/source/library/lux/meta/macro/local.lux +++ b/stdlib/source/library/lux/meta/macro/local.lux @@ -17,6 +17,7 @@ ["[0]" list (.use "[1]#[0]" functor) ["[0]" property]]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection]]]]] ["[0]" // (.only) @@ -64,7 +65,7 @@ (-> [Symbol Macro] (Meta Any)) (do meta.monad - [[module_name definition_name] (meta.normal name) + [[module_name definition_name] (binding.normal name) .let [definition (is Global {.#Definition [.Macro macro]}) add_macro! (is (-> (property.List [Bit Global]) (property.List [Bit Global])) (property.has definition_name [false definition]))]] @@ -84,7 +85,7 @@ (-> Symbol (Meta Any)) (do meta.monad - [[module_name definition_name] (meta.normal name) + [[module_name definition_name] (binding.normal name) .let [lacks_macro! (is (-> (property.List [Bit Global]) (property.List [Bit Global])) (property.lacks definition_name))]] (..with_module module_name diff --git a/stdlib/source/library/lux/meta/macro/vocabulary.lux b/stdlib/source/library/lux/meta/macro/vocabulary.lux index 033ab4931a..10f5f71bbf 100644 --- a/stdlib/source/library/lux/meta/macro/vocabulary.lux +++ b/stdlib/source/library/lux/meta/macro/vocabulary.lux @@ -14,6 +14,7 @@ ["[0]" syntax (.only) ["[0]" export]] ["/[1]" // (.only) + ["[0]" binding] ["[0]" code (.only) ["?[1]" \\projection (.only Projection)]] ["[0]" type (.only) @@ -49,7 +50,7 @@ (` (.the (, public|private@by_name) ((, by_name) (, g!_)) (-> Symbol (Meta Macro)) (do ///.monad - [[(, g!type) (, g!value)] (///.export (, g!_))] + [[(, g!type) (, g!value)] (binding.export (, g!_))] (if (of type.equivalence (,' =) (, type) (, g!type)) ((,' in) ((, macro) (as (, type) (, g!value)))) (///.failure (exception.error ..invalid_type [(, type) (, g!type)]))))))))))) diff --git a/stdlib/source/library/lux/meta/type.lux b/stdlib/source/library/lux/meta/type.lux index 96f4df0192..8daa3e9f9c 100644 --- a/stdlib/source/library/lux/meta/type.lux +++ b/stdlib/source/library/lux/meta/type.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except function as let variant tuple only except) + [lux (.except function as let variant tuple) [abstract [equivalence (.only Equivalence)] [format (.only Format)] @@ -26,6 +26,7 @@ ["[0]" meta (.use "[1]#[0]" functor) ["[0]" location] ["[0]" symbol (.use "[1]#[0]" equivalence)] + ["[0]" binding] ["[0]" code (.only) ["?[1]" \\projection (.only Projection)]] ["[0]" macro (.only) @@ -464,7 +465,7 @@ {.#Left [valueN valueC]} (do meta.monad [location meta.location - valueT (meta.type valueN) + valueT (binding.type valueN) .let [[@ _ _] location _ (.log!# (all text#composite (of symbol.absolute injection (symbol ..log!)) " " (location.injection location) text.new_line @@ -598,7 +599,7 @@ (-> Symbol (List Code) (Meta [(List Type) Type])) (do [! meta.monad] - [[it _] (meta.export it) + [[it _] (binding.export it) parameters (monad.each ! (|>> (meta.eval Type) (of ! each (|>> (.as Type)))) parameters) diff --git a/stdlib/source/library/lux/meta/type/implicit.lux b/stdlib/source/library/lux/meta/type/implicit.lux index dac31531e1..d2d971b882 100644 --- a/stdlib/source/library/lux/meta/type/implicit.lux +++ b/stdlib/source/library/lux/meta/type/implicit.lux @@ -22,6 +22,7 @@ ["[0]" number (.only) ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" label] [module ["[0]" import]] @@ -57,7 +58,7 @@ (-> Symbol (Meta Type)) (do meta.monad - [raw_type (meta.type var_name) + [raw_type (binding.type var_name) compiler meta.compiler_state] (when raw_type {.#Var id} @@ -97,7 +98,7 @@ (when member ["" simple_name] (meta.either (do meta.monad - [member (meta.normal member) + [member (binding.normal member) _ (label.slot member)] (in member)) (do [! meta.monad] @@ -170,7 +171,7 @@ (-> Type (Meta (List [Symbol Type]))) (do meta.monad - [local_batches meta.locals + [local_batches binding.locals .let [total_locals (list#mix (function (_ [name type] table) (try.else table (dictionary.has' name type table))) (is (Dictionary Text Type) @@ -188,7 +189,7 @@ (Meta (List [Symbol Type]))) (do [! meta.monad] [this_module_name meta.current_module_name - definitions (meta.resolved_globals this_module_name)] + definitions (binding.resolved_globals this_module_name)] (in (available_definitions sig_type this_module_name this_module_name definitions {.#End})))) (the (imported_structs sig_type) @@ -197,7 +198,7 @@ (do [! meta.monad] [this_module_name meta.current_module_name imported_modules (import.all this_module_name) - accessible_definitions (monad.each ! meta.resolved_globals imported_modules)] + accessible_definitions (monad.each ! binding.resolved_globals imported_modules)] (in (list#mix (function (_ [imported_module definitions] tail) (available_definitions sig_type imported_module this_module_name definitions tail)) {.#End} diff --git a/stdlib/source/library/lux/meta/type/nominal.lux b/stdlib/source/library/lux/meta/type/nominal.lux index a359c04791..57acf694f0 100644 --- a/stdlib/source/library/lux/meta/type/nominal.lux +++ b/stdlib/source/library/lux/meta/type/nominal.lux @@ -4,7 +4,6 @@ (.require [library [lux (.except every) - ["[0]" meta] [abstract [monad (.only do)]] [control @@ -12,8 +11,9 @@ [data [collection ["[0]" list (.use "[1]#[0]" functor)]]] - [meta + ["[0]" meta (.only) ["[0]" symbol (.use "[1]#[0]" absolute equivalence)] + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection (.only Projection)]] ["[0]" macro (.only) @@ -59,7 +59,7 @@ [[name type_vars abstraction representation] (when frame {.#Some frame} (do ! - [frame (meta.normal frame)] + [frame (binding.normal frame)] (..specific frame)) {.#None} diff --git a/stdlib/source/library/lux/meta/type/record.lux b/stdlib/source/library/lux/meta/type/record.lux index fb9a2393a6..ce9974abe7 100644 --- a/stdlib/source/library/lux/meta/type/record.lux +++ b/stdlib/source/library/lux/meta/type/record.lux @@ -20,6 +20,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" location] ["[0]" symbol] ["[0]" label] @@ -33,7 +34,7 @@ (syntax.macro (_ [label ?code.global parameters (?code.tuple (?.some ?code.any))]) (do [! meta.monad] - [full_label (meta.normal label) + [full_label (binding.normal label) label (meta.or (label.tag full_label) (label.slot full_label)) parameters (monad.each ! (|>> (meta.eval Type) diff --git a/stdlib/source/library/lux/music/balance.lux b/stdlib/source/library/lux/music/balance.lux index 2997880202..a5aa6f81f7 100644 --- a/stdlib/source/library/lux/music/balance.lux +++ b/stdlib/source/library/lux/music/balance.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right)]]) + [lux (.except)]]) ... https://en.wikipedia.org/wiki/Stereophonic_sound#Balance (every .public Balance diff --git a/stdlib/source/library/lux/music/panning.lux b/stdlib/source/library/lux/music/panning.lux index d45fdb4bcf..1a2b90c140 100644 --- a/stdlib/source/library/lux/music/panning.lux +++ b/stdlib/source/library/lux/music/panning.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right)]]) + [lux (.except)]]) ... https://en.wikipedia.org/wiki/Panning_(audio) (every .public Panning diff --git a/stdlib/source/library/lux/test/coverage.lux b/stdlib/source/library/lux/test/coverage.lux index 678f191416..676699923c 100644 --- a/stdlib/source/library/lux/test/coverage.lux +++ b/stdlib/source/library/lux/test/coverage.lux @@ -13,6 +13,7 @@ ["[0]" list (.use "[1]#[0]" mix functor)] ["[0]" set (.only Set)]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" code (.only) ["<[1]>" \\projection]] @@ -30,7 +31,7 @@ (, (code.text (symbol.short symbol)))]))))] (syntax.macro (_ [name .global]) (do meta.monad - [_ (meta.export name)] + [_ (binding.export name)] (in (list (symbol name))))))) (the separator diff --git a/stdlib/source/library/lux/test/property.lux b/stdlib/source/library/lux/test/property.lux index f15892923a..2b3e43810f 100644 --- a/stdlib/source/library/lux/test/property.lux +++ b/stdlib/source/library/lux/test/property.lux @@ -43,7 +43,7 @@ ["[0]" environment] ["[0]" console] [time - [duration (.only Duration)] + ["[0]" duration (.only Duration)] ["[0]" instant]]]]] [// ["//" unit] @@ -197,7 +197,7 @@ (maybe.else raw) (text.suffix "%"))))))] (exception.report - (list ["Duration" (%.duration duration)] + (list ["Duration" (duration.as_text duration)] ["Tests" (%.nat (n.+ successes failures))] ["Successes" (%.nat successes)] diff --git a/stdlib/source/library/lux/test/unit.lux b/stdlib/source/library/lux/test/unit.lux index 233aeed3bb..e1bee75825 100644 --- a/stdlib/source/library/lux/test/unit.lux +++ b/stdlib/source/library/lux/test/unit.lux @@ -23,6 +23,7 @@ [math [number (.only hex)]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" symbol] ["[0]" code (.only) ["<[1]>" \\projection]] @@ -161,7 +162,7 @@ test .any]) (do meta.monad [.let [module (symbol.module module)] - definitions (meta.resolved_globals module) + definitions (binding.resolved_globals module) .let [coverage (|> definitions (list#mix (function (_ [short [exported? _]] aggregate) (if exported? diff --git a/stdlib/source/library/lux/web/css/property.lux b/stdlib/source/library/lux/web/css/property.lux index b221495233..f36569fdda 100644 --- a/stdlib/source/library/lux/web/css/property.lux +++ b/stdlib/source/library/lux/web/css/property.lux @@ -3,7 +3,8 @@ (.require [library - [lux (.except All Location all left right) + [lux (.except All Location + all) [data ["[0]" text]] [meta diff --git a/stdlib/source/library/lux/world/input/keyboard.lux b/stdlib/source/library/lux/world/input/keyboard.lux index 3b1a517968..c50afdc70f 100644 --- a/stdlib/source/library/lux/world/input/keyboard.lux +++ b/stdlib/source/library/lux/world/input/keyboard.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right r) + [lux (.except r) [meta [macro ["[0]" template]]]]]) diff --git a/stdlib/source/library/lux/world/time.lux b/stdlib/source/library/lux/world/time.lux index 29aed8770c..c3f462774d 100644 --- a/stdlib/source/library/lux/world/time.lux +++ b/stdlib/source/library/lux/world/time.lux @@ -206,8 +206,8 @@ .nat ..of_millis)) -(the (injection time) - (-> Time Text) +(the .public (as_text time) + (text.Injection Time) (let [(open "_[0]") (..clock time) segment (of (n.padded 2 n.decimal) injection)] (all text#composite @@ -220,5 +220,5 @@ (the .public format (Format Text Time) (implementation - (the injection ..injection) + (the injection ..as_text) (the projection (.value ..projection)))) diff --git a/stdlib/source/library/lux/world/time/date.lux b/stdlib/source/library/lux/world/time/date.lux index c347c27c3f..8c5a3cff7c 100644 --- a/stdlib/source/library/lux/world/time/date.lux +++ b/stdlib/source/library/lux/world/time/date.lux @@ -183,8 +183,8 @@ utc_day ..section_projection] (<>.of_try (..date utc_year month utc_day)))) -(the (injection value) - (-> Date Text) +(the .public (as_text value) + (text.Injection Date) (let [segment (of (n.padded 2 n.decimal) injection)] (all text#composite (of //year.format injection (..year value)) @@ -194,7 +194,7 @@ (the .public format (Format Text Date) (implementation - (the injection ..injection) + (the injection ..as_text) (the projection (.value ..projection)))) (the days_per_leap diff --git a/stdlib/source/library/lux/world/time/day.lux b/stdlib/source/library/lux/world/time/day.lux index 448f5796d7..5657489ae2 100644 --- a/stdlib/source/library/lux/world/time/day.lux +++ b/stdlib/source/library/lux/world/time/day.lux @@ -11,11 +11,14 @@ [enum (.only Enum)] [format (.only Format)]] [control + ["?" projection (.use "[1]#[0]" monad)] ["[0]" try (.only Try)] ["[0]" exception (.only Exception)]] [data - ["[0]" text (.use "[1]#[0]" monoid)]] + ["[0]" text (.use "[1]#[0]" monoid) + ["?[1]" \\projection (.only Projection)]]] [math + ["[0]" random (.only Random)] [number ["n" nat]]] [meta @@ -100,32 +103,27 @@ {#Saturday} {#Friday} {#Sunday} {#Saturday})))) -(exception.the .public (not_a_day_of_the_week value) - (Exception Text) - (exception.report - (list ["Value" (text.injection value)]))) - -(the .public format - (Format Text Day) - (implementation - (the (injection value) - (`` (when value - (,, (template.with [] - [{} - (text.replaced "#" "" (template.text []))] - - [..#Monday] - [..#Tuesday] - [..#Wednesday] - [..#Thursday] - [..#Friday] - [..#Saturday] - [..#Sunday]))))) - (the (projection value) - (`` (when (text#composite "#" value) - (,, (template.with [] - [(template.text []) - {try.#Success {}}] +(the .public (as_text value) + (text.Injection Day) + (`` (when value + (,, (template.with [] + [{} + (text.replaced "#" "" (template.text []))] + + [..#Monday] + [..#Tuesday] + [..#Wednesday] + [..#Thursday] + [..#Friday] + [..#Saturday] + [..#Sunday]))))) + +(the .public projection + (Projection Day) + (`` (all ?.either + (,, (template.with [,tag] + [(?.after (?text.this (text.replaced "#" "" (template.text [,tag]))) + (?#in {,tag}))] [..#Monday] [..#Tuesday] @@ -134,9 +132,13 @@ [..#Friday] [..#Saturday] [..#Sunday])) - - _ - (exception.except ..not_a_day_of_the_week [value])))))) + ))) + +(the .public format + (Format Text Day) + (implementation + (the injection ..as_text) + (the projection (?text.value ..projection)))) (the .public week (List Day) @@ -202,3 +204,14 @@ [11 #Thursday] [13 #Friday] [17 #Saturday]))))))) + +(the .public random + (Random Day) + (let [(open "random#[0]") random.monad] + (random.either (random.either (random#in {..#Sunday}) + (random.either (random#in {..#Monday}) + (random#in {..#Tuesday}))) + (random.either (random.either (random#in {..#Wednesday}) + (random#in {..#Thursday})) + (random.either (random#in {..#Friday}) + (random#in {..#Saturday})))))) diff --git a/stdlib/source/library/lux/world/time/duration.lux b/stdlib/source/library/lux/world/time/duration.lux index 559c802ad0..bd00ecfd1a 100644 --- a/stdlib/source/library/lux/world/time/duration.lux +++ b/stdlib/source/library/lux/world/time/duration.lux @@ -145,7 +145,7 @@ ["-" negative_sign] ) -(the (injection duration) +(the .public (as_text duration) (if (of ..equivalence = ..empty duration) (all text#composite ..positive_sign @@ -172,7 +172,7 @@ (if (i.= +0 millis) "" (text#composite (nat#injection (.nat millis)) ..milli_second_suffix)) )))) -(the projection +(the .public projection (Projection Duration) (let [section (is (-> Text Text (Projection Nat)) (function (_ suffix false_suffix) @@ -204,7 +204,7 @@ (the .public format (Format Text Duration) (implementation - (the injection ..injection) + (the injection ..as_text) (the projection (.value ..projection)))) (the .public (difference from to) diff --git a/stdlib/source/library/lux/world/time/month.lux b/stdlib/source/library/lux/world/time/month.lux index f7b5295cde..cc86bfb2eb 100644 --- a/stdlib/source/library/lux/world/time/month.lux +++ b/stdlib/source/library/lux/world/time/month.lux @@ -11,10 +11,12 @@ [enum (.only Enum)] [format (.only Format)]] [control + ["?" projection (.use "[1]#[0]" monad)] ["[0]" try (.only Try)] ["[0]" exception (.only Exception)]] [data - ["[0]" text (.use "[1]#[0]" monoid)]] + ["[0]" text (.use "[1]#[0]" monoid) + ["?[1]" \\projection (.only Projection)]]] [math [number ["n" nat]]] @@ -216,37 +218,32 @@ {#November} {#December})) -(exception.the .public (not_a_month_of_the_year value) - (Exception Text) - (exception.report - (list ["Value" (text.injection value)]))) +(the .public (as_text value) + (text.Injection Month) + (`` (when value + (,, (template.with [] + [{} + (text.replaced "#" "" (template.text []))] -(the .public format - (Format Text Month) - (implementation - (the (injection value) - (`` (when value - (,, (template.with [] - [{} - (text.replaced "#" "" (template.text []))] + [..#January] + [..#February] + [..#March] + [..#April] + [..#May] + [..#June] + [..#July] + [..#August] + [..#September] + [..#October] + [..#November] + [..#December]))))) - [..#January] - [..#February] - [..#March] - [..#April] - [..#May] - [..#June] - [..#July] - [..#August] - [..#September] - [..#October] - [..#November] - [..#December]))))) - (the (projection value) - (`` (when (text#composite "#" value) - (,, (template.with [] - [(template.text []) - {try.#Success {}}] +(the .public projection + (Projection Month) + (`` (all ?.either + (,, (template.with [,tag] + [(?.after (?text.this (text.replaced "#" "" (template.text [,tag]))) + (?#in {,tag}))] [..#January] [..#February] @@ -260,6 +257,10 @@ [..#October] [..#November] [..#December])) - - _ - (exception.except ..not_a_month_of_the_year [value])))))) + ))) + +(the .public format + (Format Text Month) + (implementation + (the injection ..as_text) + (the projection (?text.value ..projection)))) diff --git a/stdlib/source/program/compositor.lux b/stdlib/source/program/compositor.lux index 9fe4881aaa..7d21fd6ff3 100644 --- a/stdlib/source/program/compositor.lux +++ b/stdlib/source/program/compositor.lux @@ -68,7 +68,8 @@ ["[0]" file (.only) ["[1]/[0]" extension]] [time - ["[0]" instant]]]]]) + ["[0]" instant] + ["[0]" duration]]]]]) (the (or_crash! failure_description action) (for_any (_ of) @@ -106,7 +107,7 @@ output process .let [_ (debug.log! (|> (io.value instant.now) (instant.span start) - %.duration + duration.as_text (%.message "Duration: ")))]] (in output))) diff --git a/stdlib/source/projection/lux/data/collection/tree.lux b/stdlib/source/projection/lux/data/collection/tree.lux index 82601fc2ef..c4f74e45bf 100644 --- a/stdlib/source/projection/lux/data/collection/tree.lux +++ b/stdlib/source/projection/lux/data/collection/tree.lux @@ -3,7 +3,7 @@ (.require [library - [lux (.except left right) + [lux (.except) [abstract [monad (.only do)]] [control diff --git a/stdlib/source/test/lux.lux b/stdlib/source/test/lux.lux index b362443e32..640944cd40 100644 --- a/stdlib/source/test/lux.lux +++ b/stdlib/source/test/lux.lux @@ -802,15 +802,15 @@ mid (random.lower_cased 1) right (random.lower_cased 1) .let [expected (text.interposed "" (list left mid right))]] - (_.coverage [/.all /.left] - (expansion.let [ (/.left %.message - left - mid - right) - (/.all %.message - left - mid - right)] + (_.coverage [/.left_associative /.right_associative] + (expansion.let [ (/.left_associative %.message + left + mid + right) + (/.right_associative %.message + left + mid + right)] (and (text#= ) (not (code#= (' ) diff --git a/stdlib/source/test/lux/data/text.lux b/stdlib/source/test/lux/data/text.lux index 9ec89210d6..68e14237f8 100644 --- a/stdlib/source/test/lux/data/text.lux +++ b/stdlib/source/test/lux/data/text.lux @@ -55,12 +55,6 @@ [macro ["^" pattern] ["[0]" template]]] - [world - ["[0]" time (.only) - ["[0]" day] - ["[0]" month] - ["[0]" duration] - ["[0]" date]]] [test ["_" property (.only Test)]]]] ["$[0]" // @@ -120,11 +114,6 @@ [\\injection.dec dec.decimal random.dec] [\\injection.frac frac.format random.frac] [\\injection.symbol symbol.absolute ($//symbol.random 5 5)] - [\\injection.day day.format random.day] - [\\injection.month month.format random.month] - [\\injection.duration duration.format random.duration] - ... [\\injection.date date.format random.date] - ... [\\injection.time time.format random.time] [\\injection.int_2 int.binary random.int] [\\injection.int_8 int.octal random.int] diff --git a/stdlib/source/test/lux/documentation/remember.lux b/stdlib/source/test/lux/documentation/remember.lux index e8597f6f93..da5577008f 100644 --- a/stdlib/source/test/lux/documentation/remember.lux +++ b/stdlib/source/test/lux/documentation/remember.lux @@ -40,7 +40,7 @@ (the (memory macro deadline message focus) (-> Symbol Date Text (Maybe Code) Code) (` ((, (code.symbol macro)) - (, (code.text (%.date deadline))) + (, (code.text (date.as_text deadline))) (, (code.text message)) (,* (when focus {.#None} (list) @@ -60,7 +60,7 @@ (the (test_failure deadline message focus failure) (-> Date Text (Maybe Code) Text Bit) - (and (text.contains? (%.date deadline) failure) + (and (text.contains? (date.as_text deadline) failure) (text.contains? message failure) (when focus {.#None} diff --git a/stdlib/source/test/lux/math/logic/continuous.lux b/stdlib/source/test/lux/math/logic/continuous.lux index 82435baba0..fc9d410e0c 100644 --- a/stdlib/source/test/lux/math/logic/continuous.lux +++ b/stdlib/source/test/lux/math/logic/continuous.lux @@ -55,8 +55,8 @@ (r.= left (/.or left left)) associativity! - (r.= (all /.or left mid right) - (.left /.or left mid right))] + (r.= (.right_associative /.or left mid right) + (.left_associative /.or left mid right))] (and identity! annihilation! idempotence! @@ -75,8 +75,8 @@ (r.= left (/.and left left)) associativity! - (r.= (all /.and left mid right) - (.left /.and left mid right))] + (r.= (.right_associative /.and left mid right) + (.left_associative /.and left mid right))] (and identity! annihilation! idempotence! diff --git a/stdlib/source/test/lux/math/random.lux b/stdlib/source/test/lux/math/random.lux index 86ea363f73..58cc6ef1b7 100644 --- a/stdlib/source/test/lux/math/random.lux +++ b/stdlib/source/test/lux/math/random.lux @@ -46,9 +46,7 @@ [world ["[0]" time (.only) ["[0]" date] - ["[0]" duration] - ["[0]" month] - ["[0]" day]]] + ["[0]" month]]] [test ["_" property (.only Test)]]]] [\\library @@ -150,9 +148,7 @@ ... [/.time time.equivalence] ... [/.date date.equivalence] - [/.duration duration.equivalence] [/.month month.equivalence] - [/.day day.equivalence] )) (do /.monad [? (distinct dec.equivalence (/.only dec.number? /.dec))] diff --git a/stdlib/source/test/lux/meta.lux b/stdlib/source/test/lux/meta.lux index 8ddfdca28e..f6cc265bfe 100644 --- a/stdlib/source/test/lux/meta.lux +++ b/stdlib/source/test/lux/meta.lux @@ -50,6 +50,7 @@ ["[1][0]" global] ["[1][0]" compiler] ["[1][0]" label] + ["[1][0]" binding] [module ["[1][0]" import]]]) @@ -286,17 +287,6 @@ (/.value expected_lux) (!expect (^.multi {try.#Success actual_modules} (same? expected_modules actual_modules))))) - (_.coverage [/.normal] - (and (|> (/.normal ["" expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success [actual_module actual_short]} - (and (text#= expected_current_module actual_module) - (same? expected_short actual_short))))) - (|> (/.normal [dummy_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success [actual_module actual_short]} - (and (text#= dummy_module actual_module) - (same? expected_short actual_short))))))) )))) (the random_location @@ -373,428 +363,6 @@ (try.else false))) ))) -(the definition_related - Test - (do [! random.monad] - [expected_current_module (random.upper_cased 1) - expected_macro_module (random.only (|>> (text#= expected_current_module) not) - (random.upper_cased 1)) - expected_short (random.upper_cased 1) - expected_type (of ! each (function (_ name) - {.#Nominal name (list)}) - (random.upper_cased 1)) - expected_value (random.either (in .the) - (in .macro)) - .let [expected_lux - (is (-> Bit (Maybe Type) - [(List [Text [Bit .Global]]) - (List [Text [Bit .Global]]) - Lux]) - (function (_ exported? def_type) - (let [current_globals (is (List [Text [Bit .Global]]) - (list [expected_short - [false {.#Alias [expected_macro_module expected_short]}]])) - macro_globals (is (List [Text [Bit .Global]]) - (when def_type - {.#Some def_type} - (list [expected_short - [exported? {.#Definition [def_type expected_value]}]]) - - {.#None} - (list)))] - [current_globals - macro_globals - [.#info [.#target "" - .#version "" - .#mode {.#Build} - .#configuration (list)] - .#source [location.dummy 0 ""] - .#location location.dummy - .#current_module {.#Some expected_current_module} - .#modules (list [expected_current_module - [.#module_hash 0 - .#module_aliases (list) - .#definitions current_globals - .#imports (list) - .#module_state {.#Active}]] - [expected_macro_module - [.#module_hash 0 - .#module_aliases (list) - .#definitions macro_globals - .#imports (list) - .#module_state {.#Active}]]) - .#scopes (list) - .#type_context [.#ex_counter 0 - .#var_counter 0 - .#var_bindings (list)] - .#expected {.#None} - .#seed 0 - .#scope_type_vars (list) - .#extensions [] - .#eval (as (-> Type Code (Meta Any)) []) - .#host []]])))]] - (all _.and - (_.coverage [.Global - .#Definition .#Alias .#Default - - .Alias /.globals] - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro}) - - current_globals! - (|> (/.globals expected_current_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_globals} - (same? current_globals actual_globals)))) - - macro_globals! - (|> (/.globals expected_macro_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_globals} - (same? macro_globals actual_globals))))] - (and current_globals! - macro_globals!))) - (_.coverage [.Definition /.definitions] - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro})] - (and (|> (/.definitions expected_current_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 0 (list.size actual_definitions))))) - (|> (/.definitions expected_macro_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 1 (list.size actual_definitions))))) - ))) - (_.coverage [/.exports] - (and (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro})] - (and (|> (/.exports expected_current_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 0 (list.size actual_definitions))))) - (|> (/.exports expected_macro_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 1 (list.size actual_definitions))))) - )) - (let [[current_globals macro_globals expected_lux] - (expected_lux false {.#Some .Macro})] - (and (|> (/.exports expected_current_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 0 (list.size actual_definitions))))) - (|> (/.exports expected_macro_module) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_definitions} - (n.= 0 (list.size actual_definitions))))) - )))) - ))) - -(the search_related - Test - (do [! random.monad] - [expected_exported? random.bit - expected_current_module (random.upper_cased 1) - expected_macro_module (random.only (|>> (text#= expected_current_module) not) - (random.upper_cased 1)) - expected_short (random.upper_cased 1) - expected_type (of ! each (function (_ name) - {.#Nominal name (list)}) - (random.upper_cased 1)) - expected_value (random.either (in .the) - (in .macro)) - .let [expected_lux - (is (-> Bit (Maybe Type) - [(List [Text [Bit .Global]]) - (List [Text [Bit .Global]]) - Lux]) - (function (_ exported? def_type) - (let [current_globals (is (List [Text [Bit .Global]]) - (list [expected_short - [false {.#Alias [expected_macro_module expected_short]}]])) - macro_globals (is (List [Text [Bit .Global]]) - (when def_type - {.#Some def_type} - (list [expected_short - [exported? {.#Definition [def_type expected_value]}]]) - - {.#None} - (list)))] - [current_globals - macro_globals - [.#info [.#target "" - .#version "" - .#mode {.#Build} - .#configuration (list)] - .#source [location.dummy 0 ""] - .#location location.dummy - .#current_module {.#Some expected_current_module} - .#modules (list [expected_current_module - [.#module_hash 0 - .#module_aliases (list) - .#definitions current_globals - .#imports (list) - .#module_state {.#Active}]] - [expected_macro_module - [.#module_hash 0 - .#module_aliases (list) - .#definitions macro_globals - .#imports (list) - .#module_state {.#Active}]]) - .#scopes (list) - .#type_context [.#ex_counter 0 - .#var_counter 0 - .#var_bindings (list)] - .#expected {.#None} - .#seed 0 - .#scope_type_vars (list) - .#extensions [] - .#eval (as (-> Type Code (Meta Any)) []) - .#host []]])))]] - (all _.and - (_.coverage [/.export] - (and (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some expected_type})] - (|> (/.export [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect {try.#Success _}))) - (let [[current_globals macro_globals expected_lux] - (expected_lux false {.#Some expected_type})] - (|> (/.export [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect {try.#Failure _}))))) - (_.coverage [/.macro - /.not_a_macro] - (let [same_module! - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro})] - (|> (/.macro [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_value} - (same? expected_value actual_value))))) - - not_macro! - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some expected_type})] - (|> (/.macro [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect {try.#Failure /.not_a_macro}))) - - not_found! - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#None})] - (|> (/.macro [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect {try.#Failure _}))) - - aliasing! - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro})] - (|> (/.macro [expected_current_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_value} - (same? expected_value actual_value)))))] - (and same_module! - not_macro! - not_found! - aliasing!))) - (_.coverage [/.de_aliased] - (let [[current_globals macro_globals expected_lux] - (expected_lux true {.#Some .Macro})] - (and (|> (/.de_aliased [expected_macro_module expected_short]) - (/.value expected_lux) - (try#each (symbol#= [expected_macro_module expected_short])) - (try.else false)) - (|> (/.de_aliased [expected_current_module expected_short]) - (/.value expected_lux) - (try#each (symbol#= [expected_macro_module expected_short])) - (try.else false))))) - (_.coverage [/.definition] - (let [[current_globals macro_globals expected_lux] - (expected_lux expected_exported? {.#Some expected_type}) - - definition! - (|> (/.definition [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success [actual_exported? {.#Definition [actual_type actual_value]}]} - (and (bit#= expected_exported? actual_exported?) - (same? expected_type actual_type) - (same? (as Any expected_value) actual_value))))) - - alias! - (|> (/.definition [expected_current_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success [.false {.#Alias [actual_module actual_short]}]} - (and (same? expected_macro_module actual_module) - (same? expected_short actual_short)))))] - (and definition! - alias!))) - (_.coverage [/.definition_type] - (let [[current_globals macro_globals expected_lux] - (expected_lux expected_exported? {.#Some expected_type}) - - definition! - (|> (/.definition_type [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_type} - (same? expected_type actual_type)))) - - alias! - (|> (/.definition_type [expected_current_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_type} - (same? expected_type actual_type))))] - (and definition! - alias!))) - (_.coverage [/.type_definition] - (let [[current_globals macro_globals expected_lux] - (expected_lux expected_exported? {.#Some .Type}) - - definition! - (|> (/.type_definition [expected_macro_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_value} - (same? (as .Type expected_value) actual_value)))) - - alias! - (|> (/.type_definition [expected_current_module expected_short]) - (/.value expected_lux) - (!expect (^.multi {try.#Success actual_value} - (same? (as .Type expected_value) actual_value))))] - (and definition! - alias!))) - ))) - -(the locals_related - Test - (do [! random.monad] - [current_module (random.upper_cased 1) - [name_0 name_1 name_2 name_3 name_4] (|> (random.upper_cased 1) - (random.set text.hash 5) - (of ! each set.list) - (random.one (function (_ values) - (when values - (list name_0 name_1 name_2 name_3 name_4) - {.#Some [name_0 name_1 name_2 name_3 name_4]} - - _ - {.#None})))) - .let [type_0 {.#Nominal name_0 (list)} - type_1 {.#Nominal name_1 (list)} - type_2 {.#Nominal name_2 (list)} - type_3 {.#Nominal name_3 (list)} - type_4 {.#Nominal name_4 (list)} - - globals (is (List [Text [Bit .Global]]) - (list [name_4 - [false {.#Definition [type_4 []]}]])) - - scopes (list [.#scope_name (list) - .#inner_scopes 0 - .#locals [.#counter 1 - .#mappings (list [name_3 [type_3 3]])] - .#captured [.#counter 0 - .#mappings (list)]] - [.#scope_name (list) - .#inner_scopes 0 - .#locals [.#counter 2 - .#mappings (list [name_1 [type_1 1]] - [name_2 [type_2 2]])] - .#captured [.#counter 0 - .#mappings (list)]] - [.#scope_name (list) - .#inner_scopes 0 - .#locals [.#counter 1 - .#mappings (list [name_0 [type_0 0]])] - .#captured [.#counter 0 - .#mappings (list)]])] - .let [expected_lux - (is Lux - [.#info [.#target "" - .#version "" - .#mode {.#Build} - .#configuration (list)] - .#source [location.dummy 0 ""] - .#location location.dummy - .#current_module {.#Some current_module} - .#modules (list [current_module - [.#module_hash 0 - .#module_aliases (list) - .#definitions globals - .#imports (list) - .#module_state {.#Active}]]) - .#scopes scopes - .#type_context [.#ex_counter 0 - .#var_counter 0 - .#var_bindings (list)] - .#expected {.#None} - .#seed 0 - .#scope_type_vars (list) - .#extensions [] - .#eval (as (-> Type Code (Meta Any)) []) - .#host []])]] - (all _.and - (_.coverage [.Scope - .#scope_name .#inner_scopes .#locals .#captured - - /.locals] - (let [equivalence (is (Equivalence (List (List [Text Type]))) - (list.equivalence - (list.equivalence - (product.equivalence - text.equivalence - type.equivalence))))] - (|> /.locals - (/.value expected_lux) - (try#each (of equivalence = (list (list [name_3 type_3]) - (list [name_1 type_1] - [name_2 type_2])))) - (try.else false)))) - (_.coverage [/.var_type] - (and (|> (/.var_type name_0) - (/.value expected_lux) - (try#each (of type.equivalence = type_0)) - (try.else false)) - (|> (/.var_type name_1) - (/.value expected_lux) - (try#each (of type.equivalence = type_1)) - (try.else false)) - (|> (/.var_type name_2) - (/.value expected_lux) - (try#each (of type.equivalence = type_2)) - (try.else false)) - (|> (/.var_type name_3) - (/.value expected_lux) - (try#each (of type.equivalence = type_3)) - (try.else false)))) - (_.coverage [/.type] - (and (|> (/.type ["" name_0]) - (/.value expected_lux) - (try#each (of type.equivalence = type_0)) - (try.else false)) - (|> (/.type ["" name_1]) - (/.value expected_lux) - (try#each (of type.equivalence = type_1)) - (try.else false)) - (|> (/.type ["" name_2]) - (/.value expected_lux) - (try#each (of type.equivalence = type_2)) - (try.else false)) - (|> (/.type ["" name_3]) - (/.value expected_lux) - (try#each (of type.equivalence = type_3)) - (try.else false)) - (|> (/.type [current_module name_4]) - (/.value expected_lux) - (try#each (of type.equivalence = type_4)) - (try.else false)) - (|> (/.type ["" name_4]) - (/.value expected_lux) - (try#each (of type.equivalence = type_4)) - (try.else false)))) - ))) - (the label_related Test (do [! random.monad] @@ -987,9 +555,6 @@ ..error_handling ..module_related ..context_related - ..definition_related - ..search_related - ..locals_related (_.for [.Label] ..label_related) )) @@ -1007,5 +572,6 @@ /global.test /compiler.test /label.test + /binding.test /import.test ))))) diff --git a/stdlib/source/test/lux/meta/binding.lux b/stdlib/source/test/lux/meta/binding.lux new file mode 100644 index 0000000000..ec66c24d98 --- /dev/null +++ b/stdlib/source/test/lux/meta/binding.lux @@ -0,0 +1,543 @@ +... This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. +... If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/. + +(.require + [library + [lux (.except) + [abstract + [equivalence (.only Equivalence)] + [monad (.only do)]] + [control + ["[0]" try (.use "[1]#[0]" functor)]] + [data + ["[0]" product] + ["[0]" bit (.use "[1]#[0]" equivalence)] + ["[0]" text (.use "[1]#[0]" equivalence)] + [collection + ["[0]" list] + ["[0]" set]]] + [math + ["[0]" random (.only Random)] + [number + ["n" nat]]] + [meta + ["[0]" location] + ["[0]" symbol (.use "[1]#[0]" equivalence)] + ["[0]" type] + [macro + ["^" pattern] + ["[0]" template]]] + [test + ["_" property (.only Test)]]]] + [\\library + ["[0]" / (.only) + ["/[1]" //]]]) + +(the !expect + (template.macro (_ ) + [(when + true + _ false)])) + +(the module_related + Test + (do random.monad + [target (random.upper_cased 1) + version (random.upper_cased 1) + source_code (random.upper_cased 1) + expected_current_module (random.upper_cased 1) + imported_module_name (random.only (|>> (text#= expected_current_module) not) + (random.upper_cased 1)) + nominal_type (random.upper_cased 1) + expected_seed random.nat + expected random.nat + dummy (random.only (|>> (n.= expected) not) random.nat) + expected_short (random.upper_cased 1) + dummy_module (random.only (function (_ module) + (not (or (text#= expected_current_module module) + (text#= imported_module_name module)))) + (random.upper_cased 1)) + .let [imported_module [.#module_hash 0 + .#module_aliases (list) + .#definitions (list) + .#imports (list) + .#module_state {.#Active}] + expected_module [.#module_hash 0 + .#module_aliases (list) + .#definitions (list) + .#imports (list imported_module_name) + .#module_state {.#Active}] + expected_modules (list [expected_current_module + expected_module] + [imported_module_name + imported_module]) + expected_lux [.#info [.#target target + .#version version + .#mode {.#Build} + .#configuration (list)] + .#source [location.dummy 0 source_code] + .#location location.dummy + .#current_module {.#Some expected_current_module} + .#modules expected_modules + .#scopes (list) + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#Some {.#Nominal nominal_type (list)}} + .#seed expected_seed + .#scope_type_vars (list) + .#extensions [] + .#eval (as (-> Type Code (Meta Any)) []) + .#host []]]] + (all _.and + (_.coverage [/.normal] + (and (|> (/.normal ["" expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success [actual_module actual_short]} + (and (text#= expected_current_module actual_module) + (same? expected_short actual_short))))) + (|> (/.normal [dummy_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success [actual_module actual_short]} + (and (text#= dummy_module actual_module) + (same? expected_short actual_short))))))) + ))) + +(the random_location + (Random Location) + (all random.and + (random.upper_cased 1) + random.nat + random.nat)) + +(the definition_related + Test + (do [! random.monad] + [expected_current_module (random.upper_cased 1) + expected_macro_module (random.only (|>> (text#= expected_current_module) not) + (random.upper_cased 1)) + expected_short (random.upper_cased 1) + expected_type (of ! each (function (_ name) + {.#Nominal name (list)}) + (random.upper_cased 1)) + expected_value (random.either (in .the) + (in .macro)) + .let [expected_lux + (is (-> Bit (Maybe Type) + [(List [Text [Bit .Global]]) + (List [Text [Bit .Global]]) + Lux]) + (function (_ exported? def_type) + (let [current_globals (is (List [Text [Bit .Global]]) + (list [expected_short + [false {.#Alias [expected_macro_module expected_short]}]])) + macro_globals (is (List [Text [Bit .Global]]) + (when def_type + {.#Some def_type} + (list [expected_short + [exported? {.#Definition [def_type expected_value]}]]) + + {.#None} + (list)))] + [current_globals + macro_globals + [.#info [.#target "" + .#version "" + .#mode {.#Build} + .#configuration (list)] + .#source [location.dummy 0 ""] + .#location location.dummy + .#current_module {.#Some expected_current_module} + .#modules (list [expected_current_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions current_globals + .#imports (list) + .#module_state {.#Active}]] + [expected_macro_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions macro_globals + .#imports (list) + .#module_state {.#Active}]]) + .#scopes (list) + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#None} + .#seed 0 + .#scope_type_vars (list) + .#extensions [] + .#eval (as (-> Type Code (Meta Any)) []) + .#host []]])))]] + (all _.and + (_.coverage [.Global + .#Definition .#Alias .#Default + + .Alias /.globals] + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro}) + + current_globals! + (|> (/.globals expected_current_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_globals} + (same? current_globals actual_globals)))) + + macro_globals! + (|> (/.globals expected_macro_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_globals} + (same? macro_globals actual_globals))))] + (and current_globals! + macro_globals!))) + (_.coverage [.Definition /.definitions] + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro})] + (and (|> (/.definitions expected_current_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 0 (list.size actual_definitions))))) + (|> (/.definitions expected_macro_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 1 (list.size actual_definitions))))) + ))) + (_.coverage [/.exports] + (and (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro})] + (and (|> (/.exports expected_current_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 0 (list.size actual_definitions))))) + (|> (/.exports expected_macro_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 1 (list.size actual_definitions))))) + )) + (let [[current_globals macro_globals expected_lux] + (expected_lux false {.#Some .Macro})] + (and (|> (/.exports expected_current_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 0 (list.size actual_definitions))))) + (|> (/.exports expected_macro_module) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_definitions} + (n.= 0 (list.size actual_definitions))))) + )))) + ))) + +(the search_related + Test + (do [! random.monad] + [expected_exported? random.bit + expected_current_module (random.upper_cased 1) + expected_macro_module (random.only (|>> (text#= expected_current_module) not) + (random.upper_cased 1)) + expected_short (random.upper_cased 1) + expected_type (of ! each (function (_ name) + {.#Nominal name (list)}) + (random.upper_cased 1)) + expected_value (random.either (in .the) + (in .macro)) + .let [expected_lux + (is (-> Bit (Maybe Type) + [(List [Text [Bit .Global]]) + (List [Text [Bit .Global]]) + Lux]) + (function (_ exported? def_type) + (let [current_globals (is (List [Text [Bit .Global]]) + (list [expected_short + [false {.#Alias [expected_macro_module expected_short]}]])) + macro_globals (is (List [Text [Bit .Global]]) + (when def_type + {.#Some def_type} + (list [expected_short + [exported? {.#Definition [def_type expected_value]}]]) + + {.#None} + (list)))] + [current_globals + macro_globals + [.#info [.#target "" + .#version "" + .#mode {.#Build} + .#configuration (list)] + .#source [location.dummy 0 ""] + .#location location.dummy + .#current_module {.#Some expected_current_module} + .#modules (list [expected_current_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions current_globals + .#imports (list) + .#module_state {.#Active}]] + [expected_macro_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions macro_globals + .#imports (list) + .#module_state {.#Active}]]) + .#scopes (list) + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#None} + .#seed 0 + .#scope_type_vars (list) + .#extensions [] + .#eval (as (-> Type Code (Meta Any)) []) + .#host []]])))]] + (all _.and + (_.coverage [/.export] + (and (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some expected_type})] + (|> (/.export [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect {try.#Success _}))) + (let [[current_globals macro_globals expected_lux] + (expected_lux false {.#Some expected_type})] + (|> (/.export [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect {try.#Failure _}))))) + (_.coverage [/.macro + /.not_a_macro] + (let [same_module! + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro})] + (|> (/.macro [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_value} + (same? expected_value actual_value))))) + + not_macro! + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some expected_type})] + (|> (/.macro [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect {try.#Failure /.not_a_macro}))) + + not_found! + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#None})] + (|> (/.macro [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect {try.#Failure _}))) + + aliasing! + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro})] + (|> (/.macro [expected_current_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_value} + (same? expected_value actual_value)))))] + (and same_module! + not_macro! + not_found! + aliasing!))) + (_.coverage [/.de_aliased] + (let [[current_globals macro_globals expected_lux] + (expected_lux true {.#Some .Macro})] + (and (|> (/.de_aliased [expected_macro_module expected_short]) + (//.value expected_lux) + (try#each (symbol#= [expected_macro_module expected_short])) + (try.else false)) + (|> (/.de_aliased [expected_current_module expected_short]) + (//.value expected_lux) + (try#each (symbol#= [expected_macro_module expected_short])) + (try.else false))))) + (_.coverage [/.definition] + (let [[current_globals macro_globals expected_lux] + (expected_lux expected_exported? {.#Some expected_type}) + + definition! + (|> (/.definition [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success [actual_exported? {.#Definition [actual_type actual_value]}]} + (and (bit#= expected_exported? actual_exported?) + (same? expected_type actual_type) + (same? (as Any expected_value) actual_value))))) + + alias! + (|> (/.definition [expected_current_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success [.false {.#Alias [actual_module actual_short]}]} + (and (same? expected_macro_module actual_module) + (same? expected_short actual_short)))))] + (and definition! + alias!))) + (_.coverage [/.definition_type] + (let [[current_globals macro_globals expected_lux] + (expected_lux expected_exported? {.#Some expected_type}) + + definition! + (|> (/.definition_type [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_type} + (same? expected_type actual_type)))) + + alias! + (|> (/.definition_type [expected_current_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_type} + (same? expected_type actual_type))))] + (and definition! + alias!))) + (_.coverage [/.type_definition] + (let [[current_globals macro_globals expected_lux] + (expected_lux expected_exported? {.#Some .Type}) + + definition! + (|> (/.type_definition [expected_macro_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_value} + (same? (as .Type expected_value) actual_value)))) + + alias! + (|> (/.type_definition [expected_current_module expected_short]) + (//.value expected_lux) + (!expect (^.multi {try.#Success actual_value} + (same? (as .Type expected_value) actual_value))))] + (and definition! + alias!))) + ))) + +(the locals_related + Test + (do [! random.monad] + [current_module (random.upper_cased 1) + [name_0 name_1 name_2 name_3 name_4] (|> (random.upper_cased 1) + (random.set text.hash 5) + (of ! each set.list) + (random.one (function (_ values) + (when values + (list name_0 name_1 name_2 name_3 name_4) + {.#Some [name_0 name_1 name_2 name_3 name_4]} + + _ + {.#None})))) + .let [type_0 {.#Nominal name_0 (list)} + type_1 {.#Nominal name_1 (list)} + type_2 {.#Nominal name_2 (list)} + type_3 {.#Nominal name_3 (list)} + type_4 {.#Nominal name_4 (list)} + + globals (is (List [Text [Bit .Global]]) + (list [name_4 + [false {.#Definition [type_4 []]}]])) + + scopes (list [.#scope_name (list) + .#inner_scopes 0 + .#locals [.#counter 1 + .#mappings (list [name_3 [type_3 3]])] + .#captured [.#counter 0 + .#mappings (list)]] + [.#scope_name (list) + .#inner_scopes 0 + .#locals [.#counter 2 + .#mappings (list [name_1 [type_1 1]] + [name_2 [type_2 2]])] + .#captured [.#counter 0 + .#mappings (list)]] + [.#scope_name (list) + .#inner_scopes 0 + .#locals [.#counter 1 + .#mappings (list [name_0 [type_0 0]])] + .#captured [.#counter 0 + .#mappings (list)]])] + .let [expected_lux + (is Lux + [.#info [.#target "" + .#version "" + .#mode {.#Build} + .#configuration (list)] + .#source [location.dummy 0 ""] + .#location location.dummy + .#current_module {.#Some current_module} + .#modules (list [current_module + [.#module_hash 0 + .#module_aliases (list) + .#definitions globals + .#imports (list) + .#module_state {.#Active}]]) + .#scopes scopes + .#type_context [.#ex_counter 0 + .#var_counter 0 + .#var_bindings (list)] + .#expected {.#None} + .#seed 0 + .#scope_type_vars (list) + .#extensions [] + .#eval (as (-> Type Code (Meta Any)) []) + .#host []])]] + (all _.and + (_.coverage [.Scope + .#scope_name .#inner_scopes .#locals .#captured + + /.locals] + (let [equivalence (is (Equivalence (List (List [Text Type]))) + (list.equivalence + (list.equivalence + (product.equivalence + text.equivalence + type.equivalence))))] + (|> /.locals + (//.value expected_lux) + (try#each (of equivalence = (list (list [name_3 type_3]) + (list [name_1 type_1] + [name_2 type_2])))) + (try.else false)))) + (_.coverage [/.var_type] + (and (|> (/.var_type name_0) + (//.value expected_lux) + (try#each (of type.equivalence = type_0)) + (try.else false)) + (|> (/.var_type name_1) + (//.value expected_lux) + (try#each (of type.equivalence = type_1)) + (try.else false)) + (|> (/.var_type name_2) + (//.value expected_lux) + (try#each (of type.equivalence = type_2)) + (try.else false)) + (|> (/.var_type name_3) + (//.value expected_lux) + (try#each (of type.equivalence = type_3)) + (try.else false)))) + (_.coverage [/.type] + (and (|> (/.type ["" name_0]) + (//.value expected_lux) + (try#each (of type.equivalence = type_0)) + (try.else false)) + (|> (/.type ["" name_1]) + (//.value expected_lux) + (try#each (of type.equivalence = type_1)) + (try.else false)) + (|> (/.type ["" name_2]) + (//.value expected_lux) + (try#each (of type.equivalence = type_2)) + (try.else false)) + (|> (/.type ["" name_3]) + (//.value expected_lux) + (try#each (of type.equivalence = type_3)) + (try.else false)) + (|> (/.type [current_module name_4]) + (//.value expected_lux) + (try#each (of type.equivalence = type_4)) + (try.else false)) + (|> (/.type ["" name_4]) + (//.value expected_lux) + (try#each (of type.equivalence = type_4)) + (try.else false)))) + ))) + +(the .public test + Test + (<| (_.covering /._) + (all _.and + ..module_related + ..definition_related + ..search_related + ..locals_related + ))) diff --git a/stdlib/source/test/lux/meta/macro/local.lux b/stdlib/source/test/lux/meta/macro/local.lux index 01b2a214d0..f796c97d58 100644 --- a/stdlib/source/test/lux/meta/macro/local.lux +++ b/stdlib/source/test/lux/meta/macro/local.lux @@ -21,6 +21,7 @@ [number ["n" nat]]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection]] ["[0]" macro (.only) @@ -64,7 +65,7 @@ (macro.with_symbols [g!output] (do meta.monad [pop! (/.push (list [name (..constant constant)])) - [module short] (meta.normal name) + [module short] (binding.normal name) _ (if pre_remove (let [remove_macro! (is (-> .Module .Module) diff --git a/stdlib/source/test/lux/meta/type/linear.lux b/stdlib/source/test/lux/meta/type/linear.lux index 6a6a105f34..9435828647 100644 --- a/stdlib/source/test/lux/meta/type/linear.lux +++ b/stdlib/source/test/lux/meta/type/linear.lux @@ -20,6 +20,7 @@ [math ["[0]" random]] ["[0]" meta (.only) + ["[0]" binding] ["[0]" code (.only) ["<[1]>" \\projection]] [macro @@ -165,7 +166,7 @@ (syntax.macro (_ [exception .symbol to_expand .any]) (monad.do meta.monad - [[_ exception] (meta.export exception)] + [[_ exception] (binding.export exception)] (function (_ compiler) {.#Right [compiler (list (code.bit (when ((expansion.single to_expand) compiler) diff --git a/stdlib/source/test/lux/world/time.lux b/stdlib/source/test/lux/world/time.lux index 534541a80d..dde945d2cf 100644 --- a/stdlib/source/test/lux/world/time.lux +++ b/stdlib/source/test/lux/world/time.lux @@ -21,7 +21,7 @@ [data ["[0]" text (.only) ["%" \\injection] - ["<[1]>" \\projection]]] + ["?[1]" \\projection]]] [math ["[0]" random (.only Random)] [number @@ -168,12 +168,14 @@ (|> /.midnight /.millis (n.= 0))) - (_.coverage [/.projection] - (|> expected - (of /.format injection) - (.value /.projection) - (try#each (of /.equivalence = expected)) - (try.else false))) + (do random.monad + [expected ..random] + (_.coverage [/.as_text /.projection] + (|> expected + /.as_text + (?text.value /.projection) + (try#each (of /.equivalence = expected)) + (try.else false)))) ..for_ranges (_.for [/.Clock] ..for_clock) diff --git a/stdlib/source/test/lux/world/time/date.lux b/stdlib/source/test/lux/world/time/date.lux index bb007abf9f..21f648619e 100644 --- a/stdlib/source/test/lux/world/time/date.lux +++ b/stdlib/source/test/lux/world/time/date.lux @@ -20,7 +20,7 @@ [data ["[0]" text ["%" \\injection] - ["<[1]>" \\projection]]] + ["?[1]" \\projection]]] [math ["[0]" random (.only Random)] [number @@ -81,13 +81,6 @@ (|> /.epoch /.days (i.= +0))) - (do random.monad - [expected ..random] - (_.coverage [/.projection] - (|> (of /.format injection expected) - (.value /.projection) - (try#each (of /.equivalence = expected)) - (try.else false)))) (do [! random.monad] [year (of ! each (|>> (n.% 10,000) ++) random.nat) @@ -99,10 +92,18 @@ "-" (%.nat month) "-" (%.nat day))]] (_.coverage [/.invalid_month] - (when (.value /.projection input) + (when (?text.value /.projection input) {try.#Failure error} (exception.is? /.invalid_month error) {try.#Success _} false))) + (do random.monad + [expected ..random] + (_.coverage [/.as_text /.projection] + (|> expected + /.as_text + (?text.value /.projection) + (try#each (of /.equivalence = expected)) + (try.else false)))) ))) diff --git a/stdlib/source/test/lux/world/time/day.lux b/stdlib/source/test/lux/world/time/day.lux index 3825b85c2b..737568044f 100644 --- a/stdlib/source/test/lux/world/time/day.lux +++ b/stdlib/source/test/lux/world/time/day.lux @@ -22,6 +22,8 @@ [function ["[0]" predicate]]] [data + ["[0]" text + ["?[1]" \\projection]] [collection ["[0]" list] ["[0]" set]]] @@ -81,15 +83,6 @@ [/.#Thursday /.#Friday /.#Saturday] [/.#Friday /.#Saturday /.#Sunday] )) - (do random.monad - [not_a_day (random.upper_cased 1)] - (_.coverage [/.not_a_day_of_the_week] - (when (of /.format projection not_a_day) - {try.#Failure error} - (exception.is? /.not_a_day_of_the_week error) - - {try.#Success _} - false))) (_.coverage [/.number /.by_number] (|> expected /.number @@ -110,4 +103,12 @@ all) (n.= all uniques)))) + (do random.monad + [expected /.random] + (_.coverage [/.as_text /.projection] + (|> expected + /.as_text + (?text.value /.projection) + (try#each (of /.equivalence = expected)) + (try.else false)))) )))) diff --git a/stdlib/source/test/lux/world/time/duration.lux b/stdlib/source/test/lux/world/time/duration.lux index 5a6150c3b3..e7ec458827 100644 --- a/stdlib/source/test/lux/world/time/duration.lux +++ b/stdlib/source/test/lux/world/time/duration.lux @@ -16,8 +16,12 @@ ["[1]T" \\test]] ["[0]" monoid ["[1]T" \\test]]] + [control + ["[0]" try (.use "[1]#[0]" functor)]] [data - ["[0]" bit (.use "[1]#[0]" equivalence)]] + ["[0]" bit (.use "[1]#[0]" equivalence)] + ["[0]" text + ["?[1]" \\projection]]] [math ["[0]" random (.only Random)] [number @@ -108,4 +112,18 @@ [+366 /.leap_year /.day] )) ))) + (do random.monad + [expected random.duration] + (_.coverage [/.as_text /.projection] + (|> expected + /.as_text + (?text.value /.projection) + (try#each (of /.equivalence = expected)) + (try.else false)))) + (do random.monad + [expected random.duration + actual (random.only (|>> (of /.equivalence = expected) not) + random.duration)] + (_.coverage [random.duration] + (not (of /.equivalence = expected actual)))) ))) diff --git a/stdlib/source/test/lux/world/time/month.lux b/stdlib/source/test/lux/world/time/month.lux index a280052785..4de03dc275 100644 --- a/stdlib/source/test/lux/world/time/month.lux +++ b/stdlib/source/test/lux/world/time/month.lux @@ -22,6 +22,8 @@ [function ["[0]" predicate]]] [data + ["[0]" text + ["?[1]" \\projection]] [collection ["[0]" set] ["[0]" list (.use "[1]#[0]" functor mix)]]] @@ -119,12 +121,11 @@ (list#mix n.+ 0) (n.= expected)))) (do random.monad - [not_a_month (random.upper_cased 1)] - (_.coverage [/.not_a_month_of_the_year] - (when (of /.format projection not_a_month) - {try.#Failure error} - (exception.is? /.not_a_month_of_the_year error) - - {try.#Success _} - false))) + [expected random.month] + (_.coverage [/.as_text /.projection] + (|> expected + /.as_text + (?text.value /.projection) + (try#each (of /.equivalence = expected)) + (try.else false)))) )))))) diff --git a/to_do.md b/to_do.md index 59366419fc..d6ba00ba38 100644 --- a/to_do.md +++ b/to_do.md @@ -37,13 +37,13 @@ 0. Go from having I32 variant tags to I8 tags. 0. Implement extensible pattern-matching in the compiler, guided by the experiment in `control/pattern`. 0. Better syntax for `.when#`. -0. Get rid of the `left` and `right` macros in the prelude. Also, get rid of their highlighting in `lux-mode`. 0. Dissolve `math/random` into the rest of the standard library. 0. Dissolve `injection/.../text` into the rest of the standard library. ## Done -0. Make type-normalization no longer confuse local type parameters with globally-defined types/macros. +0. Re-name the `left` and `right` macros in the prelude. Also, get rid of their highlighting in `lux-mode`. +0. [(Commit)](https://github.com/LuxLang/lux/commit/6de33f8b2c7b3804be4bd5ec04fb3c4b0a3efe79) Make type-normalization no longer confuse local type parameters with globally-defined types/macros. * Remove instances of `(.except left right)`. 0. [(Commit)](https://github.com/LuxLang/lux/commit/c7daf84dfd365df8da5b381dfb1d3fca9afd62a7) Favor partial calls over successive calls when compiling function application. 0. [(Commit)](https://github.com/LuxLang/lux/commit/b7fb27e49cba22cdbad5ffc034b32963b35c05f4) Re-name `Codec` to `Embedding`. Alternatively, re-name to `Format`.