diff options
Diffstat (limited to 'stdlib/source/library')
138 files changed, 1392 insertions, 1263 deletions
diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux index c342863e7..e9b0278e5 100644 --- a/stdlib/source/library/lux.lux +++ b/stdlib/source/library/lux.lux @@ -735,7 +735,7 @@ #1) ## Base functions & macros -("lux def" return +("lux def" in_meta ("lux type check" (#UnivQ #End (#Function (#Parameter 1) @@ -767,8 +767,8 @@ ("lux macro" ([_ tokens] ({(#Item lhs (#Item rhs (#Item body #End))) - (return (#Item (form$ (#Item (record$ (#Item [lhs body] #End)) (#Item rhs #End))) - #End)) + (in_meta (#Item (form$ (#Item (record$ (#Item [lhs body] #End)) (#Item rhs #End))) + #End)) _ (failure "Wrong syntax for let''")} @@ -780,32 +780,32 @@ ("lux macro" ([_ tokens] ({(#Item [_ (#Tuple (#Item arg args'))] (#Item body #End)) - (return (#Item (_ann (#Form (#Item (_ann (#Tuple (#Item (_ann (#Identifier ["" ""])) - (#Item arg #End)))) - (#Item ({#End - body + (in_meta (#Item (_ann (#Form (#Item (_ann (#Tuple (#Item (_ann (#Identifier ["" ""])) + (#Item arg #End)))) + (#Item ({#End + body - _ - (_ann (#Form (#Item (_ann (#Identifier ["library/lux" "function''"])) - (#Item (_ann (#Tuple args')) - (#Item body #End)))))} - args') - #End)))) - #End)) + _ + (_ann (#Form (#Item (_ann (#Identifier ["library/lux" "function''"])) + (#Item (_ann (#Tuple args')) + (#Item body #End)))))} + args') + #End)))) + #End)) (#Item [_ (#Identifier ["" self])] (#Item [_ (#Tuple (#Item arg args'))] (#Item body #End))) - (return (#Item (_ann (#Form (#Item (_ann (#Tuple (#Item (_ann (#Identifier ["" self])) - (#Item arg #End)))) - (#Item ({#End - body + (in_meta (#Item (_ann (#Form (#Item (_ann (#Tuple (#Item (_ann (#Identifier ["" self])) + (#Item arg #End)))) + (#Item ({#End + body - _ - (_ann (#Form (#Item (_ann (#Identifier ["library/lux" "function''"])) - (#Item (_ann (#Tuple args')) - (#Item body #End)))))} - args') - #End)))) - #End)) + _ + (_ann (#Form (#Item (_ann (#Identifier ["library/lux" "function''"])) + (#Item (_ann (#Tuple args')) + (#Item body #End)))))} + args') + #End)))) + #End)) _ (failure "Wrong syntax for function''")} @@ -838,12 +838,6 @@ (record$ #End) #0) -("lux def" doc_meta - ("lux type check" (#Function Text (#Product Code Code)) - (function'' [doc] [(tag$ ["library/lux" "doc"]) (text$ doc)])) - (record$ #End) - #0) - ("lux def" as_def ("lux type check" (#Function Code (#Function Code (#Function Code (#Function Bit Code)))) (function'' [name value annotations exported?] @@ -883,37 +877,37 @@ ({(#Item [[_ (#Tag ["" "export"])] (#Item [[_ (#Form (#Item [name args]))] (#Item [meta (#Item [type (#Item [body #End])])])])]) - (return (#Item [(as_def name (as_checked type (as_function name args body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - #1) - #End])) + (in_meta (#Item [(as_def name (as_checked type (as_function name args body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + #1) + #End])) (#Item [[_ (#Tag ["" "export"])] (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])]) - (return (#Item [(as_def name (as_checked type body) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - #1) - #End])) + (in_meta (#Item [(as_def name (as_checked type body) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + #1) + #End])) (#Item [[_ (#Form (#Item [name args]))] (#Item [meta (#Item [type (#Item [body #End])])])]) - (return (#Item [(as_def name (as_checked type (as_function name args body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - #0) - #End])) + (in_meta (#Item [(as_def name (as_checked type (as_function name args body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + #0) + #End])) (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])]) - (return (#Item [(as_def name (as_checked type body) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - #0) - #End])) + (in_meta (#Item [(as_def name (as_checked type body) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + #0) + #End])) _ (failure "Wrong syntax for def''")} @@ -925,28 +919,28 @@ ("lux macro" (function'' [tokens] ({(#Item [_ (#Form (#Item name args))] (#Item body #End)) - (return (#Item (as_def name (as_macro (as_function name args body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item (tag$ ["library/lux" "End"]) - #End))) - #0) - #End)) + (in_meta (#Item (as_def name (as_macro (as_function name args body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item (tag$ ["library/lux" "End"]) + #End))) + #0) + #End)) (#Item [_ (#Tag ["" "export"])] (#Item [_ (#Form (#Item name args))] (#Item body #End))) - (return (#Item (as_def name (as_macro (as_function name args body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item (tag$ ["library/lux" "End"]) - #End))) - #1) - #End)) + (in_meta (#Item (as_def name (as_macro (as_function name args body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item (tag$ ["library/lux" "End"]) + #End))) + #1) + #End)) (#Item [_ (#Tag ["" "export"])] (#Item [_ (#Form (#Item name args))] (#Item meta_data (#Item body #End)))) - (return (#Item (as_def name (as_macro (as_function name args body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta_data - #End))) - #1) - #End)) + (in_meta (#Item (as_def name (as_macro (as_function name args body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta_data + #End))) + #1) + #End)) _ (failure "Wrong syntax for macro:'")} @@ -962,18 +956,18 @@ ("lux text concat" "## Great for commenting-out code, while retaining syntax high-lighting and formatting in your text editor." __paragraph) "(comment +1 +2 +3 +4)")))] #End) - (return #End)) + (in_meta #End)) (macro:' ($' tokens) ({(#Item x #End) - (return tokens) + (in_meta tokens) (#Item x (#Item y xs)) - (return (#Item (form$ (#Item (identifier$ ["library/lux" "$'"]) - (#Item (form$ (#Item (tag$ ["library/lux" "Apply"]) - (#Item y (#Item x #End)))) - xs))) - #End)) + (in_meta (#Item (form$ (#Item (identifier$ ["library/lux" "$'"]) + (#Item (form$ (#Item (tag$ ["library/lux" "Apply"]) + (#Item y (#Item x #End)))) + xs))) + #End)) _ (failure "Wrong syntax for $'")} @@ -1058,7 +1052,7 @@ syntax)) (def:'' (n/* param subject) - (#.Item (doc_meta "Nat(ural) multiplication.") #.End) + #.End (#Function Nat (#Function Nat Nat)) ("lux type as" Nat ("lux i64 *" @@ -1160,18 +1154,18 @@ #End)))))) body names) - (return (#Item ({[#1 _] - body' - - [_ #End] - body' - - [#0 _] - (with_replacements (#Item [self_name (type_parameter (n/* 2 ("lux i64 -" 1 (list\size names))))] - #End) - body')} - [(text\= "" self_name) names]) - #End))))) + (in_meta (#Item ({[#1 _] + body' + + [_ #End] + body' + + [#0 _] + (with_replacements (#Item [self_name (type_parameter (n/* 2 ("lux i64 -" 1 (list\size names))))] + #End) + body')} + [(text\= "" self_name) names]) + #End))))) _ (failure "Wrong syntax for All")} @@ -1205,18 +1199,18 @@ #End)))))) body names) - (return (#Item ({[#1 _] - body' - - [_ #End] - body' - - [#0 _] - (with_replacements (#Item [self_name (type_parameter (n/* 2 ("lux i64 -" 1 (list\size names))))] - #End) - body')} - [(text\= "" self_name) names]) - #End))))) + (in_meta (#Item ({[#1 _] + body' + + [_ #End] + body' + + [#0 _] + (with_replacements (#Item [self_name (type_parameter (n/* 2 ("lux i64 -" 1 (list\size names))))] + #End) + body')} + [(text\= "" self_name) names]) + #End))))) _ (failure "Wrong syntax for Ex")} @@ -1239,11 +1233,11 @@ "## This is the type of a function that takes 2 Ints and returns an Int.")))] #End) ({(#Item output inputs) - (return (#Item (list\fold ("lux type check" (#Function Code (#Function Code Code)) - (function'' [i o] (form$ (#Item (tag$ ["library/lux" "Function"]) (#Item i (#Item o #End)))))) - output - inputs) - #End)) + (in_meta (#Item (list\fold ("lux type check" (#Function Code (#Function Code Code)) + (function'' [i o] (form$ (#Item (tag$ ["library/lux" "Function"]) (#Item i (#Item o #End)))))) + output + inputs) + #End)) _ (failure "Wrong syntax for ->")} @@ -1255,13 +1249,13 @@ ("lux text concat" "## List-construction macro." __paragraph) "(list +1 +2 +3)"))] #End) - (return (#Item (list\fold (function'' [head tail] - (form$ (#Item (tag$ ["library/lux" "Item"]) - (#Item (tuple$ (#Item [head (#Item [tail #End])])) - #End)))) - (tag$ ["library/lux" "End"]) - (list\reverse xs)) - #End))) + (in_meta (#Item (list\fold (function'' [head tail] + (form$ (#Item (tag$ ["library/lux" "Item"]) + (#Item (tuple$ (#Item [head (#Item [tail #End])])) + #End)))) + (tag$ ["library/lux" "End"]) + (list\reverse xs)) + #End))) (macro:' #export (list& xs) (#Item [(tag$ ["library/lux" "doc"]) @@ -1272,11 +1266,11 @@ "(list& +1 +2 +3 (list +4 +5 +6))")))] #End) ({(#Item last init) - (return (list (list\fold (function'' [head tail] - (form$ (list (tag$ ["library/lux" "Item"]) - (tuple$ (list head tail))))) - last - init))) + (in_meta (list (list\fold (function'' [head tail] + (form$ (list (tag$ ["library/lux" "Item"]) + (tuple$ (list head tail))))) + last + init))) _ (failure "Wrong syntax for list&")} @@ -1293,12 +1287,12 @@ "(&)"))))] #End) ({#End - (return (list (identifier$ ["library/lux" "Any"]))) + (in_meta (list (identifier$ ["library/lux" "Any"]))) (#Item last prevs) - (return (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Product"]) left right))) - last - prevs)))} + (in_meta (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Product"]) left right))) + last + prevs)))} (list\reverse tokens))) (macro:' #export (Variant tokens) @@ -1312,12 +1306,12 @@ "(Variant)"))))] #End) ({#End - (return (list (identifier$ ["library/lux" "Nothing"]))) + (in_meta (list (identifier$ ["library/lux" "Nothing"]))) (#Item last prevs) - (return (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Sum"]) left right))) - last - prevs)))} + (in_meta (list (list\fold (function'' [left right] (form$ (list (tag$ ["library/lux" "Sum"]) left right))) + last + prevs)))} (list\reverse tokens))) (macro:' (function' tokens) @@ -1332,14 +1326,14 @@ (failure "function' requires a non-empty arguments tuple.") (#Item [harg targs]) - (return (list (form$ (list (tuple$ (list (local_identifier$ name) - harg)) - (list\fold (function'' [arg body'] - (form$ (list (tuple$ (list (local_identifier$ "") - arg)) - body'))) - body - (list\reverse targs))))))} + (in_meta (list (form$ (list (tuple$ (list (local_identifier$ name) + harg)) + (list\fold (function'' [arg body'] + (form$ (list (tuple$ (list (local_identifier$ "") + arg)) + body'))) + body + (list\reverse targs))))))} args) _ @@ -1350,53 +1344,53 @@ ({(#Item [[_ (#Tag ["" "export"])] (#Item [[_ (#Form (#Item [name args]))] (#Item [meta (#Item [type (#Item [body #End])])])])]) - (return (list (form$ (list (text$ "lux def") - name - (form$ (list (text$ "lux type check") - type - (form$ (list (identifier$ ["library/lux" "function'"]) - name - (tuple$ args) - body)))) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - (bit$ #1))))) + (in_meta (list (form$ (list (text$ "lux def") + name + (form$ (list (text$ "lux type check") + type + (form$ (list (identifier$ ["library/lux" "function'"]) + name + (tuple$ args) + body)))) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + (bit$ #1))))) (#Item [[_ (#Tag ["" "export"])] (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])])]) - (return (list (form$ (list (text$ "lux def") - name - (form$ (list (text$ "lux type check") - type - body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - (bit$ #1))))) + (in_meta (list (form$ (list (text$ "lux def") + name + (form$ (list (text$ "lux type check") + type + body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + (bit$ #1))))) (#Item [[_ (#Form (#Item [name args]))] (#Item [meta (#Item [type (#Item [body #End])])])]) - (return (list (form$ (list (text$ "lux def") - name - (form$ (list (text$ "lux type check") - type - (form$ (list (identifier$ ["library/lux" "function'"]) - name - (tuple$ args) - body)))) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - (bit$ #0))))) + (in_meta (list (form$ (list (text$ "lux def") + name + (form$ (list (text$ "lux type check") + type + (form$ (list (identifier$ ["library/lux" "function'"]) + name + (tuple$ args) + body)))) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + (bit$ #0))))) (#Item [name (#Item [meta (#Item [type (#Item [body #End])])])]) - (return (list (form$ (list (text$ "lux def") - name - (form$ (list (text$ "lux type check") type body)) - (form$ (#Item (identifier$ ["library/lux" "record$"]) - (#Item meta - #End))) - (bit$ #0))))) + (in_meta (list (form$ (list (text$ "lux def") + name + (form$ (list (text$ "lux type check") type body)) + (form$ (#Item (identifier$ ["library/lux" "record$"]) + (#Item meta + #End))) + (bit$ #0))))) _ (failure "Wrong syntax for def:'''")} @@ -1424,14 +1418,14 @@ (macro:' (let' tokens) ({(#Item [[_ (#Tuple bindings)] (#Item [body #End])]) - (return (list (list\fold ("lux type check" (-> (Tuple Code Code) Code - Code) - (function' [binding body] - ({[label value] - (form$ (list (record$ (list [label body])) value))} - binding))) - body - (list\reverse (pairs bindings))))) + (in_meta (list (list\fold ("lux type check" (-> (Tuple Code Code) Code + Code) + (function' [binding body] + ({[label value] + (form$ (list (record$ (list [label body])) value))} + binding))) + body + (list\reverse (pairs bindings))))) _ (failure "Wrong syntax for let'")} @@ -1450,7 +1444,7 @@ (p x))} xs)) -(def:''' (wrap_meta content) +(def:''' (with_location content) #End (-> Code Code) (tuple$ (list (tuple$ (list (text$ "") (nat$ 0) (nat$ 0))) @@ -1505,7 +1499,7 @@ #End) ({(#Item op tokens') ({(#Item first nexts) - (return (list (list\fold (function\flip (right_associativity op)) first nexts))) + (in_meta (list (list\fold (function\flip (right_associativity op)) first nexts))) _ (failure "Wrong syntax for _$")} @@ -1527,7 +1521,7 @@ #End) ({(#Item op tokens') ({(#Item last prevs) - (return (list (list\fold (right_associativity op) last prevs))) + (in_meta (list (list\fold (right_associativity op) last prevs))) _ (failure "Wrong syntax for $_")} @@ -1590,8 +1584,16 @@ body' (list\fold ("lux type check" (-> (Tuple Code Code) Code Code) (function' [binding body'] (let' [[var value] binding] - ({[_ (#Tag "" "let")] - (form$ (list (identifier$ ["library/lux" "let'"]) value body')) + ({[_ (#Identifier [module short])] + ({"" + (form$ (list g!bind + (form$ (list (tuple$ (list (local_identifier$ "") var)) body')) + value)) + + _ + (form$ (list var value body'))} + module) + _ (form$ (list g!bind @@ -1600,9 +1602,9 @@ var)))) body (list\reverse (pairs bindings)))] - (return (list (form$ (list (record$ (list [(record$ (list [(tag$ ["library/lux" "in"]) g!in] [(tag$ ["library/lux" "bind"]) g!bind])) - body'])) - monad))))) + (in_meta (list (form$ (list (record$ (list [(record$ (list [(tag$ ["library/lux" "in"]) g!in] [(tag$ ["library/lux" "bind"]) g!bind])) + body'])) + monad))))) _ (failure "Wrong syntax for do")} @@ -1655,9 +1657,9 @@ "(if #1 ''Oh, yeah!'' ''Aw hell naw!'')" __paragraph "=> ''Oh, yeah!''"))]) ({(#Item test (#Item then (#Item else #End))) - (return (list (form$ (list (record$ (list [(bit$ #1) then] - [(bit$ #0) else])) - test)))) + (in_meta (list (form$ (list (record$ (list [(bit$ #1) then] + [(bit$ #0) else])) + test)))) _ (failure "Wrong syntax for if")} @@ -1772,7 +1774,7 @@ (-> Bit (-> Code ($' Meta Code)) ($' List Code) ($' Meta Code)) ({#1 ({#End - (return (tag$ ["library/lux" "End"])) + (in_meta (tag$ ["library/lux" "End"])) (#Item lastI inits) (do meta_monad @@ -1810,31 +1812,31 @@ (def:''' (untemplated_text value) #End (-> Text Code) - (wrap_meta (form$ (list (tag$ ["library/lux" "Text"]) (text$ value))))) + (with_location (form$ (list (tag$ ["library/lux" "Text"]) (text$ value))))) (def:''' (untemplate replace? subst token) #End (-> Bit Text Code ($' Meta Code)) ({[_ [_ (#Bit value)]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Bit"]) (bit$ value))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Bit"]) (bit$ value))))) [_ [_ (#Nat value)]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Nat"]) (nat$ value))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Nat"]) (nat$ value))))) [_ [_ (#Int value)]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Int"]) (int$ value))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Int"]) (int$ value))))) [_ [_ (#Rev value)]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Rev"]) (rev$ value))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Rev"]) (rev$ value))))) [_ [_ (#Frac value)]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Frac"]) (frac$ value))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Frac"]) (frac$ value))))) [_ [_ (#Text value)]] - (return (untemplated_text value)) + (in_meta (untemplated_text value)) [#0 [_ (#Tag [module name])]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Tag"]) (tuple$ (list (text$ module) (text$ name))))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Tag"]) (tuple$ (list (text$ module) (text$ name))))))) [#1 [_ (#Tag [module name])]] (let' [module' ({"" @@ -1843,7 +1845,7 @@ _ module} module)] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Tag"]) (tuple$ (list (text$ module') (text$ name)))))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Tag"]) (tuple$ (list (text$ module') (text$ name)))))))) [#1 [_ (#Identifier [module name])]] (do meta_monad @@ -1855,24 +1857,24 @@ _ (in [module name])} module) - #let [[module name] real_name]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Identifier"]) (tuple$ (list (text$ module) (text$ name)))))))) + .let' [[module name] real_name]] + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Identifier"]) (tuple$ (list (text$ module) (text$ name)))))))) [#0 [_ (#Identifier [module name])]] - (return (wrap_meta (form$ (list (tag$ ["library/lux" "Identifier"]) (tuple$ (list (text$ module) (text$ name))))))) + (in_meta (with_location (form$ (list (tag$ ["library/lux" "Identifier"]) (tuple$ (list (text$ module) (text$ name))))))) [#1 [_ (#Form (#Item [[_ (#Identifier ["" "~"])] (#Item [unquoted #End])]))]] - (return (form$ (list (text$ "lux type check") - (identifier$ ["library/lux" "Code"]) - unquoted))) + (in_meta (form$ (list (text$ "lux type check") + (identifier$ ["library/lux" "Code"]) + unquoted))) [#1 [_ (#Form (#Item [[_ (#Identifier ["" "~!"])] (#Item [dependent #End])]))]] (do meta_monad [independent (untemplate replace? subst dependent)] - (in (wrap_meta (form$ (list (tag$ ["library/lux" "Form"]) - (untemplated_list (list (untemplated_text "lux in-module") - (untemplated_text subst) - independent))))))) + (in (with_location (form$ (list (tag$ ["library/lux" "Form"]) + (untemplated_list (list (untemplated_text "lux in-module") + (untemplated_text subst) + independent))))))) [#1 [_ (#Form (#Item [[_ (#Identifier ["" "~'"])] (#Item [keep_quoted #End])]))]] (untemplate #0 subst keep_quoted) @@ -1880,13 +1882,13 @@ [_ [meta (#Form elems)]] (do meta_monad [output (spliced replace? (untemplate replace? subst) elems) - #let [[_ output'] (wrap_meta (form$ (list (tag$ ["library/lux" "Form"]) output)))]] + .let' [[_ output'] (with_location (form$ (list (tag$ ["library/lux" "Form"]) output)))]] (in [meta output'])) [_ [meta (#Tuple elems)]] (do meta_monad [output (spliced replace? (untemplate replace? subst) elems) - #let [[_ output'] (wrap_meta (form$ (list (tag$ ["library/lux" "Tuple"]) output)))]] + .let' [[_ output'] (with_location (form$ (list (tag$ ["library/lux" "Tuple"]) output)))]] (in [meta output'])) [_ [_ (#Record fields)]] @@ -1900,7 +1902,7 @@ =v (untemplate replace? subst v)] (in (tuple$ (list =k =v))))))) fields)] - (in (wrap_meta (form$ (list (tag$ ["library/lux" "Record"]) (untemplated_list =fields))))))} + (in (with_location (form$ (list (tag$ ["library/lux" "Record"]) (untemplated_list =fields))))))} [replace? token])) (macro:' #export (primitive tokens) @@ -1910,10 +1912,10 @@ "(primitive ''java.lang.Object'')" __paragraph "(primitive ''java.util.List'' [(primitive ''java.lang.Long'')])"))]) ({(#Item [_ (#Text class_name)] #End) - (return (list (form$ (list (tag$ ["library/lux" "Primitive"]) (text$ class_name) (tag$ ["library/lux" "End"]))))) + (in_meta (list (form$ (list (tag$ ["library/lux" "Primitive"]) (text$ class_name) (tag$ ["library/lux" "End"]))))) (#Item [_ (#Text class_name)] (#Item [_ (#Tuple params)] #End)) - (return (list (form$ (list (tag$ ["library/lux" "Primitive"]) (text$ class_name) (untemplated_list params))))) + (in_meta (list (form$ (list (tag$ ["library/lux" "Primitive"]) (text$ class_name) (untemplated_list params))))) _ (failure "Wrong syntax for primitive")} @@ -1988,19 +1990,19 @@ "## =>" __paragraph "(fold text\compose '''' (interpose '' '' (list\map int\encode elems)))"))]) ({(#Item [init apps]) - (return (list (list\fold ("lux type check" (-> Code Code Code) - (function' [app acc] - ({[_ (#Tuple parts)] - (tuple$ (list\compose parts (list acc))) + (in_meta (list (list\fold ("lux type check" (-> Code Code Code) + (function' [app acc] + ({[_ (#Tuple parts)] + (tuple$ (list\compose parts (list acc))) - [_ (#Form parts)] - (form$ (list\compose parts (list acc))) + [_ (#Form parts)] + (form$ (list\compose parts (list acc))) - _ - (` ((~ app) (~ acc)))} - app))) - init - apps))) + _ + (` ((~ app) (~ acc)))} + app))) + init + apps))) _ (failure "Wrong syntax for |>")} @@ -2014,19 +2016,19 @@ "## =>" __paragraph "(fold text\compose '''' (interpose '' '' (list\map int\encode elems)))"))]) ({(#Item [init apps]) - (return (list (list\fold ("lux type check" (-> Code Code Code) - (function' [app acc] - ({[_ (#Tuple parts)] - (tuple$ (list\compose parts (list acc))) + (in_meta (list (list\fold ("lux type check" (-> Code Code Code) + (function' [app acc] + ({[_ (#Tuple parts)] + (tuple$ (list\compose parts (list acc))) - [_ (#Form parts)] - (form$ (list\compose parts (list acc))) + [_ (#Form parts)] + (form$ (list\compose parts (list acc))) - _ - (` ((~ app) (~ acc)))} - app))) - init - apps))) + _ + (` ((~ app) (~ acc)))} + app))) + init + apps))) _ (failure "Wrong syntax for <|")} @@ -2172,7 +2174,7 @@ (|> data' (list\map (compose apply (replacement_environment bindings'))) list\join - return) + in_meta) (failure "Irregular arguments tuples for template."))) _ @@ -2335,7 +2337,7 @@ (in [module_name name])) _ - (return name)} + (in_meta name)} name)) (def:''' (macro full_name) @@ -2388,11 +2390,11 @@ (("lux type as" Macro' macro) args) #None - (return (list token))} + (in_meta (list token))} ?macro)) _ - (return (list token))} + (in_meta (list token))} token)) (def:''' (expansion token) @@ -2409,11 +2411,11 @@ (in (list\join recursive_expansion))) #None - (return (list token))} + (in_meta (list token))} ?macro)) _ - (return (list token))} + (in_meta (list token))} token)) (def:''' (full_expansion syntax) @@ -2453,7 +2455,7 @@ (do meta_monad [val' (full_expansion val)] ({(#Item val'' #End) - (return [key val'']) + (in_meta [key val'']) _ (failure "The value-part of a KV-pair in a record must macro-expand to a single Code.")} @@ -2462,7 +2464,7 @@ (in (list (record$ pairs')))) _ - (return (list syntax))} + (in_meta (list syntax))} syntax)) (def:''' (normal_type type) @@ -2496,7 +2498,7 @@ (macro:' #export (type tokens) (list [(tag$ ["library/lux" "doc"]) (text$ ($_ "lux text concat" - "## Takes a type expression and returns it's representation as data-structure." __paragraph + "## Takes a type expression and returns its representation as data-structure." __paragraph "(type (All [a] (Maybe (List a))))"))]) ({(#Item type #End) (do meta_monad @@ -2518,7 +2520,7 @@ "## The type-annotation macro." __paragraph "(: (List Int) (list +1 +2 +3))"))]) ({(#Item type (#Item value #End)) - (return (list (` ("lux type check" (type (~ type)) (~ value))))) + (in_meta (list (` ("lux type check" (type (~ type)) (~ value))))) _ (failure "Wrong syntax for :")} @@ -2530,7 +2532,7 @@ "## The type-coercion macro." __paragraph "(:as Dinosaur (list +1 +2 +3))"))]) ({(#Item type (#Item value #End)) - (return (list (` ("lux type as" (type (~ type)) (~ value))))) + (in_meta (list (` ("lux type as" (type (~ type)) (~ value))))) _ (failure "Wrong syntax for :as")} @@ -2561,24 +2563,24 @@ (: (-> [Code Code] (Meta [Text Code])) (function' [pair] ({[[_ (#Tag "" member_name)] member_type] - (return [member_name member_type]) + (in_meta [member_name member_type]) _ (failure "Wrong syntax for variant case.")} pair))) pairs)] - (return [(` (Tuple (~+ (list\map second members)))) - (#Some (list\map first members))])) + (in_meta [(` (Tuple (~+ (list\map second members)))) + (#Some (list\map first members))])) (#Item type #End) ({[_ (#Tag "" member_name)] - (return [(` .Any) (#Some (list member_name))]) + (in_meta [(` .Any) (#Some (list member_name))]) [_ (#Form (#Item [_ (#Tag "" member_name)] member_types))] - (return [(` (Tuple (~+ member_types))) (#Some (list member_name))]) + (in_meta [(` (Tuple (~+ member_types))) (#Some (list member_name))]) _ - (return [type #None])} + (in_meta [type #None])} type) (#Item case cases) @@ -2587,20 +2589,20 @@ (: (-> Code (Meta [Text Code])) (function' [case] ({[_ (#Tag "" member_name)] - (return [member_name (` .Any)]) + (in_meta [member_name (` .Any)]) [_ (#Form (#Item [_ (#Tag "" member_name)] (#Item member_type #End)))] - (return [member_name member_type]) + (in_meta [member_name member_type]) [_ (#Form (#Item [_ (#Tag "" member_name)] member_types))] - (return [member_name (` (Tuple (~+ member_types)))]) + (in_meta [member_name (` (Tuple (~+ member_types)))]) _ (failure "Wrong syntax for variant case.")} case))) (list& case cases))] - (return [(` (..Variant (~+ (list\map second members)))) - (#Some (list\map first members))])) + (in_meta [(` (..Variant (~+ (list\map second members)))) + (#Some (list\map first members))])) _ (failure "Improper type-definition syntax")} @@ -2632,7 +2634,7 @@ (let' [body' (|> body nested_quantification (with_replacements (list [name (` (#.Apply (~ (type_parameter 1)) (~ (type_parameter 0))))])))] - (return (list (` (#.Apply .Nothing (#.UnivQ #.End (~ body'))))))) + (in_meta (list (` (#.Apply .Nothing (#.UnivQ #.End (~ body'))))))) _ (failure "Wrong syntax for Rec")} @@ -2649,11 +2651,11 @@ "''YOLO'')"))]) ({(#Item value actions) (let' [dummy (local_identifier$ "")] - (return (list (list\fold ("lux type check" (-> Code Code Code) - (function' [pre post] (` ({(~ dummy) (~ post)} - (~ pre))))) - value - actions)))) + (in_meta (list (list\fold ("lux type check" (-> Code Code Code) + (function' [pre post] (` ({(~ dummy) (~ post)} + (~ pre))))) + value + actions)))) _ (failure "Wrong syntax for exec")} @@ -2695,11 +2697,11 @@ #None body'} ?type)] - (return (list (` ("lux def" (~ name) - (~ body'') - [(~ location_code) - (#.Record #.End)] - (~ (bit$ export?))))))) + (in_meta (list (` ("lux def" (~ name) + (~ body'') + [(~ location_code) + (#.Record #.End)] + (~ (bit$ export?))))))) #None (failure "Wrong syntax for def'")} @@ -2864,7 +2866,7 @@ (let' [pairs (|> patterns (list\map (function' [pattern] (list pattern body))) (list\join))] - (return (list\compose pairs branches)))) + (in_meta (list\compose pairs branches)))) _ (failure "Wrong syntax for ^or"))) @@ -2897,7 +2899,7 @@ (` (case (~ r) (~ l) (~ body'))))))) body) list - return) + in_meta) (failure "let requires an even number of parts")) _ @@ -2929,8 +2931,8 @@ (` ([(~ g!name) (~ arg)] (~ body'))) (` ([(~ g!name) (~ g!blank)] (.case (~ g!blank) (~ arg) (~ body'))))))))] - (return (list (nest (..local_identifier$ g!name) head - (list\fold (nest g!blank) body (list\reverse tail)))))) + (in_meta (list (nest (..local_identifier$ g!name) head + (list\fold (nest g!blank) body (list\reverse tail)))))) #None (failure "Wrong syntax for function"))) @@ -3075,11 +3077,11 @@ #None body) =meta (definition_annotations meta)] - (return (list (` ("lux def" (~ name) - (~ body) - [(~ location_code) - (#.Record (~ (with_func_args args =meta)))] - (~ (bit$ exported?))))))) + (in_meta (list (` ("lux def" (~ name) + (~ body) + [(~ location_code) + (#.Record (~ (with_func_args args =meta)))] + (~ (bit$ exported?))))))) #None (failure "Wrong syntax for def:")))) @@ -3110,7 +3112,7 @@ " (case tokens" ..\n " (^template [<tag>]" ..\n " [(^ (list [_ (<tag> [prefix name])]))" ..\n - " (return (list (` [(~ (text$ prefix)) (~ (text$ name))])))])" ..\n + " (in (list (` [(~ (text$ prefix)) (~ (text$ name))])))])" ..\n " ([#Identifier] [#Tag])" __paragraph " _" ..\n @@ -3143,11 +3145,11 @@ (` ("lux macro" (function ((~ name) (~+ args)) (~ body))))) =meta (definition_annotations meta)] - (return (list (` ("lux def" (~ name) - (~ body) - [(~ location_code) - (#Record (~ =meta))] - (~ (bit$ exported?))))))) + (in_meta (list (` ("lux def" (~ name) + (~ body) + [(~ location_code) + (#Record (~ =meta))] + (~ (bit$ exported?))))))) #None (failure "Wrong syntax for macro:")))) @@ -3199,13 +3201,13 @@ _ (failure "Signatures require typed members!")))) (list\join sigs'))) - #let [[_module _name] name+ + .let [[_module _name] name+ def_name (identifier$ name) sig_type (record$ (list\map (: (-> [Text Code] [Code Code]) - (function (_ [m_name m_type]) - [(local_tag$ m_name) m_type])) + (function (_ [module_name m_type]) + [(local_tag$ module_name) m_type])) members)) - sig_meta (merged_definition_annotations (` {#.sig? #1}) + sig_meta (merged_definition_annotations (` {#.interface? #1}) meta) usage (case args #End @@ -3213,7 +3215,7 @@ _ (` ((~ def_name) (~+ args))))]] - (return (list (` (..type: (~+ (export exported?)) (~ usage) (~ sig_meta) (~ sig_type)))))) + (in_meta (list (` (..type: (~+ (export exported?)) (~ usage) (~ sig_meta) (~ sig_type)))))) #None (failure "Wrong syntax for interface:")))) @@ -3233,15 +3235,15 @@ (#Some y) (#Some y)))) -(template [<name> <form> <message> <doc_msg>] +(template [<name> <form> <message> <documentation>] [(macro: #export (<name> tokens) - {#.doc <doc_msg>} + {#.doc <documentation>} (case (list\reverse tokens) (^ (list& last init)) - (return (list (list\fold (: (-> Code Code Code) - (function (_ pre post) (` <form>))) - last - init))) + (in_meta (list (list\fold (: (-> Code Code Code) + (function (_ pre post) (` <form>))) + last + init))) _ (failure <message>)))] @@ -3386,9 +3388,9 @@ _ (list type)))] - [flat_variant #Sum] - [flat_tuple #Product] - [flat_lambda #Function] + [flat_variant #Sum] + [flat_tuple #Product] + [flat_lambda #Function] ) (def: (flat_application type) @@ -3451,10 +3453,10 @@ (-> Name (Meta [Nat (List Name) Bit Type])) (do meta_monad [=module (..module module) - #let [{#module_hash _ #module_aliases _ #definitions bindings #imports _ #tags tags_table #types types #module_annotations _ #module_state _} =module]] + .let [{#module_hash _ #module_aliases _ #definitions bindings #imports _ #tags tags_table #types types #module_annotations _ #module_state _} =module]] (case (get name tags_table) (#Some output) - (return output) + (in_meta output) _ (failure (text\compose "Unknown tag: " (name\encode [module name])))))) @@ -3474,21 +3476,21 @@ (#Named [module name] unnamed) (do meta_monad [=module (..module module) - #let [{#module_hash _ #module_aliases _ #definitions bindings #imports _ #tags tags #types types #module_annotations _ #module_state _} =module]] + .let [{#module_hash _ #module_aliases _ #definitions bindings #imports _ #tags tags #types types #module_annotations _ #module_state _} =module]] (case (get name types) (#Some [tags exported? (#Named _ _type)]) (case (interface_methods _type) (#Some members) - (return (#Some [tags members])) + (in_meta (#Some [tags members])) _ - (return #None)) + (in_meta #None)) _ (record_slots unnamed))) _ - (return #None))) + (in_meta #None))) (def: get_expected_type (Meta Type) @@ -3513,11 +3515,11 @@ tags (: (Meta (List Name)) (case tags+type (#Some [tags _]) - (return tags) + (in_meta tags) _ (failure "No tags available for type."))) - #let [tag_mappings (: (List [Text Code]) + .let [tag_mappings (: (List [Text Code]) (list\map (function (_ tag) [(second tag) (tag$ tag)]) tags))] members (monad\map meta_monad @@ -3589,11 +3591,11 @@ _ (` ((~ name) (~+ args))))] - (return (list (` (..def: (~+ (export exported?)) (~ usage) - (~ (merged_definition_annotations (` {#.implementation? #1}) - meta)) - (~ type) - (implementation (~+ definitions))))))) + (in_meta (list (` (..def: (~+ (export exported?)) (~ usage) + (~ (merged_definition_annotations (` {#.implementation? #1}) + meta)) + (~ type) + (implementation (~+ definitions))))))) #None (failure "Wrong syntax for implementation:")))) @@ -3669,20 +3671,20 @@ (let [typeC (` (#.Named [(~ (text$ module_name)) (~ (text$ name))] (.type (~ type''))))] - (return (list (case tags?? - (#Some tags) - (` ("lux def type tagged" (~ type_name) - (~ typeC) - (~ total_meta) - [(~+ (list\map text$ tags))] - (~ (bit$ exported?)))) - - _ - (` ("lux def" (~ type_name) - ("lux type check type" - (~ typeC)) - (~ total_meta) - (~ (bit$ exported?)))))))) + (in_meta (list (case tags?? + (#Some tags) + (` ("lux def type tagged" (~ type_name) + (~ typeC) + (~ total_meta) + [(~+ (list\map text$ tags))] + (~ (bit$ exported?)))) + + _ + (` ("lux def" (~ type_name) + ("lux type check type" + (~ typeC)) + (~ total_meta) + (~ (bit$ exported?)))))))) #None (failure "Wrong syntax for type:")))) @@ -3728,7 +3730,7 @@ (function (_ def) (case def [_ (#Identifier ["" name])] - (return name) + (in_meta name) _ (failure "#only/#+ and #exclude/#- require identifiers.")))) @@ -3751,20 +3753,20 @@ (^or (^ (list& [_ (#Tag ["" "*"])] tokens')) (^ (list& [_ (#Tag ["" "all"])] tokens'))) - (return [#All tokens']) + (in_meta [#All tokens']) (^or (^ (list& [_ (#Tag ["" "_"])] tokens')) (^ (list& [_ (#Tag ["" "nothing"])] tokens'))) - (return [#Ignore tokens']) + (in_meta [#Ignore tokens']) _ - (return [#Nothing tokens]))) + (in_meta [#Nothing tokens]))) (def: (openings_parser parts) (-> (List Code) (Meta [(List Openings) (List Code)])) (case parts #.End - (return [#.End #.End]) + (in_meta [#.End #.End]) (^ (list& [_ (#Form (list& [_ (#Text prefix)] structs))] parts')) (do meta_monad @@ -3772,18 +3774,18 @@ (function (_ struct) (case struct [_ (#Identifier ["" struct_name])] - (return struct_name) + (in_meta struct_name) _ (failure "Expected all implementations of opening form to be identifiers."))) structs) next+remainder (openings_parser parts')] (let [[next remainder] next+remainder] - (return [(#.Item [prefix structs'] next) - remainder]))) + (in_meta [(#.Item [prefix structs'] next) + remainder]))) _ - (return [#.End parts]))) + (in_meta [#.End parts]))) (def: (text\split! at x) (-> Nat Text [Text Text]) @@ -3794,7 +3796,7 @@ (-> Text Text (Maybe [Text Text])) (do ..maybe_monad [index (..index token sample) - #let [[pre post'] (text\split! index sample) + .let [[pre post'] (text\split! index sample) [_ post] (text\split! ("lux text size" token) post')]] (in [pre post]))) @@ -3876,13 +3878,13 @@ [_ (#Item _ tail)] (list\drop ("lux i64 -" 1 amount) tail))) -(def: (clean_module nested? relative_root module) +(def: (absolute_module_name nested? relative_root module) (-> Bit Text Text (Meta Text)) (case (count_relatives 0 module) 0 - (return (if nested? - ($_ "lux text concat" relative_root ..module_separator module) - module)) + (in_meta (if nested? + ($_ "lux text concat" relative_root ..module_separator module) + module)) relatives (let [parts (text\split_all_with ..module_separator relative_root) @@ -3898,27 +3900,12 @@ output (case ("lux text size" clean) 0 prefix _ ($_ text\compose prefix ..module_separator clean))] - (return output)) + (in_meta output)) (failure ($_ "lux text concat" "Cannot climb the module hierarchy..." ..\n "Importing module: " module ..\n " Relative Root: " relative_root ..\n)))))) -(def: (alter_domain alteration domain import) - (-> Nat Text Importation Importation) - (let [[import_name import_alias import_refer] import - original (text\split_all_with ..module_separator import_name) - truncated (list\drop (.nat alteration) original) - parallel (case domain - "" - truncated - - _ - (list& domain truncated))] - {#import_name (text\join_with ..module_separator parallel) - #import_alias import_alias - #import_refer import_refer})) - (def: (imports_parser nested? relative_root context_alias imports) (-> Bit Text Text (List Code) (Meta (List Importation))) (do meta_monad @@ -3927,59 +3914,59 @@ (function (_ token) (case token ## Simple - [_ (#Identifier ["" m_name])] + [_ (#Identifier ["" module_name])] (do meta_monad - [m_name (clean_module nested? relative_root m_name)] - (in (list {#import_name m_name + [absolute_module_name (..absolute_module_name nested? relative_root module_name)] + (in (list {#import_name absolute_module_name #import_alias #None #import_refer {#refer_defs #All #refer_open (list)}}))) ## Nested - (^ [_ (#Tuple (list& [_ (#Identifier ["" m_name])] extra))]) + (^ [_ (#Tuple (list& [_ (#Identifier ["" module_name])] extra))]) (do meta_monad - [import_name (case (normal_parallel_path relative_root m_name) - (#.Some parallel_path) - (in parallel_path) + [absolute_module_name (case (normal_parallel_path relative_root module_name) + (#.Some parallel_path) + (in parallel_path) - #.None - (clean_module nested? relative_root m_name)) + #.None + (..absolute_module_name nested? relative_root module_name)) referral+extra (referrals_parser extra) - #let [[referral extra] referral+extra] + .let [[referral extra] referral+extra] openings+extra (openings_parser extra) - #let [[openings extra] openings+extra] - sub_imports (imports_parser #1 import_name context_alias extra)] + .let [[openings extra] openings+extra] + sub_imports (imports_parser #1 absolute_module_name context_alias extra)] (in (case [referral openings] [#Nothing #End] sub_imports _ - (list& {#import_name import_name + (list& {#import_name absolute_module_name #import_alias #None #import_refer {#refer_defs referral #refer_open openings}} sub_imports)))) - (^ [_ (#Tuple (list& [_ (#Text alias)] [_ (#Identifier ["" m_name])] extra))]) + (^ [_ (#Tuple (list& [_ (#Text alias)] [_ (#Identifier ["" module_name])] extra))]) (do meta_monad - [import_name (case (normal_parallel_path relative_root m_name) - (#.Some parallel_path) - (in parallel_path) + [absolute_module_name (case (normal_parallel_path relative_root module_name) + (#.Some parallel_path) + (in parallel_path) - #.None - (clean_module nested? relative_root m_name)) + #.None + (..absolute_module_name nested? relative_root module_name)) referral+extra (referrals_parser extra) - #let [[referral extra] referral+extra] + .let [[referral extra] referral+extra] openings+extra (openings_parser extra) - #let [[openings extra] openings+extra - module_alias (..module_alias context_alias m_name alias)] - sub_imports (imports_parser #1 import_name module_alias extra)] + .let [[openings extra] openings+extra + module_alias (..module_alias context_alias module_name alias)] + sub_imports (imports_parser #1 absolute_module_name module_alias extra)] (in (case [referral openings] [#Ignore #End] sub_imports _ - (list& {#import_name import_name + (list& {#import_name absolute_module_name #import_alias (#Some module_alias) #import_refer {#refer_defs referral #refer_open openings}} @@ -4148,7 +4135,7 @@ (def: (type_definition full_name) (-> Name (Meta Type)) (do meta_monad - [#let [[module name] full_name] + [.let [[module name] full_name] current_module current_module_name] (function (_ compiler) (let [temp (if (text\= "" module) @@ -4310,12 +4297,12 @@ (failure "cond requires an uneven number of arguments.") (case (list\reverse tokens) (^ (list& else branches')) - (return (list (list\fold (: (-> [Code Code] Code Code) - (function (_ branch else) - (let [[right left] branch] - (` (if (~ left) (~ right) (~ else)))))) - else - (pairs branches')))) + (in_meta (list (list\fold (: (-> [Code Code] Code Code) + (function (_ branch else) + (let [[right left] branch] + (` (if (~ left) (~ right) (~ else)))))) + else + (pairs branches')))) _ (failure "Wrong syntax for cond")))) @@ -4349,7 +4336,7 @@ (do meta_monad [slot (normal slot') output (..type_tag slot) - #let [[idx tags exported? type] output] + .let [[idx tags exported? type] output] g!_ (gensym "_") g!output (gensym "")] (case (interface_methods type) @@ -4361,17 +4348,17 @@ g!output g!_)])) (zipped/2 tags (enumeration members))))] - (return (list (` ({(~ pattern) (~ g!output)} (~ record)))))) + (in_meta (list (` ({(~ pattern) (~ g!output)} (~ record)))))) _ (failure "get@ can only use records."))) (^ (list [_ (#Tuple slots)] record)) - (return (list (list\fold (: (-> Code Code Code) - (function (_ slot inner) - (` (..get@ (~ slot) (~ inner))))) - record - slots))) + (in_meta (list (list\fold (: (-> Code Code Code) + (function (_ slot inner) + (` (..get@ (~ slot) (~ inner))))) + record + slots))) (^ (list selector)) (do meta_monad @@ -4387,7 +4374,7 @@ (do meta_monad [output (record_slots type) g!_ (gensym "g!_") - #let [g!output (local_identifier$ short) + .let [g!output (local_identifier$ short) pattern (|> tags enumeration (list\map (function (_ [tag_idx tag]) @@ -4404,13 +4391,13 @@ (function (_ [sub_tag_index sname stype]) (open_declaration alias tags' sub_tag_index sname source+ stype))) (enumeration (zipped/2 tags' members')))] - (return (list\join decls'))) + (in_meta (list\join decls'))) _ - (return (list (` ("lux def" (~ (local_identifier$ (..module_alias "" short alias))) - (~ source+) - [(~ location_code) (#.Record #End)] - #0))))))) + (in_meta (list (` ("lux def" (~ (local_identifier$ (..module_alias "" short alias))) + (~ source+) + [(~ location_code) (#.Record #End)] + #0))))))) (macro: #export (open: tokens) {#.doc (text$ ($_ "lux text concat" @@ -4431,7 +4418,7 @@ (do meta_monad [struct_type (type_definition struct_name) output (record_slots struct_type) - #let [source (identifier$ struct_name)]] + .let [source (identifier$ struct_name)]] (case output (#Some [tags members]) (do meta_monad @@ -4439,7 +4426,7 @@ (function (_ [tag_index sname stype]) (open_declaration alias tags tag_index sname source stype))) (enumeration (zipped/2 tags members)))] - (return (list\join decls'))) + (in_meta (list\join decls'))) _ (failure (text\compose "Can only 'open:' structs: " (type\encode struct_type))))) @@ -4447,10 +4434,10 @@ _ (do meta_monad [g!struct (gensym "struct")] - (return (list (` ("lux def" (~ g!struct) (~ struct) - [(~ location_code) (#.Record #End)] - #0)) - (` (..open: (~ (text$ alias)) (~ g!struct))))))) + (in_meta (list (` ("lux def" (~ g!struct) (~ struct) + [(~ location_code) (#.Record #End)] + #0)) + (` (..open: (~ (text$ alias)) (~ g!struct))))))) _ (failure "Wrong syntax for open:"))) @@ -4464,7 +4451,7 @@ (do meta_monad [g!_ (gensym "_") g!arg (gensym "arg")] - (return (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens)))))))) + (in_meta (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens)))))))) (macro: #export (<<| tokens) {#.doc (text$ ($_ "lux text concat" @@ -4475,22 +4462,22 @@ (do meta_monad [g!_ (gensym "_") g!arg (gensym "arg")] - (return (list (` (function ((~ g!_) (~ g!arg)) (<| (~+ tokens) (~ g!arg)))))))) + (in_meta (list (` (function ((~ g!_) (~ g!arg)) (<| (~+ tokens) (~ g!arg)))))))) (def: (imported_by? import_name module_name) (-> Text Text (Meta Bit)) (do meta_monad [module (module module_name) - #let [{#module_hash _ #module_aliases _ #definitions _ #imports imports #tags _ #types _ #module_annotations _ #module_state _} module]] + .let [{#module_hash _ #module_aliases _ #definitions _ #imports imports #tags _ #types _ #module_annotations _ #module_state _} module]] (in (is_member? imports import_name)))) (def: (referrals module_name options) (-> Text (List Code) (Meta Refer)) (do meta_monad [referral+options (referrals_parser options) - #let [[referral options] referral+options] + .let [[referral options] referral+options] openings+options (openings_parser options) - #let [[openings options] openings+options] + .let [[openings options] openings+options] current_module current_module_name] (case options #End @@ -4508,13 +4495,13 @@ (-> Text Refer (Meta (List Code))) (do meta_monad [current_module current_module_name - #let [test_referrals (: (-> Text (List Text) (List Text) (Meta (List Any))) + .let [test_referrals (: (-> Text (List Text) (List Text) (Meta (List Any))) (function (_ module_name all_defs referred_defs) (monad\map meta_monad (: (-> Text (Meta Any)) (function (_ _def) (if (is_member? all_defs _def) - (return []) + (in_meta []) (failure ($_ text\compose _def " is not defined in module " module_name " @ " current_module))))) referred_defs)))] defs' (case r_defs @@ -4538,7 +4525,7 @@ #Nothing (in (list))) - #let [defs (list\map (: (-> Text Code) + .let [defs (list\map (: (-> Text Code) (function (_ def) (` ("lux def alias" (~ (local_identifier$ def)) (~ (identifier$ [module_name def])))))) defs') @@ -4607,7 +4594,7 @@ " [//" ..\n " [type (''.'' equivalence)]])"))} (do meta_monad - [#let [[_meta _imports] (: [(List [Code Code]) (List Code)] + [.let [[_meta _imports] (: [(List [Code Code]) (List Code)] (case tokens (^ (list& [_ (#Record _meta)] _imports)) [_meta _imports] @@ -4616,14 +4603,14 @@ [(list) tokens]))] current_module current_module_name imports (imports_parser #0 current_module "" _imports) - #let [=imports (|> imports + .let [=imports (|> imports (list\map (: (-> Importation Code) - (function (_ [m_name m_alias =refer]) - (` [(~ (text$ m_name)) (~ (text$ (..else "" m_alias)))])))) + (function (_ [module_name m_alias =refer]) + (` [(~ (text$ module_name)) (~ (text$ (..else "" m_alias)))])))) tuple$) =refers (list\map (: (-> Importation Code) - (function (_ [m_name m_alias =refer]) - (refer_code m_name m_alias =refer))) + (function (_ [module_name m_alias =refer]) + (refer_code module_name m_alias =refer))) imports) =module (` ("lux def module" [(~ location_code) (#.Record (~ (definition_annotations _meta)))] @@ -4639,10 +4626,10 @@ "(\ codec encode +123)"))} (case tokens (^ (list struct [_ (#Identifier member)])) - (return (list (` (let [(^open (~ (text$ ..self_reference))) (~ struct)] (~ (identifier$ member)))))) + (in_meta (list (` (let [(^open (~ (text$ ..self_reference))) (~ struct)] (~ (identifier$ member)))))) (^ (list& struct member args)) - (return (list (` ((..\ (~ struct) (~ member)) (~+ args))))) + (in_meta (list (` ((..\ (~ struct) (~ member)) (~+ args))))) _ (failure "Wrong syntax for \"))) @@ -4663,7 +4650,7 @@ (do meta_monad [slot (normal slot') output (..type_tag slot) - #let [[idx tags exported? type] output]] + .let [[idx tags exported? type] output]] (case (interface_methods type) (#Some members) (do meta_monad @@ -4672,7 +4659,7 @@ (function (_ [r_slot_name [r_idx r_type]]) (do meta_monad [g!slot (gensym "")] - (return [r_slot_name r_idx g!slot])))) + (in_meta [r_slot_name r_idx g!slot])))) (zipped/2 tags (enumeration members)))] (let [pattern (record$ (list\map (: (-> [Name Nat Code] [Code Code]) (function (_ [r_slot_name r_idx r_var]) @@ -4686,7 +4673,7 @@ value r_var)])) pattern'))] - (return (list (` ({(~ pattern) (~ output)} (~ record))))))) + (in_meta (list (` ({(~ pattern) (~ output)} (~ record))))))) _ (failure "set@ can only use records."))) @@ -4702,7 +4689,7 @@ (: (-> Code (Meta Code)) (function (_ _) (gensym "temp"))) slots) - #let [pairs (zipped/2 slots bindings) + .let [pairs (zipped/2 slots bindings) update_expr (list\fold (: (-> [Code Code] Code Code) (function (_ [s b] v) (` (..set@ (~ s) (~ v) (~ b))))) @@ -4752,7 +4739,7 @@ (do meta_monad [slot (normal slot') output (..type_tag slot) - #let [[idx tags exported? type] output]] + .let [[idx tags exported? type] output]] (case (interface_methods type) (#Some members) (do meta_monad @@ -4761,7 +4748,7 @@ (function (_ [r_slot_name [r_idx r_type]]) (do meta_monad [g!slot (gensym "")] - (return [r_slot_name r_idx g!slot])))) + (in_meta [r_slot_name r_idx g!slot])))) (zipped/2 tags (enumeration members)))] (let [pattern (record$ (list\map (: (-> [Name Nat Code] [Code Code]) (function (_ [r_slot_name r_idx r_var]) @@ -4775,7 +4762,7 @@ (` ((~ fun) (~ r_var))) r_var)])) pattern'))] - (return (list (` ({(~ pattern) (~ output)} (~ record))))))) + (in_meta (list (` ({(~ pattern) (~ output)} (~ record))))))) _ (failure "update@ can only use records."))) @@ -4866,7 +4853,7 @@ in)) #None)))) (#Some output) - (return (list\compose output branches)) + (in_meta (list\compose output branches)) #None (failure "Wrong syntax for ^template")) @@ -4901,18 +4888,18 @@ (list\map (|>> second baseline_column) pairs))) )) -(type: Doc_Fragment - (#Doc_Comment Text) - (#Doc_Example Code)) +(type: Documentation_Fragment + (#Documentation_Comment Text) + (#Documentation_Example Code)) -(def: (identify_doc_fragment code) - (-> Code Doc_Fragment) +(def: (documentation_fragment code) + (-> Code Documentation_Fragment) (case code [_ (#Text comment)] - (#Doc_Comment comment) + (#Documentation_Comment comment) _ - (#Doc_Example code))) + (#Documentation_Example code))) (template [<name> <extension> <doc>] [(def: #export <name> @@ -4963,7 +4950,7 @@ (|>> (list\map pair_list) list\join))) -(def: (doc_example_to_text prev_location baseline example) +(def: (example_documentation prev_location baseline example) (-> Location Nat Code [Location Text]) (case example (^template [<tag> <encode>] @@ -4983,7 +4970,7 @@ (^template [<tag> <open> <close> <prep>] [[group_location (<tag> parts)] (let [[group_location' parts_text] (list\fold (function (_ part [last_location text_accum]) - (let [[part_location part_text] (doc_example_to_text last_location baseline part)] + (let [[part_location part_text] (example_documentation last_location baseline part)] [part_location (text\compose text_accum part_text)])) [(delim_update_location group_location) ""] (<prep> parts))] @@ -4997,26 +4984,26 @@ [#Record "{" "}" ..un_paired]) [new_location (#Rev value)] - ("lux io error" "@doc_example_to_text Undefined behavior.") + ("lux io error" "@example_documentation Undefined behavior.") )) (def: (with_baseline baseline [file line column]) (-> Nat Location Location) [file line baseline]) -(def: (doc_fragment_to_text fragment) - (-> Doc_Fragment Text) +(def: (fragment_documentation fragment) + (-> Documentation_Fragment Text) (case fragment - (#Doc_Comment comment) + (#Documentation_Comment comment) (|> comment (text\split_all_with ..\n) (list\map (function (_ line) ($_ text\compose "## " line ..\n))) (text\join_with "")) - (#Doc_Example example) + (#Documentation_Example example) (let [baseline (baseline_column example) [location _] example - [_ text] (doc_example_to_text (with_baseline baseline location) baseline example)] + [_ text] (..example_documentation (with_baseline baseline location) baseline example)] (text\compose text __paragraph)))) (macro: #export (doc tokens) @@ -5031,13 +5018,13 @@ " (if (< +10 count)" ..\n " (recur (inc count) (f x))" ..\n " x)))"))} - (return (list (` [(~ location_code) - (#.Text (~ (|> tokens - (list\map (|>> identify_doc_fragment doc_fragment_to_text)) - (text\join_with "") - text$)))])))) + (in_meta (list (` [(~ location_code) + (#.Text (~ (|> tokens + (list\map (|>> ..documentation_fragment ..fragment_documentation)) + (text\join_with "") + text$)))])))) -(def: (interleave xs ys) +(def: (interleaved xs ys) (All [a] (-> (List a) (List a) (List a))) (case xs #End @@ -5049,7 +5036,7 @@ #End (#Item y ys') - (list& x y (interleave xs' ys'))))) + (list& x y (interleaved xs' ys'))))) (def: (type_code type) (-> Type Code) @@ -5116,25 +5103,25 @@ (do meta_monad [inits' (: (Meta (List Name)) (case (monad\map maybe_monad get_name inits) - (#Some inits') (return inits') + (#Some inits') (in_meta inits') #None (failure "Wrong syntax for loop"))) init_types (monad\map meta_monad type_definition inits') expected get_expected_type] - (return (list (` (("lux type check" - (-> (~+ (list\map type_code init_types)) - (~ (type_code expected))) - (function ((~ name) (~+ vars)) - (~ body))) - (~+ inits)))))) + (in_meta (list (` (("lux type check" + (-> (~+ (list\map type_code init_types)) + (~ (type_code expected))) + (function ((~ name) (~+ vars)) + (~ body))) + (~+ inits)))))) (do meta_monad [aliases (monad\map meta_monad (: (-> Code (Meta Code)) (function (_ _) (gensym ""))) inits)] - (return (list (` (let [(~+ (interleave aliases inits))] - (.loop (~ name) - [(~+ (interleave vars aliases))] - (~ body))))))))) + (in_meta (list (` (let [(~+ (..interleaved aliases inits))] + (.loop (~ name) + [(~+ (..interleaved vars aliases))] + (~ body))))))))) #.None (failure "Wrong syntax for loop")))) @@ -5154,16 +5141,16 @@ tslots (monad\map maybe_monad get_tag tslots')] (in [hslot tslots]))) (#Some slots) - (return slots) + (in_meta slots) #None (failure "Wrong syntax for ^slots"))) - #let [[hslot tslots] slots] + .let [[hslot tslots] slots] hslot (..normal hslot) tslots (monad\map meta_monad ..normal tslots) output (..type_tag hslot) g!_ (gensym "_") - #let [[idx tags exported? type] output + .let [[idx tags exported? type] output slot_pairings (list\map (: (-> Name [Text Code]) (function (_ [module name]) [name (local_identifier$ name)])) @@ -5175,7 +5162,7 @@ (#Some binding) [tag binding] #None [tag g!_])))) tags))]] - (return (list& pattern body branches))) + (in_meta (list& pattern body branches))) _ (failure "Wrong syntax for ^slots"))) @@ -5254,7 +5241,7 @@ (failure "[with_expansions] Improper macro expansion."))) #End - (return bodies) + (in_meta bodies) _ (failure "Wrong syntax for with_expansions")) @@ -5281,11 +5268,11 @@ _ type)) -(def: (anti_quote_def name) +(def: (static_simple_literal name) (-> Name (Meta Code)) (do meta_monad [type+value (definition_value name) - #let [[type value] type+value]] + .let [[type value] type+value]] (case (flat_alias type) (^template [<name> <type> <wrapper>] [(#Named ["library/lux" <name>] _) @@ -5300,20 +5287,20 @@ _ (failure (text\compose "Cannot anti-quote type: " (name\encode name)))))) -(def: (anti_quote token) +(def: (static_literal token) (-> Code (Meta Code)) (case token [_ (#Identifier [def_prefix def_name])] (if (text\= "" def_prefix) (do meta_monad [current_module current_module_name] - (anti_quote_def [current_module def_name])) - (anti_quote_def [def_prefix def_name])) + (static_simple_literal [current_module def_name])) + (static_simple_literal [def_prefix def_name])) (^template [<tag>] [[meta (<tag> parts)] (do meta_monad - [=parts (monad\map meta_monad anti_quote parts)] + [=parts (monad\map meta_monad static_literal parts)] (in [meta (<tag> =parts)]))]) ([#Form] [#Tuple]) @@ -5324,13 +5311,13 @@ (: (-> [Code Code] (Meta [Code Code])) (function (_ [slot value]) (do meta_monad - [=value (anti_quote value)] + [=value (static_literal value)] (in [slot =value])))) pairs)] (in [meta (#Record =pairs)])) _ - (\ meta_monad return token) + (\ meta_monad in_meta token) ## TODO: Figure out why this doesn't work: ## (\ meta_monad in token) )) @@ -5339,7 +5326,7 @@ (case tokens (^ (list pattern)) (do meta_monad - [pattern' (anti_quote pattern)] + [pattern' (static_literal pattern)] (in (list pattern'))) _ @@ -5352,10 +5339,10 @@ (-> Code (Meta [Code Code])) (case level (^ [_ (#Record (list [expr binding]))]) - (return [expr binding]) + (in_meta [expr binding]) _ - (return [level (` #1)]) + (in_meta [level (` #1)]) )) (def: (multi_level_case^ levels) @@ -5414,7 +5401,7 @@ (^ (list& [_meta (#Form levels)] body next_branches)) (do meta_monad [mlc (multi_level_case^ levels) - #let [initial_bind? (case mlc + .let [initial_bind? (case mlc [[_ (#.Identifier _)] _] #1 @@ -5457,7 +5444,7 @@ (case tokens (^template [<tag>] [(^ (list [_ (<tag> [prefix name])])) - (return (list (` [(~ (text$ prefix)) (~ (text$ name))])))]) + (in_meta (list (` [(~ (text$ prefix)) (~ (text$ name))])))]) ([#Identifier] [#Tag]) _ @@ -5516,9 +5503,9 @@ (case tokens (^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] pattern))] body branches)) (let [g!whole (local_identifier$ name)] - (return (list& g!whole - (` (case (~ g!whole) (~ pattern) (~ body))) - branches))) + (in_meta (list& g!whole + (` (case (~ g!whole) (~ pattern) (~ body))) + branches))) _ (failure (..wrong_syntax_error (name_of ..^@))))) @@ -5531,10 +5518,10 @@ (case tokens (^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] [_ (#Tuple steps)]))] body branches)) (let [g!name (local_identifier$ name)] - (return (list& g!name - (` (let [(~ g!name) (|> (~ g!name) (~+ steps))] - (~ body))) - branches))) + (in_meta (list& g!name + (` (let [(~ g!name) (|> (~ g!name) (~+ steps))] + (~ body))) + branches))) _ (failure (..wrong_syntax_error (name_of ..^|>))))) @@ -5568,7 +5555,7 @@ #End (do meta_monad [location ..location - #let [[module line column] location + .let [[module line column] location location ($_ "lux text concat" (text\encode module) "," (nat\encode line) "," (nat\encode column)) message ($_ "lux text concat" "Undefined behavior @ " location)]] (in (list (` (..error! (~ (text$ message))))))) @@ -5627,7 +5614,7 @@ (-> (List Code) (Meta [Code (List Code)])) (case tokens (^ (list& token tokens')) - (return [token tokens']) + (in_meta [token tokens']) _ (failure "Could not parse anything.") @@ -5637,7 +5624,7 @@ (-> (List Code) (Meta [(List Code) (List Code)])) (case tokens (^ (list& head tail)) - (return [tokens (list)]) + (in_meta [tokens (list)]) _ (failure "Could not parse anything.") @@ -5647,7 +5634,7 @@ (-> (List Code) (Meta Any)) (case tokens (^ (list)) - (return []) + (in_meta []) _ (failure "Expected input Codes to be empty.") @@ -5657,10 +5644,10 @@ (-> (List Code) (Meta [Code (List Code)])) (case tokens (^ (list& [_ (#Record _anns)] tokens')) - (return [(record$ _anns) tokens']) + (in_meta [(record$ _anns) tokens']) _ - (return [(' {}) tokens]) + (in_meta [(' {}) tokens]) )) (macro: #export (template: tokens) @@ -5669,18 +5656,18 @@ (template: (square x) (* x x)))} (do meta_monad - [#let [[export? tokens] (export^ tokens)] + [.let [[export? tokens] (export^ tokens)] name+args|tokens (complex_declaration_parser tokens) - #let [[[name args] tokens] name+args|tokens] + .let [[[name args] tokens] name+args|tokens] anns|tokens (anns_parser tokens) - #let [[anns tokens] anns|tokens] + .let [[anns tokens] anns|tokens] input_templates|tokens (many_parser tokens) - #let [[input_templates tokens] input_templates|tokens] + .let [[input_templates tokens] input_templates|tokens] _ (end_parser tokens) g!tokens (gensym "tokens") g!compiler (gensym "compiler") g!_ (gensym "_") - #let [rep_env (list\map (function (_ arg) + .let [rep_env (list\map (function (_ arg) [arg (` ((~' ~) (~ (local_identifier$ arg))))]) args)] this_module current_module_name] @@ -5723,13 +5710,13 @@ (-> Code (Meta Text)) (case choice [_ (#Text platform)] - (..return platform) + (..in_meta platform) [_ (#Identifier identifier)] (do meta_monad [identifier (..global_identifier identifier) type+value (..definition_value identifier) - #let [[type value] type+value]] + .let [[type value] type+value]] (case (..flat_alias type) (^or (#Primitive "#Text" #End) (#Named ["library/lux" "Text"] (#Primitive "#Text" #End))) @@ -5754,13 +5741,13 @@ (failure ($_ text\compose "No code for target platform: " target)) (#.Some default) - (return (list default))) + (in_meta (list default))) (#Item [key pick] options') (do meta_monad [platform (..platform_name key)] (if (text\= target platform) - (return (list pick)) + (in_meta (list pick)) (target_pick target options' default))))) (macro: #export (for tokens) @@ -5776,14 +5763,13 @@ _ (failure (..wrong_syntax_error (name_of ..for)))))) -(template [<name> <type> <output>] - [(def: (<name> xy) - (All [a b] (-> [a b] <type>)) - (let [[x y] xy] - <output>))] +(template [<name>] + [(def: (<name> [left right]) + (All [left right] (-> [left right] <name>)) + <name>)] - [left a x] - [right b y]) + [left] + [right]) (def: (embedded_expansions code) (-> Code (Meta [(List [Code Code]) Code])) @@ -5808,7 +5794,7 @@ (do meta_monad [=key (embedded_expansions key) =val (embedded_expansions val) - #let [[key_labels key_labelled] =key + .let [[key_labels key_labelled] =key [val_labels val_labelled] =val]] (in [(list\compose key_labels val_labels) [key_labelled val_labelled]]))) kvs)] @@ -5816,22 +5802,21 @@ [ann (#Record (list\map right =kvs))]])) _ - (return [(list) code]))) + (in_meta [(list) code]))) (macro: #export (`` tokens) (case tokens (^ (list raw)) (do meta_monad [=raw (..embedded_expansions raw) - #let [[labels labelled] =raw]] + .let [[labels labelled] =raw]] (in (list (` (with_expansions [(~+ (|> labels (list\map (function (_ [label expansion]) (list label expansion))) list\join))] (~ labelled)))))) _ - (failure (..wrong_syntax_error (name_of ..``))) - )) + (failure (..wrong_syntax_error (name_of ..``))))) (def: (name$ [module name]) (-> Name Code) @@ -5897,7 +5882,7 @@ [#.Identifier name$]) [_ (#Form (#Item [[_ (#Identifier ["" "~"])] (#Item [unquoted #End])]))] - (return unquoted) + (in_meta unquoted) [_ (#Form (#Item [[_ (#Identifier ["" "~+"])] (#Item [spliced #End])]))] (failure "Cannot use (~+) inside of ^code unless it is the last element in a form or a tuple.") @@ -5939,12 +5924,12 @@ (case tokens (^ (list [_ (#Tuple bindings)] bodyT)) (if (multiple? 2 (list\size bindings)) - (return (list (` (..with_expansions [(~+ (|> bindings - ..pairs - (list\map (function (_ [localT valueT]) - (list localT (` (..as_is (~ valueT)))))) - (list\fold list\compose (list))))] - (~ bodyT))))) + (in_meta (list (` (..with_expansions [(~+ (|> bindings + ..pairs + (list\map (function (_ [localT valueT]) + (list localT (` (..as_is (~ valueT)))))) + (list\fold list\compose (list))))] + (~ bodyT))))) (..failure ":let requires an even number of parts")) _ diff --git a/stdlib/source/library/lux/abstract/comonad.lux b/stdlib/source/library/lux/abstract/comonad.lux index 3c2ce81b7..869eb3de5 100644 --- a/stdlib/source/library/lux/abstract/comonad.lux +++ b/stdlib/source/library/lux/abstract/comonad.lux @@ -50,14 +50,17 @@ g!split (gensym "split") body' (list\fold (: (-> [Code Code] Code Code) (function (_ binding body') - (let [[var value] binding] - (case var - [_ (#.Tag ["" "let"])] - (` (let (~ value) (~ body'))) + (with_expansions [<default> (` (|> (~ value) (~ g!split) ((~ g!map) (function ((~ g!_) (~ var)) (~ body')))))] + (let [[var value] binding] + (case var + [_ (#.Identifier ["" _])] + <default> - _ - (` (|> (~ value) (~ g!split) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))))) - )))) + [_ (#.Identifier _)] + (` ((~ var) (~ value) (~ body'))) + + _ + <default>))))) body (list.reversed (list.pairs bindings)))] (#.Right [state (list (case ?name diff --git a/stdlib/source/library/lux/abstract/monad.lux b/stdlib/source/library/lux/abstract/monad.lux index b0e09b794..0bbb58149 100644 --- a/stdlib/source/library/lux/abstract/monad.lux +++ b/stdlib/source/library/lux/abstract/monad.lux @@ -82,14 +82,17 @@ g!join (gensym "join") body' (list\fold (: (-> [Code Code] Code Code) (function (_ binding body') - (let [[var value] binding] - (case var - [_ (#.Tag ["" "let"])] - (` (let (~ value) (~ body'))) - - _ - (` (|> (~ value) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))) (~ g!join))) - )))) + (with_expansions [<default> (` (|> (~ value) ((~ g!map) (function ((~ g!_) (~ var)) (~ body'))) (~ g!join)))] + (let [[var value] binding] + (case var + [_ (#.Identifier ["" _])] + <default> + + [_ (#.Identifier _)] + (` ((~ var) (~ value) (~ body'))) + + _ + <default>))))) body (reversed (pairs bindings)))] (#.Right [state (list (case ?name diff --git a/stdlib/source/library/lux/abstract/monad/indexed.lux b/stdlib/source/library/lux/abstract/monad/indexed.lux index c32aac5eb..120e33a7d 100644 --- a/stdlib/source/library/lux/abstract/monad/indexed.lux +++ b/stdlib/source/library/lux/abstract/monad/indexed.lux @@ -2,7 +2,6 @@ [library [lux #* [control - [monad] ["<>" parser ["<.>" code (#+ Parser)]]] [data @@ -10,7 +9,8 @@ ["." list ("#\." functor fold)]]] ["." macro [syntax (#+ syntax:)] - ["." code]]]]) + ["." code]]]] + ["." //]) (interface: #export (IxMonad m) (: (All [p a] @@ -31,13 +31,20 @@ (<>.and <code>.any <code>.any)) (type: Context - (#Let (List Binding)) + (#Macro Name Code) (#Bind Binding)) +(def: global_identifier + (Parser Name) + (//.do <>.monad + [[module short] <code>.identifier + _ (<>.assertion "" (case module "" false _ true))] + (in [module short]))) + (def: context (Parser Context) - (<>.or (<>.after (<code>.this! (' #let)) - (<code>.tuple (<>.some binding))) + (<>.or (<>.and ..global_identifier + <code>.any) binding)) (def: (pair_list [binding value]) @@ -58,11 +65,10 @@ (macro.with_gensyms [g!_ g!bind] (let [body (list\fold (function (_ context next) (case context - (#Let bindings) - (` (let [(~+ (|> bindings - (list\map pair_list) - list.concat))] - (~ next))) + (#Macro macro parameter) + (` ((~ (code.identifier macro)) + (~ parameter) + (~ next))) (#Bind [binding value]) (` ((~ g!bind) diff --git a/stdlib/source/library/lux/control/concurrency/actor.lux b/stdlib/source/library/lux/control/concurrency/actor.lux index 067cf0178..eff114796 100644 --- a/stdlib/source/library/lux/control/concurrency/actor.lux +++ b/stdlib/source/library/lux/control/concurrency/actor.lux @@ -263,9 +263,9 @@ ((on_mail mail state self) (do (try.with async.monad) - [#let [_ (debug.log! "BEFORE")] + [.let [_ (debug.log! "BEFORE")] output (mail state self) - #let [_ (debug.log! "AFTER")]] + .let [_ (debug.log! "AFTER")]] (in output))) (message: #export (push {value a} state self) @@ -296,7 +296,7 @@ (with_gensyms [g!_] (do meta.monad [g!type (macro.gensym (format name "_abstract_type")) - #let [g!actor (code.local_identifier name) + .let [g!actor (code.local_identifier name) g!vars (list\map code.local_identifier vars)]] (in (list (` ((~! abstract:) (~+ (|export|.format export)) ((~ g!type) (~+ g!vars)) (~ state_type) @@ -361,7 +361,7 @@ (with_gensyms [g!_ g!return] (do meta.monad [actor_scope abstract.current - #let [g!type (code.local_identifier (get@ #abstract.name actor_scope)) + .let [g!type (code.local_identifier (get@ #abstract.name actor_scope)) g!message (code.local_identifier (get@ #name signature)) g!actor_vars (get@ #abstract.type_vars actor_scope) g!all_vars (|> signature (get@ #vars) (list\map code.local_identifier) (list\compose g!actor_vars)) diff --git a/stdlib/source/library/lux/control/concurrency/async.lux b/stdlib/source/library/lux/control/concurrency/async.lux index dc95a97e1..243d7327f 100644 --- a/stdlib/source/library/lux/control/concurrency/async.lux +++ b/stdlib/source/library/lux/control/concurrency/async.lux @@ -40,7 +40,7 @@ #.None (do ! - [#let [new [(#.Some value) #.None]] + [.let [new [(#.Some value) #.None]] succeeded? (atom.compare_and_swap old new async)] (if succeeded? (do ! @@ -71,7 +71,7 @@ {#.doc (doc "Executes the given function as soon as the async has been resolved.")} (All [a] (-> (-> a (IO Any)) (Async a) (IO Any))) (do {! io.monad} - [#let [async (:representation async)] + [.let [async (:representation async)] (^@ old [_value _observers]) (atom.read async)] (case _value (#.Some value) diff --git a/stdlib/source/library/lux/control/concurrency/atom.lux b/stdlib/source/library/lux/control/concurrency/atom.lux index 138e03e02..9a86f191b 100644 --- a/stdlib/source/library/lux/control/concurrency/atom.lux +++ b/stdlib/source/library/lux/control/concurrency/atom.lux @@ -90,7 +90,7 @@ (loop [_ []] (do io.monad [old (read atom) - #let [new (f old)] + .let [new (f old)] swapped? (..compare_and_swap old new atom)] (if swapped? (in [old new]) diff --git a/stdlib/source/library/lux/control/concurrency/frp.lux b/stdlib/source/library/lux/control/concurrency/frp.lux index 7d0ac6129..14b4013d3 100644 --- a/stdlib/source/library/lux/control/concurrency/frp.lux +++ b/stdlib/source/library/lux/control/concurrency/frp.lux @@ -58,7 +58,7 @@ (loop [_ []] (do {! io.monad} [current (atom.read sink) - #let [[next resolve_next] (:sharing [a] + .let [[next resolve_next] (:sharing [a] (async.Resolver (Maybe [a (Channel a)])) current diff --git a/stdlib/source/library/lux/control/concurrency/semaphore.lux b/stdlib/source/library/lux/control/concurrency/semaphore.lux index ea575915c..f4e094d3b 100644 --- a/stdlib/source/library/lux/control/concurrency/semaphore.lux +++ b/stdlib/source/library/lux/control/concurrency/semaphore.lux @@ -161,7 +161,7 @@ [(def: (<phase> (^:representation barrier)) (-> Barrier (Async Any)) (do async.monad - [#let [limit (refinement.value (get@ #limit barrier)) + [.let [limit (refinement.value (get@ #limit barrier)) goal <goal> [_ count] (io.run (atom.update <update> (get@ #count barrier))) reached? (n.= goal count)]] diff --git a/stdlib/source/library/lux/control/concurrency/stm.lux b/stdlib/source/library/lux/control/concurrency/stm.lux index 183558265..29979e17e 100644 --- a/stdlib/source/library/lux/control/concurrency/stm.lux +++ b/stdlib/source/library/lux/control/concurrency/stm.lux @@ -48,7 +48,7 @@ (def: (write! new_value var) (All [a] (-> a (Var a) (IO Any))) (do {! io.monad} - [#let [var' (:representation var)] + [.let [var' (:representation var)] (^@ old [old_value observers]) (atom.read var') succeeded? (atom.compare_and_swap old [new_value observers] var')] (if succeeded? @@ -70,7 +70,7 @@ {#.doc "Creates a channel that will receive all changes to the value of the given var."} (All [a] (-> (Var a) (IO [(Channel a) (Sink a)]))) (do io.monad - [#let [[channel sink] (frp.channel [])] + [.let [[channel sink] (frp.channel [])] _ (atom.update (function (_ [value observers]) [value (#.Item sink observers)]) (:representation target))] @@ -180,7 +180,7 @@ (All [a] (-> (-> a a) (Var a) (STM [a a]))) (do ..monad [a (..read var) - #let [a' (f a)] + .let [a' (f a)] _ (..write a' var)] (in [a a']))) diff --git a/stdlib/source/library/lux/control/concurrency/thread.lux b/stdlib/source/library/lux/control/concurrency/thread.lux index edfc01f8c..0a2a2c547 100644 --- a/stdlib/source/library/lux/control/concurrency/thread.lux +++ b/stdlib/source/library/lux/control/concurrency/thread.lux @@ -129,7 +129,7 @@ ## Default (do {! io.monad} - [now (\ ! map (|>> instant.to_millis .nat) instant.now) + [now (\ ! map (|>> instant.millis .nat) instant.now) _ (atom.update (|>> (#.Item {#creation now #delay milli_seconds #action action})) @@ -158,8 +158,8 @@ _ (do ! - [now (\ ! map (|>> instant.to_millis .nat) instant.now) - #let [[ready pending] (list.partition (function (_ thread) + [now (\ ! map (|>> instant.millis .nat) instant.now) + .let [[ready pending] (list.partition (function (_ thread) (|> (get@ #creation thread) (n.+ (get@ #delay thread)) (n.<= now))) diff --git a/stdlib/source/library/lux/control/continuation.lux b/stdlib/source/library/lux/control/continuation.lux index e36f3ba69..16f789010 100644 --- a/stdlib/source/library/lux/control/continuation.lux +++ b/stdlib/source/library/lux/control/continuation.lux @@ -94,7 +94,7 @@ z))) (call/cc (function (_ k) (do ..monad - [#let [nexus (function (nexus val) + [.let [nexus (function (nexus val) (k [nexus val]))] _ (k [nexus init])] (in (undefined)))))) diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 65ddd84f1..7515cb9fb 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -57,7 +57,7 @@ then)) (#//.Failure error))))) -(def: #export (otherwise to_do try) +(def: #export (otherwise else try) {#.doc "If no handler could be found to catch the exception, then run a function as a last-resort measure."} (All [a] (-> (-> Text a) (Try a) a)) @@ -66,7 +66,7 @@ output (#//.Failure error) - (to_do error))) + (else error))) (def: #export (return value) {#.doc "A way to lift normal values into the error-handling context."} @@ -106,7 +106,7 @@ (macro.with_gensyms [g!descriptor] (do meta.monad [current_module meta.current_module_name - #let [descriptor ($_ text\compose "{" current_module "." name "}" text.new_line) + .let [descriptor ($_ text\compose "{" current_module "." name "}" text.new_line) g!self (code.local_identifier name)]] (in (list (` (def: (~+ (|export|.format export)) (~ g!self) @@ -116,8 +116,7 @@ {#..label (~ g!descriptor) #..constructor (function ((~ g!self) [(~+ (list\map (get@ #|input|.binding) inputs))]) ((~! text\compose) (~ g!descriptor) - (~ (maybe.else (' "") body))))}))))) - ))) + (~ (maybe.else (' "") body))))})))))))) (def: (report' entries) (-> (List [Text Text]) Text) diff --git a/stdlib/source/library/lux/control/function/mutual.lux b/stdlib/source/library/lux/control/function/mutual.lux index d53249897..e292f19ee 100644 --- a/stdlib/source/library/lux/control/function/mutual.lux +++ b/stdlib/source/library/lux/control/function/mutual.lux @@ -86,7 +86,7 @@ [here_name meta.current_module_name hidden_names (monad.map ! (//.constant (macro.gensym "mutual_function#")) functions) - #let [definitions (list\map (..mutual_definition hidden_names g!context) + .let [definitions (list\map (..mutual_definition hidden_names g!context) (list.zipped/2 hidden_names functions)) context_types (list\map (function (_ mutual) @@ -152,7 +152,7 @@ [here_name meta.current_module_name hidden_names (monad.map ! (//.constant (macro.gensym "mutual_function#")) functions) - #let [definitions (list\map (..mutual_definition hidden_names g!context) + .let [definitions (list\map (..mutual_definition hidden_names g!context) (list.zipped/2 hidden_names (list\map (get@ #mutual) functions))) context_types (list\map (function (_ mutual) diff --git a/stdlib/source/library/lux/control/parser/binary.lux b/stdlib/source/library/lux/control/parser/binary.lux index 7827bd8c0..fd4e1880a 100644 --- a/stdlib/source/library/lux/control/parser/binary.lux +++ b/stdlib/source/library/lux/control/parser/binary.lux @@ -239,7 +239,7 @@ (All [a] (-> (Hash a) (Parser a) (Parser (Set a)))) (do //.monad [raw (..list value) - #let [output (set.of_list hash raw)] + .let [output (set.of_list hash raw)] _ (//.assertion (exception.error ..set_elements_are_not_unique []) (n.= (list.size raw) (set.size output)))] diff --git a/stdlib/source/library/lux/control/parser/json.lux b/stdlib/source/library/lux/control/parser/json.lux index 741933205..74747195d 100644 --- a/stdlib/source/library/lux/control/parser/json.lux +++ b/stdlib/source/library/lux/control/parser/json.lux @@ -132,7 +132,7 @@ [head ..any] (case head (#/.Array values) - (case (//.run parser (row.to_list values)) + (case (//.run parser (row.list values)) (#try.Failure error) (//.failure error) diff --git a/stdlib/source/library/lux/control/parser/text.lux b/stdlib/source/library/lux/control/parser/text.lux index 1806d77e4..fcabe68ab 100644 --- a/stdlib/source/library/lux/control/parser/text.lux +++ b/stdlib/source/library/lux/control/parser/text.lux @@ -174,7 +174,7 @@ (-> Nat Nat (Parser Text)) (do //.monad [char any - #let [char' (maybe.assume (/.char 0 char))] + .let [char' (maybe.assume (/.char 0 char))] _ (//.assertion ($_ /\compose "Character is not within range: " (/.of_char bottom) "-" (/.of_char top)) (.and (n.>= bottom char') (n.<= top char')))] diff --git a/stdlib/source/library/lux/control/parser/type.lux b/stdlib/source/library/lux/control/parser/type.lux index 9c4dae7ee..0e07c633c 100644 --- a/stdlib/source/library/lux/control/parser/type.lux +++ b/stdlib/source/library/lux/control/parser/type.lux @@ -179,7 +179,7 @@ (Parser [Nat Type]) (do //.monad [headT any - #let [[num_arg bodyT] (type.flat_univ_q (type.anonymous headT))]] + .let [[num_arg bodyT] (type.flat_univ_q (type.anonymous headT))]] (if (n.= 0 num_arg) (//.failure (exception.error ..not_polymorphic headT)) (in [num_arg bodyT])))) @@ -191,7 +191,7 @@ funcI (\ ! map dictionary.size ..env) [num_args non_poly] (local (list headT) ..polymorphic') env ..env - #let [funcL (label funcI) + .let [funcL (label funcI) [all_varsL env'] (loop [current_arg 0 env' env all_varsL (: (List Code) (list))] @@ -226,7 +226,7 @@ (All [i o] (-> (Parser i) (Parser o) (Parser [i o]))) (do //.monad [headT any - #let [[inputsT outputT] (type.flat_function (type.anonymous headT))]] + .let [[inputsT outputT] (type.flat_function (type.anonymous headT))]] (if (n.> 0 (list.size inputsT)) (//.and (local inputsT in_poly) (local (list outputT) out_poly)) @@ -237,7 +237,7 @@ (All [a] (-> (Parser a) (Parser a))) (do //.monad [headT any - #let [[funcT paramsT] (type.flat_application (type.anonymous headT))]] + .let [[funcT paramsT] (type.flat_application (type.anonymous headT))]] (if (n.= 0 (list.size paramsT)) (//.failure (exception.error ..not_application headT)) (..local (#.Item funcT paramsT) poly)))) diff --git a/stdlib/source/library/lux/control/pipe.lux b/stdlib/source/library/lux/control/pipe.lux index 5f40fc055..8f36f8a41 100644 --- a/stdlib/source/library/lux/control/pipe.lux +++ b/stdlib/source/library/lux/control/pipe.lux @@ -123,7 +123,7 @@ [step (list.reversed prev_steps)] (list g!temp (` (|> (~ g!temp) (~+ step)))))] (in (list (` ((~! do) (~ monad) - [(~' #let) [(~ g!temp) (~ prev)] + [.let [(~ g!temp) (~ prev)] (~+ step_bindings)] (|> (~ g!temp) (~+ last_step))))))) diff --git a/stdlib/source/library/lux/control/security/capability.lux b/stdlib/source/library/lux/control/security/capability.lux index 14461791f..b58468911 100644 --- a/stdlib/source/library/lux/control/security/capability.lux +++ b/stdlib/source/library/lux/control/security/capability.lux @@ -60,10 +60,10 @@ (is? left right)))} (do {! meta.monad} [this_module meta.current_module_name - #let [[name vars] declaration] + .let [[name vars] declaration] g!brand (\ ! map (|>> %.code code.text) (macro.gensym (format (%.name [this_module name])))) - #let [capability (` (..Capability (.primitive (~ g!brand)) (~ input) (~ output)))]] + .let [capability (` (..Capability (.primitive (~ g!brand)) (~ input) (~ output)))]] (in (list (` (type: (~+ (|export|.format export)) (~ (|declaration|.format declaration)) (~ capability))) diff --git a/stdlib/source/library/lux/control/security/policy.lux b/stdlib/source/library/lux/control/security/policy.lux index 05b05cf5f..dc5a07e0d 100644 --- a/stdlib/source/library/lux/control/security/policy.lux +++ b/stdlib/source/library/lux/control/security/policy.lux @@ -77,19 +77,19 @@ (scope label)))) (context ..privilege)) - (def: (decorate constructor) + (def: (of_policy constructor) (-> Type Type) (type (All [brand label] (constructor (All [value] (Policy brand value label)))))) (implementation: #export functor - (:~ (..decorate Functor)) + (:~ (..of_policy Functor)) (def: (map f fa) (|> fa :representation f :abstraction))) (implementation: #export apply - (:~ (..decorate Apply)) + (:~ (..of_policy Apply)) (def: &functor ..functor) @@ -97,7 +97,7 @@ (:abstraction ((:representation ff) (:representation fa))))) (implementation: #export monad - (:~ (..decorate Monad)) + (:~ (..of_policy Monad)) (def: &functor ..functor) (def: in (|>> :abstraction)) diff --git a/stdlib/source/library/lux/data/collection/array.lux b/stdlib/source/library/lux/data/collection/array.lux index e823c4212..6811c2234 100644 --- a/stdlib/source/library/lux/data/collection/array.lux +++ b/stdlib/source/library/lux/data/collection/array.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- list) ["@" target] [abstract [monoid (#+ Monoid)] @@ -288,7 +288,7 @@ Nat (dec 0)) -(def: #export (to_list array) +(def: #export (list array) {#.doc (doc "Yields a list with every non-empty item in the array.")} (All [a] (-> (Array a) (List a))) (loop [idx (dec (size array)) @@ -306,8 +306,8 @@ #.None output))))) -(def: #export (to_list' default array) - {#.doc (doc "Like 'to_list', but uses the 'default' value when encountering an empty cell in the array.")} +(def: #export (list' default array) + {#.doc (doc "Like 'list', but uses the 'default' value when encountering an empty cell in the array.")} (All [a] (-> a (Array a) (List a))) (loop [idx (dec (size array)) output #.End] diff --git a/stdlib/source/library/lux/data/collection/dictionary.lux b/stdlib/source/library/lux/data/collection/dictionary.lux index 923d64c42..771bdc551 100644 --- a/stdlib/source/library/lux/data/collection/dictionary.lux +++ b/stdlib/source/library/lux/data/collection/dictionary.lux @@ -179,11 +179,11 @@ (i64.left_shifted index 1)) ## The bit-position within a base that a given hash-code would have. -(def: (bit_position level hash) +(def: (level_bit_position level hash) (-> Level Hash_Code Bit_Position) (to_bit_position (level_index level hash))) -(def: (bit_position_is_set? bit bitmap) +(def: (with_bit_position? bit bitmap) (-> Bit_Position Bit_Map Bit) (|> bitmap (i64.and bit) @@ -195,11 +195,11 @@ (-> Bit_Position Bit_Map Bit) n.=) -(def: (set_bit_position bit bitmap) +(def: (with_bit_position bit bitmap) (-> Bit_Position Bit_Map Bit_Map) (i64.or bit bitmap)) -(def: unset_bit_position +(def: without_bit_position (-> Bit_Position Bit_Map Bit_Map) i64.xor) @@ -241,7 +241,7 @@ (#.Some sub_node) (if (n.= except_idx idx) [insertion_idx node] [(inc insertion_idx) - [(set_bit_position (to_bit_position idx) bitmap) + [(with_bit_position (to_bit_position idx) bitmap) (array.write! insertion_idx (#.Left sub_node) base)]]) ))) [0 [clean_bitmap @@ -261,8 +261,8 @@ Bit_Map (Base k v) (Array (Node k v)))) (product.right (list\fold (function (_ hierarchy_idx (^@ default [base_idx h_array])) - (if (bit_position_is_set? (to_bit_position hierarchy_idx) - bitmap) + (if (with_bit_position? (to_bit_position hierarchy_idx) + bitmap) [(inc base_idx) (case (array.read base_idx base) (#.Some (#.Left sub_node)) @@ -312,8 +312,8 @@ ## For #Base nodes, check if the corresponding Bit_Position has ## already been used. (#Base bitmap base) - (let [bit (bit_position level hash)] - (if (bit_position_is_set? bit bitmap) + (let [bit (level_bit_position level hash)] + (if (with_bit_position? bit bitmap) ## If so... (let [idx (base_index bit bitmap)] (case (array.read idx base) @@ -364,7 +364,7 @@ (put' (level_up level) hash key val key_hash empty_node)))) ## Otherwise, just resize the #Base node to accommodate the ## new KV-pair. - (#Base (set_bit_position bit bitmap) + (#Base (with_bit_position bit bitmap) (insert! (base_index bit bitmap) (#.Right [key val]) base)))))) ## For #Collisions nodes, compare the hashes. @@ -383,7 +383,7 @@ (#Collisions _hash (insert! (array.size _colls) [key val] _colls))) ## If the hashes are not equal, create a new #Base node that ## contains the old #Collisions node, plus the new KV-pair. - (|> (#Base (bit_position level _hash) + (|> (#Base (level_bit_position level _hash) (|> (array.empty 1) (array.write! 0 (#.Left node)))) (put' level hash key val key_hash))) @@ -422,8 +422,8 @@ ## For #Base nodes, check whether the Bit_Position is set. (#Base bitmap base) - (let [bit (bit_position level hash)] - (if (bit_position_is_set? bit bitmap) + (let [bit (level_bit_position level hash)] + (if (with_bit_position? bit bitmap) (let [idx (base_index bit bitmap)] (case (array.read idx base) ## If set, check if it's a sub_node, and remove the KV @@ -442,7 +442,7 @@ empty_node ## But if not, then just unset the position and ## remove the node. - (#Base (unset_bit_position bit bitmap) + (#Base (without_bit_position bit bitmap) (remove! idx base))) ## But, if it did not come out empty, then the ## position is kept, and the node gets updated. @@ -454,7 +454,7 @@ ## Check if the keys match. (if (\ key_hash = key key') ## If so, remove the KV-pair and unset the Bit_Position. - (#Base (unset_bit_position bit bitmap) + (#Base (without_bit_position bit bitmap) (remove! idx base)) ## Otherwise, there's nothing to remove. node) @@ -492,8 +492,8 @@ ## For #Base nodes, check the leaves, and recursively check the branches. (#Base bitmap base) - (let [bit (bit_position level hash)] - (if (bit_position_is_set? bit bitmap) + (let [bit (level_bit_position level hash)] + (if (with_bit_position? bit bitmap) (case (array.read (base_index bit bitmap) base) (#.Some (#.Left sub_node)) (get' (level_up level) hash key key_hash sub_node) diff --git a/stdlib/source/library/lux/data/collection/list.lux b/stdlib/source/library/lux/data/collection/list.lux index 5b20c22fb..35aeaafe4 100644 --- a/stdlib/source/library/lux/data/collection/list.lux +++ b/stdlib/source/library/lux/data/collection/list.lux @@ -622,3 +622,18 @@ (#.Item x xs') (#.Item [idx x] (recur (inc idx) xs'))))) + +(macro: #export (when tokens state) + {#.doc (doc "Can be used as a guard in (co)monadic be/do expressions." + (do monad + [value (do_something 1 2 3) + ..when (passes_test? value)] + (do_something_else 4 5 6)))} + (case tokens + (^ (.list test then)) + (#.Right [state (.list (` (.if (~ test) + (~ then) + (.list))))]) + + _ + (#.Left "Wrong syntax for when"))) diff --git a/stdlib/source/library/lux/data/collection/queue.lux b/stdlib/source/library/lux/data/collection/queue.lux index 0fa870a0c..0c6a24f88 100644 --- a/stdlib/source/library/lux/data/collection/queue.lux +++ b/stdlib/source/library/lux/data/collection/queue.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- list) [abstract [equivalence (#+ Equivalence)] [functor (#+ Functor)]] @@ -18,15 +18,15 @@ (def: #export empty Queue - {#front (list) - #rear (list)}) + {#front (.list) + #rear (.list)}) (def: #export (of_list entries) (All [a] (-> (List a) (Queue a))) {#front entries - #rear (list)}) + #rear (.list)}) -(def: #export (to_list queue) +(def: #export (list queue) (All [a] (-> (Queue a) (List a))) (let [(^slots [#front #rear]) queue] (list\compose front (list.reversed rear)))) @@ -56,17 +56,17 @@ (All [a] (-> (Queue a) (Queue a))) (case (get@ #front queue) ## Empty... - (^ (list)) + (^ (.list)) queue ## Front has dried up... - (^ (list _)) + (^ (.list _)) (|> queue (set@ #front (list.reversed (get@ #rear queue))) - (set@ #rear (list))) + (set@ #rear (.list))) ## Consume front! - (^ (list& _ front')) + (^ (.list& _ front')) (|> queue (set@ #front front')))) @@ -74,7 +74,7 @@ (All [a] (-> a (Queue a) (Queue a))) (case (get@ #front queue) #.End - (set@ #front (list val) queue) + (set@ #front (.list val) queue) _ (update@ #rear (|>> (#.Item val)) queue))) @@ -84,8 +84,8 @@ (def: (= reference subject) (\ (list.equivalence super) = - (..to_list reference) - (..to_list subject)))) + (..list reference) + (..list subject)))) (implementation: #export functor (Functor Queue) diff --git a/stdlib/source/library/lux/data/collection/queue/priority.lux b/stdlib/source/library/lux/data/collection/queue/priority.lux index 8f0a788fc..698bb57ac 100644 --- a/stdlib/source/library/lux/data/collection/queue/priority.lux +++ b/stdlib/source/library/lux/data/collection/queue/priority.lux @@ -3,7 +3,7 @@ [lux #* [abstract [equivalence (#+ Equivalence)] - [monad (#+ do Monad)]] + [monad (#+ do)]] [data ["." maybe] [collection @@ -86,7 +86,7 @@ (:abstraction (do maybe.monad [tree (:representation queue) - #let [highest_priority (tree.tag tree)]] + .let [highest_priority (tree.tag tree)]] (loop [node tree] (case (tree.root node) (0 #0 reference) diff --git a/stdlib/source/library/lux/data/collection/row.lux b/stdlib/source/library/lux/data/collection/row.lux index 1af5037ce..20c6c2cea 100644 --- a/stdlib/source/library/lux/data/collection/row.lux +++ b/stdlib/source/library/lux/data/collection/row.lux @@ -3,7 +3,7 @@ ## https://hypirion.com/musings/understanding-persistent-vector-pt-3 (.module: [library - [lux #* + [lux (#- list) ["@" target] [abstract [functor (#+ Functor)] @@ -72,9 +72,9 @@ (-> Index Index) (i64.and branch_idx_mask)) -(def: (new_hierarchy _) +(def: (empty_hierarchy _) (All [a] (-> Any (Hierarchy a))) - (array.empty full_node_size)) + (array.empty ..full_node_size)) (def: (tail_off row_size) (-> Nat Nat) @@ -84,20 +84,20 @@ (i64.right_shifted branching_exponent) (i64.left_shifted branching_exponent)))) -(def: (new_path level tail) +(def: (path level tail) (All [a] (-> Level (Base a) (Node a))) (if (n.= 0 level) (#Base tail) - (|> (new_hierarchy []) - (array.write! 0 (new_path (level_down level) tail)) + (|> (empty_hierarchy []) + (array.write! 0 (path (level_down level) tail)) #Hierarchy))) -(def: (new_tail singleton) +(def: (tail singleton) (All [a] (-> a (Base a))) (|> (array.empty 1) (array.write! 0 singleton))) -(def: (push_tail size level tail parent) +(def: (with_tail size level tail parent) (All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a))) (let [sub_idx (branch_idx (i64.right_shifted level (dec size))) ## If we're currently on a bottom node @@ -108,10 +108,10 @@ (case (array.read sub_idx parent) ## If so, set the path to the tail #.None - (new_path (level_down level) tail) + (..path (level_down level) tail) ## If not, push the tail onto the sub_node. (#.Some (#Hierarchy sub_node)) - (#Hierarchy (push_tail size (level_down level) tail sub_node)) + (#Hierarchy (with_tail size (level_down level) tail sub_node)) _ (undefined)) @@ -119,7 +119,7 @@ (|> (array.clone parent) (array.write! sub_idx sub_node)))) -(def: (expand_tail val tail) +(def: (expanded_tail val tail) (All [a] (-> a (Base a) (Base a))) (let [tail_size (array.size tail)] (|> (array.empty (inc tail_size)) @@ -144,7 +144,7 @@ _ (undefined)))) -(def: (pop_tail size level hierarchy) +(def: (without_tail size level hierarchy) (All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a)))) (let [sub_idx (branch_idx (i64.right_shifted level (n.- 2 size)))] (cond (n.= 0 sub_idx) @@ -155,7 +155,7 @@ [base|hierarchy (array.read sub_idx hierarchy) sub (case base|hierarchy (#Hierarchy sub) - (pop_tail size (level_down level) sub) + (without_tail size (level_down level) sub) (#Base _) (undefined))] @@ -169,17 +169,17 @@ #.Some) ))) -(def: (to_list' node) +(def: (list' node) (All [a] (-> (Node a) (List a))) (case node (#Base base) - (array.to_list base) + (array.list base) (#Hierarchy hierarchy) (|> hierarchy - array.to_list + array.list list.reversed - (list\fold (function (_ sub acc) (list\compose (to_list' sub) acc)) + (list\fold (function (_ sub acc) (list\compose (list' sub) acc)) #.End)))) (type: #export (Row a) @@ -193,7 +193,7 @@ Row {#level (level_up root_level) #size 0 - #root (array.empty full_node_size) + #root (empty_hierarchy []) #tail (array.empty 0)}) (def: #export (size row) @@ -208,7 +208,7 @@ ## If so, append to it. (|> row (update@ #size inc) - (update@ #tail (expand_tail val))) + (update@ #tail (..expanded_tail val))) ## Otherwise, push tail into the tree ## -------------------------------------------------------- ## Will the root experience an overflow with this addition? @@ -219,18 +219,18 @@ (|> row (set@ #root (|> (for {@.old (: (Hierarchy (:parameter 0)) - (new_hierarchy []))} - (new_hierarchy [])) + (empty_hierarchy []))} + (empty_hierarchy [])) (array.write! 0 (#Hierarchy (get@ #root row))) - (array.write! 1 (new_path (get@ #level row) (get@ #tail row))))) + (array.write! 1 (..path (get@ #level row) (get@ #tail row))))) (update@ #level level_up)) ## Otherwise, just push the current tail onto the root. (|> row - (update@ #root (push_tail row_size (get@ #level row) (get@ #tail row))))) + (update@ #root (..with_tail row_size (get@ #level row) (get@ #tail row))))) ## Finally, update the size of the row and grow a new ## tail with the new element as it's sole member. (update@ #size inc) - (set@ #tail (new_tail val))) + (set@ #tail (..tail val))) ))) (exception: incorrect_row_structure) @@ -319,10 +319,10 @@ (maybe.assume (do maybe.monad [new_tail (base_for (n.- 2 row_size) row) - #let [[level' root'] (let [init_level (get@ #level row)] + .let [[level' root'] (let [init_level (get@ #level row)] (loop [level init_level - root (maybe.else (new_hierarchy []) - (pop_tail row_size init_level (get@ #root row)))] + root (maybe.else (empty_hierarchy []) + (without_tail row_size init_level (get@ #root row)))] (if (n.> branching_exponent level) (case [(array.read 1 root) (array.read 0 root)] [#.None (#.Some (#Hierarchy sub_node))] @@ -341,10 +341,10 @@ (set@ #tail new_tail)))))) )) -(def: #export (to_list row) +(def: #export (list row) (All [a] (-> (Row a) (List a))) - (list\compose (to_list' (#Hierarchy (get@ #root row))) - (to_list' (#Base (get@ #tail row))))) + (list\compose (list' (#Hierarchy (get@ #root row))) + (list' (#Base (get@ #tail row))))) (def: #export of_list (All [a] (-> (List a) (Row a))) @@ -352,7 +352,7 @@ (def: #export (member? a/Equivalence row val) (All [a] (-> (Equivalence a) (Row a) a Bit)) - (list.member? a/Equivalence (to_list row) val)) + (list.member? a/Equivalence (list row) val)) (def: #export empty? (All [a] (-> (Row a) Bit)) @@ -361,7 +361,7 @@ (syntax: #export (row {elems (p.some s.any)}) {#.doc (doc "Row literals." (row 12 34 56 78 90))} - (in (list (` (..of_list (list (~+ elems))))))) + (in (.list (` (..of_list (.list (~+ elems))))))) (implementation: (node_equivalence Equivalence<a>) (All [a] (-> (Equivalence a) (Equivalence (Node a)))) @@ -418,7 +418,7 @@ (def: identity ..empty) (def: (compose xs ys) - (list\fold add xs (..to_list ys)))) + (list\fold add xs (..list ys)))) (implementation: node_functor (Functor Node) @@ -467,7 +467,7 @@ (def: #export reversed (All [a] (-> (Row a) (Row a))) - (|>> ..to_list + (|>> ..list list.reversed (list\fold add ..empty))) diff --git a/stdlib/source/library/lux/data/collection/set.lux b/stdlib/source/library/lux/data/collection/set.lux index d6436be3b..64438517f 100644 --- a/stdlib/source/library/lux/data/collection/set.lux +++ b/stdlib/source/library/lux/data/collection/set.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- list) [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)] @@ -44,7 +44,7 @@ (All [a] (-> (Set a) a Bit)) //.key?) -(def: #export to_list +(def: #export list (All [a] (-> (Set a) (List a))) //.keys) @@ -54,7 +54,7 @@ (def: #export (difference sub base) (All [a] (-> (Set a) (Set a) (Set a))) - (list\fold ..remove base (..to_list sub))) + (list\fold ..remove base (..list sub))) (def: #export (intersection filter base) (All [a] (-> (Set a) (Set a) (Set a))) @@ -68,7 +68,7 @@ (and (n.= (..size reference) (..size sample)) (list.every? (..member? reference) - (..to_list sample))))) + (..list sample))))) (implementation: #export hash (All [a] (Hash (Set a))) @@ -77,7 +77,7 @@ (def: (hash set) (|> set - ..to_list + ..list (\ (list.hash (..member_hash set)) hash)))) (implementation: #export (monoid hash) @@ -96,7 +96,7 @@ (def: #export (sub? super sub) (All [a] (-> (Set a) (Set a) Bit)) - (list.every? (..member? super) (..to_list sub))) + (list.every? (..member? super) (..list sub))) (def: #export (super? sub super) (All [a] (-> (Set a) (Set a) Bit)) diff --git a/stdlib/source/library/lux/data/collection/set/multi.lux b/stdlib/source/library/lux/data/collection/set/multi.lux index df4db9a85..9d746ae52 100644 --- a/stdlib/source/library/lux/data/collection/set/multi.lux +++ b/stdlib/source/library/lux/data/collection/set/multi.lux @@ -1,7 +1,7 @@ ## https://en.wikipedia.org/wiki/Multiset (.module: [library - [lux #* + [lux (#- list) [abstract [equivalence (#+ Equivalence)] [hash (#+ Hash)]] @@ -59,7 +59,7 @@ (All [a] (-> (Set a) a Nat)) (|> set :representation (dictionary.get elem) (maybe.else 0))) - (def: #export to_list + (def: #export list (All [a] (-> (Set a) (List a))) (|>> :representation dictionary.entries @@ -155,7 +155,7 @@ (def: #export (of_set subject) (All [a] (-> (//.Set a) (Set a))) (..of_list (//.member_hash subject) - (//.to_list subject))) + (//.list subject))) (def: #export super? {#.doc (doc "Is 'subject' a super-set of 'reference'?")} diff --git a/stdlib/source/library/lux/data/collection/set/ordered.lux b/stdlib/source/library/lux/data/collection/set/ordered.lux index d0916508f..97e32646c 100644 --- a/stdlib/source/library/lux/data/collection/set/ordered.lux +++ b/stdlib/source/library/lux/data/collection/set/ordered.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- list) [abstract [equivalence (#+ Equivalence)] [order (#+ Order)]] @@ -44,7 +44,7 @@ (All [a] (-> a (Set a) (Set a))) (|> set :representation (/.remove elem) :abstraction)) - (def: #export to_list + (def: #export list (All [a] (-> (Set a) (List a))) (|>> :representation /.keys)) @@ -54,17 +54,17 @@ (def: #export (union left right) (All [a] (-> (Set a) (Set a) (Set a))) - (list\fold ..add right (..to_list left))) + (list\fold ..add right (..list left))) (def: #export (intersection left right) (All [a] (-> (Set a) (Set a) (Set a))) - (|> (..to_list right) + (|> (..list right) (list.only (..member? left)) (..of_list (get@ #/.&order (:representation right))))) (def: #export (difference param subject) (All [a] (-> (Set a) (Set a) (Set a))) - (|> (..to_list subject) + (|> (..list subject) (list.only (|>> (..member? param) not)) (..of_list (get@ #/.&order (:representation subject))))) @@ -73,14 +73,14 @@ (def: (= reference sample) (\ (list.equivalence (\ (:representation reference) &equivalence)) - = (..to_list reference) (..to_list sample)))) + = (..list reference) (..list sample)))) ) (def: #export (sub? super sub) {#.doc (doc "Is 'sub' a sub-set of 'super'?")} (All [a] (-> (Set a) (Set a) Bit)) (|> sub - ..to_list + ..list (list.every? (..member? super)))) (def: #export (super? sub super) diff --git a/stdlib/source/library/lux/data/color.lux b/stdlib/source/library/lux/data/color.lux index ad79c9fd8..433dd9bc3 100644 --- a/stdlib/source/library/lux/data/color.lux +++ b/stdlib/source/library/lux/data/color.lux @@ -27,8 +27,8 @@ [type abstract]]]) -(def: rgb 256) -(def: top (dec rgb)) +(def: rgb_limit 256) +(def: top (dec rgb_limit)) (def: rgb_factor (|> top .int int.frac)) @@ -69,11 +69,11 @@ (def: #export (of_rgb [red green blue]) (-> RGB Color) - (:abstraction {#red (n.% ..rgb red) - #green (n.% ..rgb green) - #blue (n.% ..rgb blue)})) + (:abstraction {#red (n.% ..rgb_limit red) + #green (n.% ..rgb_limit green) + #blue (n.% ..rgb_limit blue)})) - (def: #export to_rgb + (def: #export rgb (-> Color RGB) (|>> :representation)) @@ -148,9 +148,9 @@ #blue (n.min lB rB)})))) ) -(def: #export (to_hsl color) +(def: #export (hsl color) (-> Color HSL) - (let [[red green blue] (to_rgb color) + (let [[red green blue] (rgb color) red (..down red) green (..down green) blue (..down blue) @@ -183,24 +183,24 @@ saturation luminance])))) -(def: (hue_to_rgb p q t) - (-> Frac Frac Frac Frac) +(def: (hue_rgb p q t) + (-> Frac Frac Frac Nat) (let [t (cond (f.< +0.0 t) (f.+ +1.0 t) (f.> +1.0 t) (f.- +1.0 t) ## else t) f2/3 (f./ +3.0 +2.0)] - (cond (f.< (f./ +6.0 +1.0) t) - (|> q (f.- p) (f.* +6.0) (f.* t) (f.+ p)) - - (f.< (f./ +2.0 +1.0) t) - q - - (f.< f2/3 t) - (|> q (f.- p) (f.* (|> f2/3 (f.- t))) (f.* +6.0) (f.+ p)) - - ## else - p))) + (..up (cond (f.< (f./ +6.0 +1.0) t) + (|> q (f.- p) (f.* +6.0) (f.* t) (f.+ p)) + + (f.< (f./ +2.0 +1.0) t) + q + + (f.< f2/3 t) + (|> q (f.- p) (f.* (|> f2/3 (f.- t))) (f.* +6.0) (f.+ p)) + + ## else + p)))) (def: #export (of_hsl [hue saturation luminance]) (-> HSL Color) @@ -216,13 +216,13 @@ (|> luminance (f.+ saturation) (f.- (f.* saturation luminance)))) p (|> luminance (f.* +2.0) (f.- q)) third (|> +1.0 (f./ +3.0))] - (of_rgb {#red (..up (|> hue (f.+ third) (hue_to_rgb p q))) - #green (..up (|> hue (hue_to_rgb p q))) - #blue (..up (|> hue (f.- third) (hue_to_rgb p q)))})))) + (of_rgb {#red (|> hue (f.+ third) (hue_rgb p q)) + #green (|> hue (hue_rgb p q)) + #blue (|> hue (f.- third) (hue_rgb p q))})))) -(def: #export (to_hsb color) +(def: #export (hsb color) (-> Color HSB) - (let [[red green blue] (to_rgb color) + (let [[red green blue] (rgb color) red (..down red) green (..down green) blue (..down blue) @@ -269,9 +269,9 @@ #green (..up green) #blue (..up blue)}))) -(def: #export (to_cmyk color) +(def: #export (cmyk color) (-> Color CMYK) - (let [[red green blue] (to_rgb color) + (let [[red green blue] (rgb color) red (..down red) green (..down green) blue (..down blue) @@ -324,8 +324,8 @@ (f.+ (|> end .int int.frac (f.* dE))) f.int .nat))) - [redS greenS blueS] (to_rgb start) - [redE greenE blueE] (to_rgb end)] + [redS greenS blueS] (rgb start) + [redE greenE blueE] (rgb end)] (of_rgb {#red (interpolated' redE redS) #green (interpolated' greenE greenS) #blue (interpolated' blueE blueS)}))) @@ -342,7 +342,7 @@ (template [<op> <name>] [(def: #export (<name> ratio color) (-> Frac Color Color) - (let [[hue saturation luminance] (to_hsl color)] + (let [[hue saturation luminance] (hsl color)] (of_hsl [hue (|> saturation (f.* (|> +1.0 (<op> (..normal ratio)))) @@ -355,7 +355,7 @@ (def: #export (gray_scale color) (-> Color Color) - (let [[_ _ luminance] (to_hsl color)] + (let [[_ _ luminance] (hsl color)] (of_hsl [+0.0 +0.0 luminance]))) @@ -369,7 +369,7 @@ [(`` (def: #export (<name> color) (~~ (..color_scheme_documentation <name>)) (-> Color [Color Color Color]) - (let [[hue saturation luminance] (to_hsl color)] + (let [[hue saturation luminance] (hsl color)] [color (of_hsl [(|> hue (f.+ <1>) ..normal) saturation @@ -387,7 +387,7 @@ [(`` (def: #export (<name> color) (~~ (..color_scheme_documentation <name>)) (-> Color [Color Color Color Color]) - (let [[hue saturation luminance] (to_hsb color)] + (let [[hue saturation luminance] (hsb color)] [color (of_hsb [(|> hue (f.+ <1>) ..normal) saturation @@ -417,7 +417,7 @@ (`` (def: #export (analogous spread variations color) (~~ (..palette_documentation analogous)) Palette - (let [[hue saturation brightness] (to_hsb color) + (let [[hue saturation brightness] (hsb color) spread (..normal spread)] (list\map (function (_ idx) (of_hsb [(|> idx inc .int int.frac (f.* spread) (f.+ hue) ..normal) @@ -428,7 +428,7 @@ (`` (def: #export (monochromatic spread variations color) (~~ (..palette_documentation monochromatic)) Palette - (let [[hue saturation brightness] (to_hsb color) + (let [[hue saturation brightness] (hsb color) spread (..normal spread)] (|> (list.indices variations) (list\map (|>> inc .int int.frac diff --git a/stdlib/source/library/lux/data/format/binary.lux b/stdlib/source/library/lux/data/format/binary.lux index b1279b292..918119cb2 100644 --- a/stdlib/source/library/lux/data/format/binary.lux +++ b/stdlib/source/library/lux/data/format/binary.lux @@ -133,7 +133,7 @@ (def: #export frac (Writer Frac) - (|>> frac.to_bits ..bits/64)) + (|>> frac.bits ..bits/64)) (def: #export (segment size) {#.doc (doc "Writes at most 'size' bytes of an input binary blob.")} @@ -192,7 +192,7 @@ original_count) value (if (n.= original_count capped_count) value - (|> value row.to_list (list.take capped_count) row.of_list)) + (|> value row.list (list.take capped_count) row.of_list)) (^open "specification\.") ..monoid [size mutation] (|> value (row\map valueW) @@ -225,7 +225,7 @@ (def: #export (set value) (All [a] (-> (Writer a) (Writer (Set a)))) - (|>> set.to_list (..list value))) + (|>> set.list (..list value))) (def: #export name (Writer Name) diff --git a/stdlib/source/library/lux/data/format/css/value.lux b/stdlib/source/library/lux/data/format/css/value.lux index cff3affb0..6dbf1c3f4 100644 --- a/stdlib/source/library/lux/data/format/css/value.lux +++ b/stdlib/source/library/lux/data/format/css/value.lux @@ -820,7 +820,7 @@ (def: #export (rgb color) (-> color.Color (Value Color)) - (let [[red green blue] (color.to_rgb color)] + (let [[red green blue] (color.rgb color)] (..apply "rgb" (list (%.nat red) (%.nat green) (%.nat blue))))) @@ -828,7 +828,7 @@ (def: #export (rgba pigment) (-> color.Pigment (Value Color)) (let [(^slots [#color.color #color.alpha]) pigment - [red green blue] (color.to_rgb color)] + [red green blue] (color.rgb color)] (..apply "rgba" (list (%.nat red) (%.nat green) (%.nat blue) @@ -946,7 +946,9 @@ (:abstraction (format (%.nat (n.% ..degree_limit value)) "deg"))) (template [<degree> <name>] - [(def: #export <name> Angle (..degree <degree>))] + [(def: #export <name> + Angle + (..degree <degree>))] [000 to_top] [090 to_right] diff --git a/stdlib/source/library/lux/data/format/json.lux b/stdlib/source/library/lux/data/format/json.lux index cc186e849..60bcfd107 100644 --- a/stdlib/source/library/lux/data/format/json.lux +++ b/stdlib/source/library/lux/data/format/json.lux @@ -254,7 +254,7 @@ (def: (array_format format) (-> (-> JSON Text) (-> Array Text)) (|>> (row\map format) - row.to_list + row.list (text.join_with ..value_separator) (text.enclosed [..array_start ..array_end]))) diff --git a/stdlib/source/library/lux/data/format/tar.lux b/stdlib/source/library/lux/data/format/tar.lux index 1f4f71967..1f1451790 100644 --- a/stdlib/source/library/lux/data/format/tar.lux +++ b/stdlib/source/library/lux/data/format/tar.lux @@ -276,7 +276,7 @@ (do <>.monad [string (<binary>.segment <size>) end <binary>.bits/8 - #let [expected (`` (char (~~ (static ..null))))] + .let [expected (`` (char (~~ (static ..null))))] _ (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end))] (<>.lift @@ -318,7 +318,7 @@ (do <>.monad [string (<binary>.segment ..magic_size) end <binary>.bits/8 - #let [expected (`` (char (~~ (static ..null))))] + .let [expected (`` (char (~~ (static ..null))))] _ (<>.assertion (exception.error ..wrong_character [expected end]) (n.= expected end))] (<>.lift @@ -800,7 +800,7 @@ [header ..header_parser _ (<>.assertion (exception.error ..wrong_link_flag [expected (get@ #link_flag header)]) (is? expected (get@ #link_flag header))) - #let [size (get@ #size header) + .let [size (get@ #size header) rounded_size (..rounded_content_size size)] content (<binary>.segment (..from_big size)) content (<>.lift (..content content)) @@ -811,7 +811,7 @@ ..from_big .int duration.of_millis - (duration.up (|> duration.second duration.to_millis .nat)) + (duration.up (|> duration.second duration.millis .nat)) instant.absolute) (get@ #mode header) {#user {#name (get@ #user_name header) diff --git a/stdlib/source/library/lux/data/format/xml.lux b/stdlib/source/library/lux/data/format/xml.lux index d065f1def..843a35c91 100644 --- a/stdlib/source/library/lux/data/format/xml.lux +++ b/stdlib/source/library/lux/data/format/xml.lux @@ -172,7 +172,7 @@ [_ (<text>.this "<") tag (..spaced^ tag^) attrs (..spaced^ attrs^) - #let [no_children^ ($_ <>.either + .let [no_children^ ($_ <>.either (do <>.monad [_ (<text>.this "/>")] (in (#Node tag attrs (list)))) @@ -197,10 +197,6 @@ (<>.before (<>.some ..null^)) (<>.after (<>.maybe ..xml_header^)))) -(def: read - (-> Text (Try XML)) - (<text>.run xml^)) - (def: (sanitize_value input) (-> Text Text) (|> input @@ -222,14 +218,6 @@ (-> Attribute Text) ..tag) -(def: (write_attrs attrs) - (-> Attrs Text) - (|> attrs - dictionary.entries - (list\map (function (_ [key value]) - ($_ text\compose (..attribute key) "=" text.double_quote (sanitize_value value) text.double_quote))) - (text.join_with " "))) - (def: xml_header Text (let [quote (: (-> Text Text) @@ -241,45 +229,51 @@ " encoding=" (quote "UTF-8") "?>"))) -(def: (write input) - (-> XML Text) - ($_ text\compose - ..xml_header text.new_line - (loop [prefix "" - input input] - (case input - (#Text value) - (sanitize_value value) - - (^ (#Node xml_tag xml_attrs (list (#Text value)))) - (let [tag (..tag xml_tag) - attrs (if (dictionary.empty? xml_attrs) - "" - ($_ text\compose " " (..write_attrs xml_attrs)))] - ($_ text\compose - prefix "<" tag attrs ">" - (sanitize_value value) - "</" tag ">")) - - (#Node xml_tag xml_attrs xml_children) - (let [tag (..tag xml_tag) - attrs (if (dictionary.empty? xml_attrs) - "" - ($_ text\compose " " (..write_attrs xml_attrs)))] - (if (list.empty? xml_children) - ($_ text\compose prefix "<" tag attrs "/>") - ($_ text\compose prefix "<" tag attrs ">" - (|> xml_children - (list\map (|>> (recur (text\compose prefix text.tab)) (text\compose text.new_line))) - (text.join_with "")) - text.new_line prefix "</" tag ">"))))) - )) - (implementation: #export codec (Codec Text XML) - (def: encode ..write) - (def: decode ..read)) + (def: encode + (let [attributes (: (-> Attrs Text) + (function (_ attrs) + (|> attrs + dictionary.entries + (list\map (function (_ [key value]) + ($_ text\compose (..attribute key) "=" text.double_quote (sanitize_value value) text.double_quote))) + (text.join_with " "))))] + (function (_ input) + ($_ text\compose + ..xml_header text.new_line + (loop [prefix "" + input input] + (case input + (#Text value) + (sanitize_value value) + + (^ (#Node xml_tag xml_attrs (list (#Text value)))) + (let [tag (..tag xml_tag) + attrs (if (dictionary.empty? xml_attrs) + "" + ($_ text\compose " " (attributes xml_attrs)))] + ($_ text\compose + prefix "<" tag attrs ">" + (sanitize_value value) + "</" tag ">")) + + (#Node xml_tag xml_attrs xml_children) + (let [tag (..tag xml_tag) + attrs (if (dictionary.empty? xml_attrs) + "" + ($_ text\compose " " (attributes xml_attrs)))] + (if (list.empty? xml_children) + ($_ text\compose prefix "<" tag attrs "/>") + ($_ text\compose prefix "<" tag attrs ">" + (|> xml_children + (list\map (|>> (recur (text\compose prefix text.tab)) (text\compose text.new_line))) + (text.join_with "")) + text.new_line prefix "</" tag ">"))))) + )))) + (def: decode + (<text>.run ..xml^))) (implementation: #export equivalence (Equivalence XML) diff --git a/stdlib/source/library/lux/data/maybe.lux b/stdlib/source/library/lux/data/maybe.lux index 7d6ac8dfa..bab93295d 100644 --- a/stdlib/source/library/lux/data/maybe.lux +++ b/stdlib/source/library/lux/data/maybe.lux @@ -1,6 +1,6 @@ (.module: [library - [lux #* + [lux (#- list) [abstract [monoid (#+ Monoid)] [equivalence (#+ Equivalence)] @@ -127,14 +127,14 @@ "=>" +20)} (case tokens - (^ (list else maybe)) + (^ (.list else maybe)) (let [g!temp (: Code [location.dummy (#.Identifier ["" ""])])] - (#.Right [state (list (` (case (~ maybe) - (#.Some (~ g!temp)) - (~ g!temp) + (#.Right [state (.list (` (case (~ maybe) + (#.Some (~ g!temp)) + (~ g!temp) - #.None - (~ else))))])) + #.None + (~ else))))])) _ (#.Left "Wrong syntax for else"))) @@ -146,7 +146,7 @@ (All [a] (-> (Maybe a) a)) (|>> (..else (undefined)))) -(def: #export (to_list value) +(def: #export (list value) (All [a] (-> (Maybe a) (List a))) (case value #.None @@ -154,3 +154,18 @@ (#.Some value) (#.Item value #.End))) + +(macro: #export (when tokens state) + {#.doc (doc "Can be used as a guard in (co)monadic be/do expressions." + (do monad + [value (do_something 1 2 3) + ..when (passes_test? value)] + (do_something_else 4 5 6)))} + (case tokens + (^ (.list test then)) + (#.Right [state (.list (` (.if (~ test) + (~ then) + #.None)))]) + + _ + (#.Left "Wrong syntax for when"))) diff --git a/stdlib/source/library/lux/data/text.lux b/stdlib/source/library/lux/data/text.lux index 76ae69e33..f4870ecf5 100644 --- a/stdlib/source/library/lux/data/text.lux +++ b/stdlib/source/library/lux/data/text.lux @@ -66,7 +66,7 @@ (-> Text Text (Maybe Nat)) (index_of' 0 pattern input)) -(def: #export (last_index_of' from part text) +(def: (last_index_of' from part text) (-> Nat Text Text (Maybe Nat)) (loop [from from output (: (Maybe Nat) diff --git a/stdlib/source/library/lux/data/text/regex.lux b/stdlib/source/library/lux/data/text/regex.lux index 0c5d42d02..8c353db1c 100644 --- a/stdlib/source/library/lux/data/text/regex.lux +++ b/stdlib/source/library/lux/data/text/regex.lux @@ -282,7 +282,7 @@ (do <>.monad [parts (<>.many (<>.or (re_complex^ current_module) (re_scoped^ current_module))) - #let [g!total (code.identifier ["" "0total"]) + .let [g!total (code.identifier ["" "0total"]) g!temp (code.identifier ["" "0temp"]) [_ names steps] (list\fold (: (-> (Either Code [Re_Group Code]) [Nat (List Code) (List (List Code))] @@ -293,7 +293,7 @@ [idx names (list& (list g!temp complex - (' #let) (` [(~ g!total) (\ (~! //.monoid) (~' compose) (~ g!total) (~ g!temp))])) + (` .let) (` [(~ g!total) (\ (~! //.monoid) (~' compose) (~ g!total) (~ g!temp))])) steps)] (#.Right [(#Capturing [?name num_captures]) scoped]) @@ -309,7 +309,7 @@ [idx! (list& name! names) (list& (list name! scoped - (' #let) (` [(~ g!total) (\ (~! //.monoid) (~' compose) (~ g!total) (~ access))])) + (` .let) (` [(~ g!total) (\ (~! //.monoid) (~' compose) (~ g!total) (~ access))])) steps)]) ))) [0 @@ -320,7 +320,7 @@ (list.size names) 0) (` ((~! do) (~! <>.monad) - [(~ (' #let)) [(~ g!total) ""] + [.let [(~ g!total) ""] (~+ (|> steps list.reversed list\join))] ((~ (' in)) [(~ g!total) (~+ (list.reversed names))])))]) )) @@ -371,7 +371,7 @@ Text (Parser [Nat Code])) (do <>.monad - [#let [sub^ (re_sequential^ capturing? re_scoped^ current_module)] + [.let [sub^ (re_sequential^ capturing? re_scoped^ current_module)] head sub^ tail (<>.some (<>.after (<text>.this "|") sub^))] (if (list.empty? tail) diff --git a/stdlib/source/library/lux/debug.lux b/stdlib/source/library/lux/debug.lux index bb4292eca..0fbd4657a 100644 --- a/stdlib/source/library/lux/debug.lux +++ b/stdlib/source/library/lux/debug.lux @@ -135,7 +135,7 @@ (~~ (as_is)))] (`` (|>> (:as (array.Array Any)) <adaption> - array.to_list + array.list (list\map inspection) (text.join_with " ") (text.enclosed ["[" "]"]))))) @@ -563,7 +563,7 @@ (do {! meta.monad} [location meta.location locals meta.locals - #let [environment (|> locals + .let [environment (|> locals list.concat ## The list is reversed to make sure that, when building the dictionary, ## later bindings overshadow earlier ones if they have the same name. diff --git a/stdlib/source/library/lux/ffi.jvm.lux b/stdlib/source/library/lux/ffi.jvm.lux index 81202885a..536960c9a 100644 --- a/stdlib/source/library/lux/ffi.jvm.lux +++ b/stdlib/source/library/lux/ffi.jvm.lux @@ -393,21 +393,21 @@ (def: (make_get_const_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (get_static_field class_name field_name)))) (def: (make_get_var_parser class_name field_name self_name) (-> Text Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (get_virtual_field class_name field_name (code.local_identifier self_name))))) (def: (make_put_var_parser class_name field_name self_name) (-> Text Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] [_ _ value] (: (Parser [Any Any Code]) (<code>.form ($_ <>.and (<code>.this! (' :=)) (<code>.this! (code.identifier ["" dotted_name])) <code>.any)))] (in (`' ("jvm member put virtual" @@ -472,7 +472,7 @@ (def: (make_static_method_parser class_name method_name arguments) (-> Text Text (List Argument) (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" method_name "!")] + [.let [dotted_name (format "::" method_name "!")] args (: (Parser (List Code)) (<code>.form (<>.after (<code>.this! (code.identifier ["" dotted_name])) (<code>.tuple (<>.exactly (list.size arguments) <code>.any)))))] @@ -485,7 +485,7 @@ [(def: (<name> class_name method_name arguments self_name) (-> Text Text (List Argument) Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" method_name "!")] + [.let [dotted_name (format "::" method_name "!")] args (: (Parser (List Code)) (<code>.form (<>.after (<code>.this! (code.identifier ["" dotted_name])) (<code>.tuple (<>.exactly (list.size arguments) <code>.any)))))] @@ -568,7 +568,7 @@ (-> (-> (List (Type Var)) (Parser (Type Parameter))) (-> (List (Type Var)) (Parser (Type Class)))) (do <>.monad - [#let [class_name^ (..valid_class_name type_vars)] + [.let [class_name^ (..valid_class_name type_vars)] [name parameters] (: (Parser [External (List (Type Parameter))]) ($_ <>.either (<>.and class_name^ (<>\in (list))) @@ -725,7 +725,7 @@ (-> (List (Type Var)) (Parser [Member_Declaration MethodDecl])) (<code>.form (do <>.monad [tvars (<>.else (list) ..vars^) - #let [total_vars (list\compose tvars type_vars)] + .let [total_vars (list\compose tvars type_vars)] name <code>.local_identifier anns ..annotations^ inputs (<code>.tuple (<>.some (..type^ total_vars))) @@ -783,7 +783,7 @@ [pm privacy_modifier^ strict_fp? (<>.parses? (<code>.this! (' #strict))) method_vars (<>.else (list) ..vars^) - #let [total_vars (list\compose class_vars method_vars)] + .let [total_vars (list\compose class_vars method_vars)] [_ self_name arguments] (<code>.form ($_ <>.and (<code>.this! (' new)) <code>.local_identifier @@ -804,7 +804,7 @@ strict_fp? (<>.parses? (<code>.this! (' #strict))) final? (<>.parses? (<code>.this! (' #final))) method_vars (<>.else (list) ..vars^) - #let [total_vars (list\compose class_vars method_vars)] + .let [total_vars (list\compose class_vars method_vars)] [name self_name arguments] (<code>.form ($_ <>.and <code>.local_identifier <code>.local_identifier @@ -824,7 +824,7 @@ [strict_fp? (<>.parses? (<code>.this! (' #strict))) owner_class ..declaration^ method_vars (<>.else (list) ..vars^) - #let [total_vars (list\compose (product.right (parser.declaration owner_class)) + .let [total_vars (list\compose (product.right (parser.declaration owner_class)) method_vars)] [name self_name arguments] (<code>.form ($_ <>.and <code>.local_identifier @@ -846,7 +846,7 @@ strict_fp? (<>.parses? (<code>.this! (' #strict))) _ (<code>.this! (' #static)) method_vars (<>.else (list) ..vars^) - #let [total_vars method_vars] + .let [total_vars method_vars] [name arguments] (<code>.form (<>.and <code>.local_identifier (..arguments^ total_vars))) return_type (..return^ total_vars) @@ -864,7 +864,7 @@ [pm privacy_modifier^ _ (<code>.this! (' #abstract)) method_vars (<>.else (list) ..vars^) - #let [total_vars method_vars] + .let [total_vars method_vars] [name arguments] (<code>.form (<>.and <code>.local_identifier (..arguments^ total_vars))) return_type (..return^ total_vars) @@ -881,7 +881,7 @@ [pm privacy_modifier^ _ (<code>.this! (' #native)) method_vars (<>.else (list) ..vars^) - #let [total_vars method_vars] + .let [total_vars method_vars] [name arguments] (<code>.form (<>.and <code>.local_identifier (..arguments^ total_vars))) return_type (..return^ total_vars) @@ -950,7 +950,7 @@ [tvars (<>.else (list) ..vars^) _ (<code>.identifier! ["" "new"]) ?alias import_member_alias^ - #let [total_vars (list\compose owner_vars tvars)] + .let [total_vars (list\compose owner_vars tvars)] ?prim_mode (<>.maybe primitive_mode^) args (..import_member_args^ total_vars) [io? try? maybe?] import_member_return_flags^] @@ -971,7 +971,7 @@ tvars (<>.else (list) ..vars^) name <code>.local_identifier ?alias import_member_alias^ - #let [total_vars (list\compose owner_vars tvars)] + .let [total_vars (list\compose owner_vars tvars)] ?prim_mode (<>.maybe primitive_mode^) args (..import_member_args^ total_vars) [io? try? maybe?] import_member_return_flags^ @@ -1200,7 +1200,7 @@ (type.class "java.lang.Object" (list))) (syntax: #export (class: - {#let [! <>.monad]} + {.let [! <>.monad]} {im inheritance_modifier^} {[full_class_name class_vars] (\ ! map parser.declaration ..declaration^)} {super (<>.else $Object @@ -1242,7 +1242,7 @@ "(::resolve! container [value]) for calling the 'resolve' method." )} (do meta.monad - [#let [fully_qualified_class_name full_class_name + [.let [fully_qualified_class_name full_class_name method_parser (: (Parser Code) (|> methods (list\map (method->parser fully_qualified_class_name)) @@ -1257,7 +1257,7 @@ [(~+ (list\map (method_def$ fully_qualified_class_name method_parser super fields) methods))])))))) (syntax: #export (interface: - {#let [! <>.monad]} + {.let [! <>.monad]} {[full_class_name class_vars] (\ ! map parser.declaration ..declaration^)} {supers (<>.else (list) (<code>.tuple (<>.some (class^ class_vars))))} @@ -1425,7 +1425,7 @@ (with_gensyms [arg_name] (in [maybe? arg_name])))) import_member_args) - #let [input_jvm_types (list\map product.right import_member_args) + .let [input_jvm_types (list\map product.right import_member_args) arg_types (list\map (: (-> [Bit (Type Value)] Code) (function (_ [maybe? arg]) (let [arg_type (value_type (get@ #import_member_mode commons) arg)] @@ -1571,7 +1571,7 @@ (case member (#EnumDecl enum_members) (do meta.monad - [#let [enum_type (: Code + [.let [enum_type (: Code (case class_tvars #.End (` (primitive (~ (code.text full_name)))) @@ -1589,7 +1589,7 @@ (#ConstructorDecl [commons _]) (do meta.monad - [#let [classT (type.class full_name (list)) + [.let [classT (type.class full_name (list)) def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) jvm_interop (|> [classT (` ("jvm member invoke constructor" @@ -1609,7 +1609,7 @@ (#MethodDecl [commons method]) (with_gensyms [g!obj] (do meta.monad - [#let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) + [.let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) (^slots [#import_member_kind]) commons (^slots [#import_method_name]) method [jvm_op object_ast] (: [Text (List Code)] @@ -1662,7 +1662,7 @@ (#FieldAccessDecl fad) (do meta.monad - [#let [(^open ".") fad + [.let [(^open ".") fad getter_name (code.identifier ["" (..import_name import_format method_prefix import_field_name)]) setter_name (code.identifier ["" (..import_name import_format method_prefix (format import_field_name "!"))])] getter_interop (with_gensyms [g!obj] @@ -1741,7 +1741,7 @@ (syntax: #export (import: {declaration ..declaration^} - {#let [[class_name class_type_vars] (parser.declaration declaration)]} + {.let [[class_name class_type_vars] (parser.declaration declaration)]} {bundles (<>.some (..bundle class_type_vars))}) {#.doc (doc "Allows importing JVM classes, and using them as types." "Their methods, fields and enum options can also be imported." @@ -1931,7 +1931,7 @@ (do meta.monad [array_type (meta.type array_name) array_jvm_type (lux_type->jvm_type array_type) - #let [g!extension (code.text (`` (cond (~~ (template [<primitive> <extension>] + .let [g!extension (code.text (`` (cond (~~ (template [<primitive> <extension>] [(\ type.equivalence = (type.array <primitive>) array_jvm_type) @@ -1967,7 +1967,7 @@ (do meta.monad [array_type (meta.type array_name) array_jvm_type (lux_type->jvm_type array_type) - #let [g!idx (` (.|> (~ idx) + .let [g!idx (` (.|> (~ idx) (.: .Nat) (.:as (.primitive (~ (code.text box.long)))) "jvm object cast" @@ -2005,7 +2005,7 @@ (do meta.monad [array_type (meta.type array_name) array_jvm_type (lux_type->jvm_type array_type) - #let [g!idx (` (.|> (~ idx) + .let [g!idx (` (.|> (~ idx) (.: .Nat) (.:as (.primitive (~ (code.text box.long)))) "jvm object cast" diff --git a/stdlib/source/library/lux/ffi.old.lux b/stdlib/source/library/lux/ffi.old.lux index 89feff739..6b8ff867d 100644 --- a/stdlib/source/library/lux/ffi.old.lux +++ b/stdlib/source/library/lux/ffi.old.lux @@ -387,21 +387,21 @@ (def: (get_const_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (`' ((~ (code.text (format "jvm getstatic" ":" class_name ":" field_name)))))))) (def: (get_var_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] _ (<code>.this! (code.identifier ["" dotted_name]))] (in (`' ((~ (code.text (format "jvm getfield" ":" class_name ":" field_name))) _jvm_this))))) (def: (put_var_parser class_name field_name) (-> Text Text (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" field_name)] + [.let [dotted_name (format "::" field_name)] [_ _ value] (: (Parser [Any Any Code]) (<code>.form ($_ <>.and (<code>.this! (' :=)) (<code>.this! (code.identifier ["" dotted_name])) <code>.any)))] (in (`' ((~ (code.text (format "jvm putfield" ":" class_name ":" field_name))) _jvm_this (~ value)))))) @@ -450,18 +450,18 @@ [args (: (Parser (List Code)) (<code>.form (<>.after (<code>.this! (' ::new!)) (<code>.tuple (<>.exactly (list.size arg_decls) <code>.any))))) - #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] + .let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] (in (` ((~ (code.text (format "jvm new" ":" class_name ":" (text.join_with "," arg_decls')))) (~+ args)))))) (def: (static_method_parser params class_name method_name arg_decls) (-> (List Type_Parameter) Text Text (List ArgDecl) (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" method_name "!")] + [.let [dotted_name (format "::" method_name "!")] args (: (Parser (List Code)) (<code>.form (<>.after (<code>.this! (code.identifier ["" dotted_name])) (<code>.tuple (<>.exactly (list.size arg_decls) <code>.any))))) - #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] + .let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] (in (`' ((~ (code.text (format "jvm invokestatic" ":" class_name ":" method_name ":" (text.join_with "," arg_decls')))) (~+ args)))))) @@ -469,11 +469,11 @@ [(def: (<name> params class_name method_name arg_decls) (-> (List Type_Parameter) Text Text (List ArgDecl) (Parser Code)) (do <>.monad - [#let [dotted_name (format "::" method_name "!")] + [.let [dotted_name (format "::" method_name "!")] args (: (Parser (List Code)) (<code>.form (<>.after (<code>.this! (code.identifier ["" dotted_name])) (<code>.tuple (<>.exactly (list.size arg_decls) <code>.any))))) - #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] + .let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ params)) arg_decls))]] (in (`' ((~ (code.text (format <jvm_op> ":" class_name ":" method_name ":" (text.join_with "," arg_decls')))) (~' _jvm_this) (~+ args))))))] @@ -713,7 +713,7 @@ [pm privacy_modifier^ strict_fp? (<>.parses? (<code>.this! (' #strict))) method_vars ..type_params^ - #let [total_vars (list\compose class_vars method_vars)] + .let [total_vars (list\compose class_vars method_vars)] [_ arg_decls] (<code>.form (<>.and (<code>.this! (' new)) (..arg_decls^ total_vars))) constructor_args (..constructor_args^ total_vars) @@ -732,7 +732,7 @@ strict_fp? (<>.parses? (<code>.this! (' #strict))) final? (<>.parses? (<code>.this! (' #final))) method_vars ..type_params^ - #let [total_vars (list\compose class_vars method_vars)] + .let [total_vars (list\compose class_vars method_vars)] [name this_name arg_decls] (<code>.form ($_ <>.and <code>.local_identifier <code>.local_identifier @@ -755,7 +755,7 @@ [strict_fp? (<>.parses? (<code>.this! (' #strict))) owner_class ..class_decl^ method_vars ..type_params^ - #let [total_vars (list\compose (product.right owner_class) method_vars)] + .let [total_vars (list\compose (product.right owner_class) method_vars)] [name this_name arg_decls] (<code>.form ($_ <>.and <code>.local_identifier <code>.local_identifier @@ -779,7 +779,7 @@ strict_fp? (<>.parses? (<code>.this! (' #strict))) _ (<code>.this! (' #static)) method_vars ..type_params^ - #let [total_vars method_vars] + .let [total_vars method_vars] [name arg_decls] (<code>.form (<>.and <code>.local_identifier (..arg_decls^ total_vars))) return_type (..generic_type^ total_vars) @@ -797,7 +797,7 @@ [pm privacy_modifier^ _ (<code>.this! (' #abstract)) method_vars ..type_params^ - #let [total_vars method_vars] + .let [total_vars method_vars] [name arg_decls] (<code>.form (<>.and <code>.local_identifier (..arg_decls^ total_vars))) return_type (..generic_type^ total_vars) @@ -814,7 +814,7 @@ [pm privacy_modifier^ _ (<code>.this! (' #native)) method_vars ..type_params^ - #let [total_vars method_vars] + .let [total_vars method_vars] [name arg_decls] (<code>.form (<>.and <code>.local_identifier (..arg_decls^ total_vars))) return_type (..generic_type^ total_vars) @@ -879,7 +879,7 @@ [tvars ..type_params^ _ (<code>.this! (' new)) ?alias import_member_alias^ - #let [total_vars (list\compose owner_vars tvars)] + .let [total_vars (list\compose owner_vars tvars)] ?prim_mode (<>.maybe primitive_mode^) args (..import_member_args^ total_vars) [io? try? maybe?] import_member_return_flags^] @@ -900,7 +900,7 @@ tvars ..type_params^ name <code>.local_identifier ?alias import_member_alias^ - #let [total_vars (list\compose owner_vars tvars)] + .let [total_vars (list\compose owner_vars tvars)] ?prim_mode (<>.maybe primitive_mode^) args (..import_member_args^ total_vars) [io? try? maybe?] import_member_return_flags^ @@ -1095,7 +1095,7 @@ (let [super_replacer (parser_replacer (<code>.form (do <>.monad [_ (<code>.this! (' ::super!)) args (<code>.tuple (<>.exactly (list.size arg_decls) <code>.any)) - #let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ (list))) + .let [arg_decls' (: (List Text) (list\map (|>> product.right (simple_class$ (list))) arg_decls))]] (in (`' ((~ (code.text (format "jvm invokespecial" ":" (get@ #super_class_name super_class) @@ -1168,8 +1168,8 @@ (syntax: #export (class: {im inheritance_modifier^} {class_decl ..class_decl^} - {#let [full_class_name (product.left class_decl)]} - {#let [class_vars (product.right class_decl)]} + {.let [full_class_name (product.left class_decl)]} + {.let [class_vars (product.right class_decl)]} {super (<>.else object_super_class (..super_class_decl^ class_vars))} {interfaces (<>.else (list) @@ -1209,7 +1209,7 @@ )} (do meta.monad [current_module meta.current_module_name - #let [fully_qualified_class_name (format (safe current_module) "." full_class_name) + .let [fully_qualified_class_name (format (safe current_module) "." full_class_name) field_parsers (list\map (field_parser fully_qualified_class_name) fields) method_parsers (list\map (method_parser (product.right class_decl) fully_qualified_class_name) methods) replacer (parser_replacer (list\fold <>.either @@ -1227,7 +1227,7 @@ (syntax: #export (interface: {class_decl ..class_decl^} - {#let [class_vars (product.right class_decl)]} + {.let [class_vars (product.right class_decl)]} {supers (<>.else (list) (<code>.tuple (<>.some (..super_class_decl^ class_vars))))} {annotations ..annotations^} @@ -1394,7 +1394,7 @@ (with_gensyms [arg_name] (in [maybe? arg_name])))) import_member_args) - #let [arg_classes (: (List Text) + .let [arg_classes (: (List Text) (list\map (|>> product.right (simple_class$ (list\compose type_params import_member_tvars))) import_member_args)) arg_types (list\map (: (-> [Bit GenericType] Code) @@ -1449,7 +1449,7 @@ #.End #1 _ #0)) -(def: (type_param_to_type_arg [name _]) +(def: (lux_type_parameter [name _]) (-> Type_Parameter Code) (code.identifier ["" name])) @@ -1498,11 +1498,11 @@ full_name (safe full_name) all_params (|> (member_type_vars class_tvars member) (list.only free_type_param?) - (list\map type_param_to_type_arg))] + (list\map lux_type_parameter))] (case member (#EnumDecl enum_members) (do {! meta.monad} - [#let [enum_type (: Code + [.let [enum_type (: Code (case class_tvars #.End (` (primitive (~ (code.text full_name)))) @@ -1510,7 +1510,7 @@ _ (let [=class_tvars (|> class_tvars (list.only free_type_param?) - (list\map type_param_to_type_arg))] + (list\map lux_type_parameter))] (` (All [(~+ =class_tvars)] (primitive (~ (code.text full_name)) [(~+ =class_tvars)])))))) getter_interop (: (-> Text Code) (function (_ name) @@ -1522,7 +1522,7 @@ (#ConstructorDecl [commons _]) (do meta.monad - [#let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) + [.let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) jvm_extension (code.text (format "jvm new" ":" full_name ":" (text.join_with "," arg_classes))) jvm_interop (|> (` ((~ jvm_extension) (~+ (jvm_extension_inputs (get@ #import_member_mode commons) arg_classes arg_function_inputs)))) @@ -1535,7 +1535,7 @@ (#MethodDecl [commons method]) (with_gensyms [g!obj] (do meta.monad - [#let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) + [.let [def_name (code.identifier ["" (..import_name import_format method_prefix (get@ #import_member_alias commons))]) (^slots [#import_member_kind]) commons (^slots [#import_method_name]) method [jvm_op object_ast] (: [Text (List Code)] @@ -1567,7 +1567,7 @@ (#FieldAccessDecl fad) (do meta.monad - [#let [(^open ".") fad + [.let [(^open ".") fad base_gtype (class_type import_field_mode type_params import_field_type) classC (class_decl_type$ class) typeC (if import_field_maybe? @@ -1576,7 +1576,7 @@ tvar_asts (: (List Code) (|> class_tvars (list.only free_type_param?) - (list\map type_param_to_type_arg))) + (list\map lux_type_parameter))) getter_name (code.identifier ["" (..import_name import_format method_prefix import_field_name)]) setter_name (code.identifier ["" (..import_name import_format method_prefix (format import_field_name "!"))])] getter_interop (with_gensyms [g!obj] diff --git a/stdlib/source/library/lux/macro.lux b/stdlib/source/library/lux/macro.lux index 04a9324c4..91025dcaf 100644 --- a/stdlib/source/library/lux/macro.lux +++ b/stdlib/source/library/lux/macro.lux @@ -145,7 +145,7 @@ (^ (list [_ (#.Tuple identifiers)] body)) (do {! //.monad} [identifier_names (monad.map ! ..get_local_identifier identifiers) - #let [identifier_defs (list\join (list\map (: (-> Text (List Code)) + .let [identifier_defs (list\join (list\map (: (-> Text (List Code)) (function (_ name) (list (code.identifier ["" name]) (` (gensym (~ (code.text name))))))) identifier_names))]] (in (list (` ((~! do) (~! //.monad) @@ -194,7 +194,7 @@ (do //.monad [location //.location output (<func> token) - #let [_ ("lux io log" ($_ text\compose (name\encode macro_name) " " (location.format location))) + .let [_ ("lux io log" ($_ text\compose (name\encode macro_name) " " (location.format location))) _ (list\map (|>> code.format "lux io log") output) _ ("lux io log" "")]] diff --git a/stdlib/source/library/lux/macro/local.lux b/stdlib/source/library/lux/macro/local.lux index 2872adb12..f6dcb0590 100644 --- a/stdlib/source/library/lux/macro/local.lux +++ b/stdlib/source/library/lux/macro/local.lux @@ -51,7 +51,7 @@ (-> [Name Macro] (Meta Any)) (do meta.monad [[module_name definition_name] (meta.normal name) - #let [definition (: Global (#.Definition [false .Macro (' {}) macro])) + .let [definition (: Global (#.Definition [false .Macro (' {}) macro])) add_macro! (: (-> (PList Global) (PList Global)) (plist.put definition_name definition))]] (..with_module module_name @@ -68,7 +68,7 @@ (-> Name (Meta Any)) (do meta.monad [[module_name definition_name] (meta.normal name) - #let [remove_macro! (: (-> (PList Global) (PList Global)) + .let [remove_macro! (: (-> (PList Global) (PList Global)) (plist.remove definition_name))]] (..with_module module_name (function (_ module) diff --git a/stdlib/source/library/lux/macro/poly.lux b/stdlib/source/library/lux/macro/poly.lux index a92c9bd96..f89f7568c 100644 --- a/stdlib/source/library/lux/macro/poly.lux +++ b/stdlib/source/library/lux/macro/poly.lux @@ -70,7 +70,7 @@ _ (<>.failure "derived: was given no explicit name, and cannot generate one from given information.")) - #let [impl (case ?custom_impl + .let [impl (case ?custom_impl (#.Some custom_impl) custom_impl @@ -81,12 +81,12 @@ {#.implementation? #1} (~ impl))))))) -(def: #export (to_code env type) +(def: #export (code env type) (-> Env Type Code) (`` (case type (#.Primitive name params) (` (#.Primitive (~ (code.text name)) - (list (~+ (list\map (to_code env) params))))) + (.list (~+ (list\map (code env) params))))) (^template [<tag>] [(<tag> idx) @@ -96,24 +96,24 @@ (#.Parameter idx) (let [idx (<type>.adjusted_idx env idx)] (if (n.= 0 idx) - (|> (dictionary.get idx env) maybe.assume product.left (to_code env)) + (|> (dictionary.get idx env) maybe.assume product.left (code env)) (` (.$ (~ (code.nat (dec idx))))))) (#.Apply (#.Named [(~~ (static .prelude_module)) "Nothing"] _) (#.Parameter idx)) (let [idx (<type>.adjusted_idx env idx)] (if (n.= 0 idx) - (|> (dictionary.get idx env) maybe.assume product.left (to_code env)) + (|> (dictionary.get idx env) maybe.assume product.left (code env)) (undefined))) (^template [<tag>] [(<tag> left right) - (` (<tag> (~ (to_code env left)) - (~ (to_code env right))))]) + (` (<tag> (~ (code env left)) + (~ (code env right))))]) ([#.Function] [#.Apply]) (^template [<macro> <tag> <flattener>] [(<tag> left right) - (` (<macro> (~+ (list\map (to_code env) (<flattener> type)))))]) + (` (<macro> (~+ (list\map (code env) (<flattener> type)))))]) ([.Variant #.Sum type.flat_variant] [.Tuple #.Product type.flat_tuple]) @@ -122,7 +122,7 @@ (^template [<tag>] [(<tag> scope body) - (` (<tag> (list (~+ (list\map (to_code env) scope))) - (~ (to_code env body))))]) + (` (<tag> (.list (~+ (list\map (code env) scope))) + (~ (code env body))))]) ([#.UnivQ] [#.ExQ]) ))) diff --git a/stdlib/source/library/lux/macro/syntax.lux b/stdlib/source/library/lux/macro/syntax.lux index 1e80a355f..99bb28c0e 100644 --- a/stdlib/source/library/lux/macro/syntax.lux +++ b/stdlib/source/library/lux/macro/syntax.lux @@ -46,8 +46,8 @@ "The inputs to the macro can be parsed in complex ways through the use of syntax parsers." "The macro body is also (implicitly) run in the Meta monad, to save some typing." "Also, the compiler state can be accessed through the *compiler* binding." - (syntax: #export (object {#let [imports (class_imports *compiler*)]} - {#let [class_vars (list)]} + (syntax: #export (object {.let [imports (class_imports *compiler*)]} + {.let [class_vars (list)]} {super (opt (super_class_decl^ imports class_vars))} {interfaces (tuple (some (super_class_decl^ imports class_vars)))} {constructor_args (constructor_args^ imports class_vars)} @@ -87,14 +87,18 @@ (function (_ arg) (case arg (^ [_ (#.Record (list [var parser]))]) - (case var - [_ (#.Tag ["" "let"])] - (in [var parser]) + (with_expansions [<default> (in [var + (` ((~! ..self_documenting) (' (~ var)) + (~ parser)))])] + (case var + [_ (#.Identifier ["" _])] + <default> - _ - (in [var - (` ((~! ..self_documenting) (' (~ var)) - (~ parser)))])) + [_ (#.Identifier _)] + (in [var parser]) + + _ + <default>)) [_ (#.Identifier var_name)] (in [arg @@ -105,7 +109,7 @@ (meta.failure "Syntax pattern expects records or identifiers.")))) args) this_module meta.current_module_name - #let [g!state (code.identifier ["" "*compiler*"]) + .let [g!state (code.identifier ["" "*compiler*"]) error_msg (code.text (macro.wrong_syntax_error [this_module name])) export_ast (: (List Code) (if exported? diff --git a/stdlib/source/library/lux/math/logic/fuzzy.lux b/stdlib/source/library/lux/math/logic/fuzzy.lux index d869eb4a7..a449f1ca6 100644 --- a/stdlib/source/library/lux/math/logic/fuzzy.lux +++ b/stdlib/source/library/lux/math/logic/fuzzy.lux @@ -67,7 +67,7 @@ //.true //.false))) -(def: #export (to_predicate treshold set) +(def: #export (predicate treshold set) (All [a] (-> Rev (Fuzzy a) (Predicate a))) (function (_ elem) (/.> treshold (set elem)))) diff --git a/stdlib/source/library/lux/math/modulus.lux b/stdlib/source/library/lux/math/modulus.lux index 8f490d236..05a0ef26d 100644 --- a/stdlib/source/library/lux/math/modulus.lux +++ b/stdlib/source/library/lux/math/modulus.lux @@ -20,29 +20,29 @@ (exception: #export zero_cannot_be_a_modulus) -(abstract: #export (Modulus m) +(abstract: #export (Modulus %) Int {#.doc (doc "A number used as a modulus in modular arithmetic." "It cannot be 0.")} (def: #export (modulus value) - (Ex [m] (-> Int (Try (Modulus m)))) + (Ex [%] (-> Int (Try (Modulus %)))) (if (i.= +0 value) (exception.except ..zero_cannot_be_a_modulus []) (#try.Success (:abstraction value)))) (def: #export divisor - (All [m] (-> (Modulus m) Int)) + (All [%] (-> (Modulus %) Int)) (|>> :representation)) (def: #export (= reference subject) - (All [r s] (-> (Modulus r) (Modulus s) Bit)) + (All [%r %s] (-> (Modulus %r) (Modulus %s) Bit)) (i.= (:representation reference) (:representation subject))) (def: #export (congruent? modulus reference subject) - (All [m] (-> (Modulus m) Int Int Bit)) + (All [%] (-> (Modulus %) Int Int Bit)) (|> subject (i.- reference) (i.% (:representation modulus)) @@ -50,6 +50,11 @@ ) (syntax: #export (literal {divisor <code>.int}) + {#.doc (doc "Success!" + (literal 123) + + "Failure!" + (literal 0))} (meta.lift (do try.monad [_ (..modulus divisor)] diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux index d2ed4651a..c602db1c5 100644 --- a/stdlib/source/library/lux/math/number/frac.lux +++ b/stdlib/source/library/lux/math/number/frac.lux @@ -247,7 +247,7 @@ (def: smallest_exponent (..log/2 ..smallest)) -(def: #export (to_bits input) +(def: #export (bits input) (-> Frac I64) (.i64 (cond (..not_a_number? input) ..not_a_number_bits @@ -349,7 +349,7 @@ (..* exponent) (..* sign))))) -(def: (split_exponent codec representation) +(def: (representation_exponent codec representation) (-> (Codec Text Nat) Text (Try [Text Int])) (case [("lux text index" 0 "e+" representation) ("lux text index" 0 "E+" representation) @@ -358,7 +358,7 @@ (^template [<factor> <patterns>] [<patterns> (do try.monad - [#let [after_offset (//nat.+ 2 split_index) + [.let [after_offset (//nat.+ 2 split_index) after_length (//nat.- after_offset ("lux text size" representation))] exponent (|> representation ("lux text clip" after_offset after_length) @@ -378,7 +378,7 @@ (Codec Text Frac) (def: (encode value) - (let [bits (..to_bits value) + (let [bits (..bits value) mantissa (..mantissa bits) exponent (//int.- (.int ..double_bias) (..exponent bits)) sign (..sign bits)] @@ -396,11 +396,11 @@ positive? (text.starts_with? "+" representation)] (if (or negative? positive?) (do {! try.monad} - [[mantissa exponent] (..split_exponent <nat> representation) + [[mantissa exponent] (..representation_exponent <nat> representation) [whole decimal] (case ("lux text index" 0 "." mantissa) (#.Some split_index) (do ! - [#let [after_offset (inc split_index) + [.let [after_offset (inc split_index) after_length (//nat.- after_offset ("lux text size" mantissa))] decimal (|> mantissa ("lux text clip" after_offset after_length) @@ -410,11 +410,11 @@ #.None (#try.Failure ("lux text concat" <error> representation))) - #let [whole ("lux text clip" 1 (dec ("lux text size" whole)) whole)] + .let [whole ("lux text clip" 1 (dec ("lux text size" whole)) whole)] mantissa (\ <nat> decode (case decimal 0 whole _ ("lux text concat" whole (\ <nat> encode decimal)))) - #let [sign (if negative? 1 0)]] + .let [sign (if negative? 1 0)]] (in (..of_bits ($_ //i64.or (//i64.left_shifted ..sign_offset (.i64 sign)) @@ -431,7 +431,7 @@ (Hash Frac) (def: &equivalence ..equivalence) - (def: hash ..to_bits)) + (def: hash ..bits)) (def: #export (approximately? margin_of_error standard value) (-> Frac Frac Frac Bit) diff --git a/stdlib/source/library/lux/math/number/int.lux b/stdlib/source/library/lux/math/number/int.lux index 64984968e..610ad296e 100644 --- a/stdlib/source/library/lux/math/number/int.lux +++ b/stdlib/source/library/lux/math/number/int.lux @@ -84,21 +84,25 @@ ) (def: #export (/% param subject) + {#.doc "Int(eger) [division remainder]."} (-> Int Int [Int Int]) [(../ param subject) (..% param subject)]) (def: #export (opposite value) + {#.doc (doc "A value of equal magnitude and opposite sign.")} (-> Int Int) (..- value +0)) (def: #export (abs x) + {#.doc (doc "A value of equal magnitude and positive sign.")} (-> Int Int) (if (..< +0 x) (..* -1 x) x)) (def: #export (signum x) + {#.doc (doc "A value (either -1, 0 or +0) which represents the sign.")} (-> Int Int) (cond (..= +0 x) +0 (..< +0 x) -1 @@ -107,6 +111,8 @@ ## https://rob.conery.io/2018/08/21/mod-and-remainder-are-not-the-same/ (def: #export (mod divisor dividend) + {#.doc (doc "Integer modulo." + "Note: The modulo and the remainder are not the same.")} (All [m] (-> Int Int Int)) (let [remainder (..% divisor dividend)] (if (or (and (..< +0 divisor) @@ -124,6 +130,7 @@ (-> Int Bit) (|>> ..even? not)) +## https://en.wikipedia.org/wiki/Greatest_common_divisor (def: #export (gcd a b) {#.doc "Greatest Common Divisor."} (-> Int Int Int) @@ -149,6 +156,7 @@ y1 (- (* q y1) y) b1 (- (* q b1) a1)))))) +## https://en.wikipedia.org/wiki/Least_common_multiple (def: #export (lcm a b) {#.doc "Least Common Multiple."} (-> Int Int Int) @@ -157,8 +165,7 @@ +0 _ - (|> a (/ (gcd a b)) (* b)) - )) + (|> a (/ (gcd a b)) (* b)))) (def: #export frac (-> Int Frac) diff --git a/stdlib/source/library/lux/math/number/ratio.lux b/stdlib/source/library/lux/math/number/ratio.lux index c97849629..a53f87dd9 100644 --- a/stdlib/source/library/lux/math/number/ratio.lux +++ b/stdlib/source/library/lux/math/number/ratio.lux @@ -24,6 +24,7 @@ ["n" nat ("#\." decimal)]]) (type: #export Ratio + {#.doc (doc "An unsigned ratio of numbers.")} {#numerator Nat #denominator Nat}) diff --git a/stdlib/source/library/lux/math/random.lux b/stdlib/source/library/lux/math/random.lux index c2dce8f0a..7d80d6f76 100644 --- a/stdlib/source/library/lux/math/random.lux +++ b/stdlib/source/library/lux/math/random.lux @@ -142,6 +142,7 @@ (\ ..monad map (|>> .i64 f.of_bits) ..nat)) (def: #export safe_frac + {#.doc (doc "A number in the interval [0.0,1.0].")} (Random Frac) (let [mantissa_range (.int (i64.left_shifted 53 1)) mantissa_max (i.frac (dec mantissa_range))] @@ -270,34 +271,34 @@ [stack Stack (list\fold stack.push stack.empty)] ) -(def: #export (set Hash<a> size value_gen) +(def: #export (set hash size value_gen) (All [a] (-> (Hash a) Nat (Random a) (Random (Set a)))) (if (n.> 0 size) (do {! ..monad} - [xs (set Hash<a> (dec size) value_gen)] + [xs (set hash (dec size) value_gen)] (loop [_ []] (do ! [x value_gen - #let [xs+ (set.add x xs)]] + .let [xs+ (set.add x xs)]] (if (n.= size (set.size xs+)) (in xs+) (recur []))))) - (\ ..monad in (set.empty Hash<a>)))) + (\ ..monad in (set.empty hash)))) -(def: #export (dictionary Hash<a> size key_gen value_gen) +(def: #export (dictionary hash size key_gen value_gen) (All [k v] (-> (Hash k) Nat (Random k) (Random v) (Random (Dictionary k v)))) (if (n.> 0 size) (do {! ..monad} - [kv (dictionary Hash<a> (dec size) key_gen value_gen)] + [kv (dictionary hash (dec size) key_gen value_gen)] (loop [_ []] (do ! [k key_gen v value_gen - #let [kv+ (dictionary.put k v kv)]] + .let [kv+ (dictionary.put k v kv)]] (if (n.= size (dictionary.size kv+)) (in kv+) (recur []))))) - (\ ..monad in (dictionary.empty Hash<a>)))) + (\ ..monad in (dictionary.empty hash)))) (def: #export instant (Random Instant) @@ -353,13 +354,13 @@ [(recur (update state)) (return state)]))) -(def: #export (pcg32 [increase seed]) +(def: #export (pcg_32 [increase seed]) {#.doc (doc "An implementation of the PCG32 algorithm." "For more information, please see: http://www.pcg-random.org/")} (-> [(I64 Any) (I64 Any)] PRNG) (let [magic 6364136223846793005] (function (_ _) - [(|> seed .nat (n.* magic) ("lux i64 +" increase) [increase] pcg32) + [(|> seed .nat (n.* magic) ("lux i64 +" increase) [increase] pcg_32) (let [rot (|> seed .i64 (i64.right_shifted 59))] (|> seed (i64.right_shifted 18) diff --git a/stdlib/source/library/lux/meta.lux b/stdlib/source/library/lux/meta.lux index 26d7d44c7..a3ae310b0 100644 --- a/stdlib/source/library/lux/meta.lux +++ b/stdlib/source/library/lux/meta.lux @@ -279,7 +279,7 @@ (-> Name (Meta Global)) (do ..monad [name (..normal name) - #let [[normal_module normal_short] name]] + .let [[normal_module normal_short] name]] (function (_ compiler) (case (: (Maybe Global) (do maybe.monad @@ -364,7 +364,7 @@ {#.doc "Looks-up the type of either a local variable or a definition."} (-> Name (Meta Type)) (do ..monad - [#let [[_ _name] name]] + [.let [[_ _name] name]] (case name ["" _name] (either (var_type _name) @@ -439,7 +439,7 @@ {#.doc "All the tags associated with a type definition."} (-> Name (Meta (Maybe (List Name)))) (do ..monad - [#let [[module name] type_name] + [.let [[module name] type_name] module (..module module)] (case (plist.get name (get@ #.types module)) (#.Some [tags _]) @@ -488,7 +488,7 @@ {#.doc "Given a tag, finds out what is its index, its related tag-list and its associated type."} (-> Name (Meta [Nat (List Name) Type])) (do ..monad - [#let [[module name] tag_name] + [.let [[module name] tag_name] =module (..module module) this_module_name ..current_module_name imported! (..imported? module)] diff --git a/stdlib/source/library/lux/meta/annotation.lux b/stdlib/source/library/lux/meta/annotation.lux index a9892473f..b49dd5d8e 100644 --- a/stdlib/source/library/lux/meta/annotation.lux +++ b/stdlib/source/library/lux/meta/annotation.lux @@ -1,4 +1,5 @@ (.module: + {#.doc (.doc "Machinary for querying annotations on modules and definitions.")} [library [lux (#- nat int rev) [abstract @@ -70,7 +71,7 @@ [implementation? #.implementation?] [recursive_type? #.type_rec?] - [signature? #.sig?] + [interface? #.interface?] ) (def: (text_parser input) diff --git a/stdlib/source/library/lux/meta/location.lux b/stdlib/source/library/lux/meta/location.lux index 8738d873a..9216889f0 100644 --- a/stdlib/source/library/lux/meta/location.lux +++ b/stdlib/source/library/lux/meta/location.lux @@ -19,13 +19,16 @@ #.column 0}) (macro: #export (here tokens compiler) + {#.doc (doc "The Location of the current form." + (here))} (case tokens #.End (let [location (get@ #.location compiler)] (#.Right [compiler - (list (` [(~ [..dummy (#.Text (get@ #.module location))]) - (~ [..dummy (#.Nat (get@ #.line location))]) - (~ [..dummy (#.Nat (get@ #.column location))])]))])) + (list (` (.: .Location + [(~ [..dummy (#.Text (get@ #.module location))]) + (~ [..dummy (#.Nat (get@ #.line location))]) + (~ [..dummy (#.Nat (get@ #.column location))])])))])) _ (#.Left (`` (("lux in-module" (~~ (static .prelude_module)) wrong_syntax_error) (name_of ..here)))))) diff --git a/stdlib/source/library/lux/target/jvm/bytecode.lux b/stdlib/source/library/lux/target/jvm/bytecode.lux index c281f119f..a22ff102b 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode.lux @@ -787,7 +787,7 @@ (function (_ [pool environment tracker]) (do try.monad [actual (/environment.stack environment) - #let [@here (get@ #program_counter tracker)] + .let [@here (get@ #program_counter tracker)] program_counter' (step estimator @here)] (in (let [@from @here] [[pool @@ -973,7 +973,7 @@ (<method> (..reflection class)) {#//constant/pool.name method #//constant/pool.descriptor (type.descriptor type)}) - #let [consumption (|> inputs + .let [consumption (|> inputs (list\map ..type_size) (list\fold n.+ (if <static?> 0 1)) //unsigned.u1 diff --git a/stdlib/source/library/lux/target/jvm/bytecode/environment.lux b/stdlib/source/library/lux/target/jvm/bytecode/environment.lux index 289e3bd99..6fbdadfa3 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode/environment.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode/environment.lux @@ -95,7 +95,7 @@ (do try.monad [previous (..stack environment) current (/stack.push amount previous) - #let [limit (|> environment + .let [limit (|> environment (get@ [#..limit #/limit.stack]) (/stack.max current))]] (in (|> environment diff --git a/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux b/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux index c2532933a..3302b60dc 100644 --- a/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux +++ b/stdlib/source/library/lux/target/jvm/bytecode/instruction.lux @@ -616,7 +616,7 @@ [amount_of_afterwards (|> amount_of_afterwards .int ///signed.s4) maximum (///signed.+/4 minimum amount_of_afterwards) _ (binary.write/8 offset (hex "AA") binary) - #let [offset (n.+ (///unsigned.value ..opcode_size) offset)] + .let [offset (n.+ (///unsigned.value ..opcode_size) offset)] _ (case padding 3 (do ! [_ (binary.write/8 offset 0 binary)] @@ -624,11 +624,11 @@ 2 (binary.write/16 offset 0 binary) 1 (binary.write/8 offset 0 binary) _ (in binary)) - #let [offset (n.+ padding offset)] + .let [offset (n.+ padding offset)] _ (binary.write/32 offset (///signed.value default) binary) - #let [offset (n.+ (///unsigned.value ..big_jump_size) offset)] + .let [offset (n.+ (///unsigned.value ..big_jump_size) offset)] _ (binary.write/32 offset (///signed.value minimum) binary) - #let [offset (n.+ (///unsigned.value ..integer_size) offset)] + .let [offset (n.+ (///unsigned.value ..integer_size) offset)] _ (binary.write/32 offset (///signed.value maximum) binary)] (loop [offset (n.+ (///unsigned.value ..integer_size) offset) afterwards (: (List Big_Jump) @@ -678,7 +678,7 @@ (try.assumed (do {! try.monad} [_ (binary.write/8 offset (hex "AB") binary) - #let [offset (n.+ (///unsigned.value ..opcode_size) offset)] + .let [offset (n.+ (///unsigned.value ..opcode_size) offset)] _ (case padding 3 (do ! [_ (binary.write/8 offset 0 binary)] @@ -686,9 +686,9 @@ 2 (binary.write/16 offset 0 binary) 1 (binary.write/8 offset 0 binary) _ (in binary)) - #let [offset (n.+ padding offset)] + .let [offset (n.+ padding offset)] _ (binary.write/32 offset (///signed.value default) binary) - #let [offset (n.+ (///unsigned.value ..big_jump_size) offset)] + .let [offset (n.+ (///unsigned.value ..big_jump_size) offset)] _ (binary.write/32 offset amount_of_cases binary)] (loop [offset (n.+ (///unsigned.value ..integer_size) offset) cases cases] diff --git a/stdlib/source/library/lux/target/jvm/constant/pool.lux b/stdlib/source/library/lux/target/jvm/constant/pool.lux index 6c85e6e61..d050b1e34 100644 --- a/stdlib/source/library/lux/target/jvm/constant/pool.lux +++ b/stdlib/source/library/lux/target/jvm/constant/pool.lux @@ -102,14 +102,14 @@ (-> Text (Resource (Index String))) (do ..monad [@value (utf8 value) - #let [value (//.string @value)]] + .let [value (//.string @value)]] (!add #//.String (//.value_equivalence //index.equivalence) value))) (def: #export (class name) (-> Internal (Resource (Index Class))) (do ..monad [@name (utf8 (//name.read name)) - #let [value (//.class @name)]] + .let [value (//.class @name)]] (!add #//.Class //.class_equivalence value))) (def: #export (descriptor value) diff --git a/stdlib/source/library/lux/target/jvm/method.lux b/stdlib/source/library/lux/target/jvm/method.lux index 6df81d091..a2868b2ac 100644 --- a/stdlib/source/library/lux/target/jvm/method.lux +++ b/stdlib/source/library/lux/target/jvm/method.lux @@ -68,7 +68,7 @@ (#try.Failure error) (function (_ _) (#try.Failure error))) [environment exceptions instruction output] (//bytecode.resolve environment code) - #let [bytecode (|> instruction //bytecode/instruction.run format.instance)] + .let [bytecode (|> instruction //bytecode/instruction.run format.instance)] @code (//attribute.code {#//attribute/code.limit (get@ #//bytecode/environment.limit environment) #//attribute/code.code bytecode #//attribute/code.exception_table exceptions diff --git a/stdlib/source/library/lux/target/jvm/reflection.lux b/stdlib/source/library/lux/target/jvm/reflection.lux index 086a394bb..6827f2be9 100644 --- a/stdlib/source/library/lux/target/jvm/reflection.lux +++ b/stdlib/source/library/lux/target/jvm/reflection.lux @@ -174,7 +174,7 @@ (do {! try.monad} [paramsT (|> reflection java/lang/reflect/ParameterizedType::getActualTypeArguments - array.to_list + array.list (monad.map ! parameter))] (in (/.class (|> raw (:as (java/lang/Class java/lang/Object)) @@ -297,7 +297,7 @@ (case type (#.Primitive name params) (let [class_name (java/lang/Class::getName class) - class_params (array.to_list (java/lang/Class::getTypeParameters class)) + class_params (array.list (java/lang/Class::getTypeParameters class)) num_class_params (list.size class_params) num_type_params (list.size params)] (if (text\= class_name name) @@ -360,7 +360,7 @@ (def: #export deprecated? (-> (array.Array java/lang/annotation/Annotation) Bit) - (|>> array.to_list + (|>> array.list (list.all (|>> (ffi.check java/lang/Deprecated))) list.empty? not)) @@ -370,7 +370,7 @@ (-> Text (java/lang/Class java/lang/Object) (Try [Bit Bit (/.Type Value)])) (do {! try.monad} [fieldJ (..field field class) - #let [modifiers (java/lang/reflect/Field::getModifiers fieldJ)]] + .let [modifiers (java/lang/reflect/Field::getModifiers fieldJ)]] (case (java/lang/reflect/Modifier::isStatic modifiers) <then?> (|> fieldJ java/lang/reflect/Field::getGenericType diff --git a/stdlib/source/library/lux/test.lux b/stdlib/source/library/lux/test.lux index e3007a55f..f37c0a3c9 100644 --- a/stdlib/source/library/lux/test.lux +++ b/stdlib/source/library/lux/test.lux @@ -142,7 +142,7 @@ (-> Text (Random Bit) Test) (random\map (..assertion message) random)) -(def: pcg32_magic_inc +(def: pcg_32_magic_inc Nat (hex "FEDCBA9876543210")) @@ -153,7 +153,7 @@ (def: #export (seed value test) (-> Seed Test Test) (function (_ prng) - (let [[_ result] (random.run (random.pcg32 [..pcg32_magic_inc value]) + (let [[_ result] (random.run (random.pcg_32 [..pcg_32_magic_inc value]) test)] [prng result]))) @@ -175,7 +175,7 @@ _ (do random.monad [seed random.nat] (function (recur prng) - (let [[prng' instance] (random.run (random.pcg32 [..pcg32_magic_inc seed]) test)] + (let [[prng' instance] (random.run (random.pcg_32 [..pcg_32_magic_inc seed]) test)] [prng' (do {! async.monad} [[tally documentation] instance] (if (..failed? tally) @@ -196,7 +196,7 @@ unexpected (set.difference (get@ #expected_coverage tally) (get@ #actual_coverage tally)) report (: (-> (Set Name) Text) - (|>> set.to_list + (|>> set.list (list.sort (\ name.order <)) (exception.listing %.name))) expected_definitions_to_cover (set.size (get@ #expected_coverage tally)) @@ -244,11 +244,11 @@ (-> Test (Async Nothing)) (do async.monad [pre (async.future instant.now) - #let [seed (instant.to_millis pre) - prng (random.pcg32 [..pcg32_magic_inc seed])] + .let [seed (instant.millis pre) + prng (random.pcg_32 [..pcg_32_magic_inc seed])] [tally documentation] (|> test (random.run prng) product.right) post (async.future instant.now) - #let [duration (instant.span pre post) + .let [duration (instant.span pre post) _ (debug.log! (format documentation text.new_line text.new_line (..description duration tally) text.new_line))]] @@ -353,9 +353,9 @@ (syntax: #export (covering {module <code>.identifier} test) (do meta.monad - [#let [module (name.module module)] + [.let [module (name.module module)] definitions (meta.definitions module) - #let [coverage (|> definitions + .let [coverage (|> definitions (list\fold (function (_ [short [exported? _]] aggregate) (if exported? (#.Item short aggregate) @@ -380,7 +380,7 @@ expected_tests (do random.monad [seed random.nat - #let [prng (random.pcg32 [..pcg32_magic_inc seed]) + .let [prng (random.pcg_32 [..pcg_32_magic_inc seed]) run! (: (-> Test Assertion) (|>> (random.run prng) product.right diff --git a/stdlib/source/library/lux/time.lux b/stdlib/source/library/lux/time.lux index 42b850964..c1ab45cd2 100644 --- a/stdlib/source/library/lux/time.lux +++ b/stdlib/source/library/lux/time.lux @@ -36,7 +36,7 @@ (def: limit Nat - (.nat (duration.to_millis duration.day))) + (.nat (duration.millis duration.day))) (exception: #export (time_exceeds_a_day {time Nat}) (exception.report @@ -92,7 +92,7 @@ (#try.Success (:abstraction milli_seconds)) (exception.except ..time_exceeds_a_day [milli_seconds]))) - (def: #export to_millis + (def: #export millis (-> Time Nat) (|>> :representation)) @@ -127,12 +127,12 @@ (def: #export parser (Parser Time) - (let [to_millis (: (-> Duration Nat) - (|>> duration.to_millis .nat)) - hour (to_millis duration.hour) - minute (to_millis duration.minute) - second (to_millis duration.second) - millis (to_millis duration.milli_second)] + (let [millis (: (-> Duration Nat) + (|>> duration.millis .nat)) + hour (millis duration.hour) + minute (millis duration.minute) + second (millis duration.second) + millis (millis duration.milli_second)] (do {! <>.monad} [utc_hour ..hour_parser _ (<text>.this ..separator) @@ -154,7 +154,7 @@ (text\compose "0" (n\encode value)) (n\encode value))) -(def: (adjust_negative space duration) +(def: (positive space duration) (-> Duration Duration Duration) (if (duration.negative? duration) (duration.merged space duration) @@ -176,7 +176,7 @@ (def: #export (clock time) (-> Time Clock) - (let [time (|> time ..to_millis .int duration.of_millis) + (let [time (|> time ..millis .int duration.of_millis) [hours time] [(duration.query duration.hour time) (duration.framed duration.hour time)] [minutes time] [(duration.query duration.minute time) (duration.framed duration.minute time)] [seconds millis] [(duration.query duration.second time) (duration.framed duration.second time)]] @@ -184,8 +184,8 @@ #minute (.nat minutes) #second (.nat seconds) #milli_second (|> millis - (..adjust_negative duration.second) - duration.to_millis + (..positive duration.second) + duration.millis .nat)})) (def: #export (time clock) @@ -195,7 +195,7 @@ (duration.up (get@ #minute clock) duration.minute) (duration.up (get@ #second clock) duration.second) (duration.of_millis (.int (get@ #milli_second clock)))) - duration.to_millis + duration.millis .nat ..of_millis)) diff --git a/stdlib/source/library/lux/time/date.lux b/stdlib/source/library/lux/time/date.lux index c634c8405..92d2a5199 100644 --- a/stdlib/source/library/lux/time/date.lux +++ b/stdlib/source/library/lux/time/date.lux @@ -72,15 +72,18 @@ #month Month #day Nat} - (def: #export (date year month day) + {#.doc (doc "A date specified as a year/month/day triplet.")} + + (def: #export (date year month day_of_month) + {#.doc (doc "A date, within the allowed limits.")} (-> Year Month Nat (Try Date)) - (if (..day_is_within_limits? year month day) + (if (..day_is_within_limits? year month day_of_month) (#try.Success (:abstraction {#year year #month month - #day day})) - (exception.except ..invalid_day [year month day]))) + #day day_of_month})) + (exception.except ..invalid_day [year month day_of_month]))) (def: #export epoch Date @@ -175,7 +178,7 @@ _ (<text>.this ..separator) utc_month ..month_parser _ (<text>.this ..separator) - #let [month (maybe.assume (dictionary.get utc_month ..month_by_number))] + .let [month (maybe.assume (dictionary.get utc_month ..month_by_number))] utc_day ..section_parser] (<>.lift (..date utc_year month utc_day)))) @@ -282,7 +285,7 @@ utc_year))) ## http://howardhinnant.github.io/date_algorithms.html -(def: #export (to_days date) +(def: #export (days date) (-> Date Int) (let [utc_month (|> date ..month //month.number) civil_year (..civil_year utc_month (..year date)) @@ -345,7 +348,7 @@ (def: &order ..order) (def: succ - (|>> ..to_days inc ..of_days)) + (|>> ..days inc ..of_days)) (def: pred - (|>> ..to_days dec ..of_days))) + (|>> ..days dec ..of_days))) diff --git a/stdlib/source/library/lux/time/day.lux b/stdlib/source/library/lux/time/day.lux index d5379cdc1..58bc46c1d 100644 --- a/stdlib/source/library/lux/time/day.lux +++ b/stdlib/source/library/lux/time/day.lux @@ -3,11 +3,12 @@ [lux (#- nat) [abstract [equivalence (#+ Equivalence)] + [hash (#+ Hash)] [order (#+ Order)] [enum (#+ Enum)] [codec (#+ Codec)]] [control - ["." try] + ["." try (#+ Try)] ["." exception (#+ exception:)]] [data ["." text]] @@ -18,6 +19,7 @@ ["n" nat]]]]]) (type: #export Day + {#.doc (doc "A day of the week.")} #Sunday #Monday #Tuesday @@ -119,3 +121,62 @@ [#..Saturday] [#..Sunday]) _ (exception.except ..not_a_day_of_the_week [value])))) + +(def: #export week + {#.doc (doc "All the days, ordered by when they come in a week.")} + (List Day) + (list #Sunday + #Monday + #Tuesday + #Wednesday + #Thursday + #Friday + #Saturday)) + +(with_expansions [<pairs> (as_is [01 #Sunday] + [02 #Monday] + [03 #Tuesday] + [04 #Wednesday] + [05 #Thursday] + [06 #Friday] + [07 #Saturday])] + (def: #export (number day) + (-> Day Nat) + (case day + (^template [<number> <day>] + [<day> <number>]) + (<pairs>))) + + (exception: #export (invalid_day {number Nat}) + (exception.report + ["Number" (\ n.decimal encode number)] + ["Valid range" ($_ "lux text concat" + (\ n.decimal encode (..number #Sunday)) + " ~ " + (\ n.decimal encode (..number #Saturday)))])) + + (def: #export (by_number number) + (-> Nat (Try Day)) + (case number + (^template [<number> <day>] + [<number> (#try.Success <day>)]) + (<pairs>) + _ (exception.except ..invalid_day [number]))) + ) + +(implementation: #export hash + (Hash Day) + + (def: &equivalence ..equivalence) + (def: (hash day) + (case day + (^template [<prime> <day>] + [<day> + <prime>]) + ([02 #Sunday] + [03 #Monday] + [05 #Tuesday] + [07 #Wednesday] + [11 #Thursday] + [13 #Friday] + [17 #Saturday])))) diff --git a/stdlib/source/library/lux/time/duration.lux b/stdlib/source/library/lux/time/duration.lux index c133b1045..ff9ad24d3 100644 --- a/stdlib/source/library/lux/time/duration.lux +++ b/stdlib/source/library/lux/time/duration.lux @@ -11,7 +11,7 @@ [control ["." try] ["<>" parser - ["<t>" text (#+ Parser)]]] + ["<.>" text (#+ Parser)]]] [data ["." text ("#\." monoid)]] [math @@ -32,7 +32,7 @@ (-> Int Duration) (|>> :abstraction)) - (def: #export to_millis + (def: #export millis (-> Duration Int) (|>> :representation)) @@ -144,7 +144,7 @@ [hours time_left] [(query hour time_left) (framed hour time_left)] [minutes time_left] [(query minute time_left) (framed minute time_left)] [seconds time_left] [(query second time_left) (framed second time_left)] - millis (to_millis time_left)] + millis (..millis time_left)] ($_ text\compose (if signed? ..negative_sign ..positive_sign) (if (i.= +0 days) "" (text\compose (nat\encode (.nat days)) ..day_suffix)) @@ -158,22 +158,22 @@ (Parser Duration) (let [section (: (-> Text Text (Parser Nat)) (function (_ suffix false_suffix) - (|> (<t>.many <t>.decimal) + (|> (<text>.many <text>.decimal) (<>.codec nat.decimal) (<>.before (case false_suffix - "" (<t>.this suffix) - _ (<>.after (<>.not (<t>.this false_suffix)) - (<t>.this suffix)))) + "" (<text>.this suffix) + _ (<>.after (<>.not (<text>.this false_suffix)) + (<text>.this suffix)))) (<>.else 0))))] (do <>.monad - [sign (<>.or (<t>.this ..negative_sign) - (<t>.this ..positive_sign)) + [sign (<>.or (<text>.this ..negative_sign) + (<text>.this ..positive_sign)) days (section ..day_suffix "") hours (section hour_suffix "") minutes (section ..minute_suffix ..milli_second_suffix) seconds (section ..second_suffix "") millis (section ..milli_second_suffix "") - #let [span (|> ..empty + .let [span (|> ..empty (..merged (..up days ..day)) (..merged (..up hours ..hour)) (..merged (..up minutes ..minute)) @@ -187,7 +187,7 @@ (Codec Text Duration) (def: encode ..encode) - (def: decode (<t>.run ..parser))) + (def: decode (<text>.run ..parser))) (def: #export (difference from to) (-> Duration Duration Duration) diff --git a/stdlib/source/library/lux/time/instant.lux b/stdlib/source/library/lux/time/instant.lux index c136a6e15..c89ffbd09 100644 --- a/stdlib/source/library/lux/time/instant.lux +++ b/stdlib/source/library/lux/time/instant.lux @@ -35,13 +35,13 @@ (abstract: #export Instant Int - {#.doc "Instant is defined as milliseconds since the epoch."} + {#.doc "Instant is defined as milli-seconds since the epoch."} (def: #export of_millis (-> Int Instant) (|>> :abstraction)) - (def: #export to_millis + (def: #export millis (-> Instant Int) (|>> :representation)) @@ -49,9 +49,9 @@ (-> Instant Instant Duration) (duration.of_millis (i.- (:representation from) (:representation to)))) - (def: #export (shift duration instant) + (def: #export (after duration instant) (-> Duration Instant Instant) - (:abstraction (i.+ (duration.to_millis duration) (:representation instant)))) + (:abstraction (i.+ (duration.millis duration) (:representation instant)))) (def: #export (relative instant) (-> Instant Duration) @@ -59,7 +59,7 @@ (def: #export (absolute offset) (-> Duration Instant) - (|> offset duration.to_millis :abstraction)) + (|> offset duration.millis :abstraction)) (implementation: #export equivalence (Equivalence Instant) @@ -87,16 +87,16 @@ ) (def: #export epoch - {#.doc "The instant corresponding to 1970-01-01T00:00:00Z"} + {#.doc "The instant corresponding to 1970-01-01T00:00:00Z."} Instant (..of_millis +0)) (def: millis_per_day (duration.query duration.milli_second duration.day)) -(def: (split_date_time instant) +(def: (date_time instant) (-> Instant [Date Duration]) - (let [offset (..to_millis instant) + (let [offset (..millis instant) bce? (i.< +0 offset) [days day_time] (if bce? (let [[days millis] (i./% ..millis_per_day offset)] @@ -119,14 +119,14 @@ (|> (if (\ duration.order < duration.empty duration) (duration.merged duration.day duration) duration) - duration.to_millis + duration.millis .nat //.of_millis try.assumed)) (def: (format instant) (-> Instant Text) - (let [[date time] (..split_date_time instant) + (let [[date time] (..date_time instant) time (..clock_time time)] ($_ text\compose (\ date.codec encode date) ..date_suffix @@ -135,9 +135,9 @@ (def: parser (Parser Instant) (do {! <>.monad} - [days (\ ! map date.to_days date.parser) + [days (\ ! map date.days date.parser) _ (<text>.this ..date_suffix) - time (\ ! map //.to_millis //.parser) + time (\ ! map //.millis //.parser) _ (<text>.this ..time_suffix)] (in (|> (if (i.< +0 days) (|> duration.day @@ -156,6 +156,7 @@ (def: decode (<text>.run ..parser))) (def: #export now + {#.doc (doc "Yields the current instant, as measured from the operating-system's clock.")} (IO Instant) (io (..of_millis (for {@.old ("jvm invokestatic:java.lang.System:currentTimeMillis:") @.jvm (|> ("jvm member invoke static" [] "java.lang.System" "currentTimeMillis" []) @@ -199,7 +200,7 @@ (template [<field> <type> <post_processing>] [(def: #export (<field> instant) (-> Instant <type>) - (let [[date time] (..split_date_time instant)] + (let [[date time] (..date_time instant)] (|> <field> <post_processing>)))] [date Date (|>)] @@ -232,7 +233,7 @@ (def: #export (of_date_time date time) (-> Date Time Instant) - (|> (date.to_days date) - (i.* (duration.to_millis duration.day)) - (i.+ (.int (//.to_millis time))) + (|> (date.days date) + (i.* (duration.millis duration.day)) + (i.+ (.int (//.millis time))) ..of_millis)) diff --git a/stdlib/source/library/lux/time/month.lux b/stdlib/source/library/lux/time/month.lux index 89dc069f2..d2e7fb0e0 100644 --- a/stdlib/source/library/lux/time/month.lux +++ b/stdlib/source/library/lux/time/month.lux @@ -19,6 +19,7 @@ ["n" nat]]]]]) (type: #export Month + {#.doc (doc "A month of the year.")} #January #February #March @@ -96,7 +97,23 @@ (Hash Month) (def: &equivalence ..equivalence) - (def: hash ..number)) + (def: (hash month) + (case month + (^template [<prime> <month>] + [<month> + <prime>]) + ([02 #January] + [03 #February] + [05 #March] + [07 #April] + [11 #May] + [13 #June] + [17 #July] + [19 #August] + [23 #September] + [29 #October] + [31 #November] + [37 #December])))) (implementation: #export order (Order Month) @@ -142,6 +159,7 @@ #January #December))) (def: #export (days month) + {#.doc (doc "The amount of days of a month.")} (-> Month Nat) (case month (^template [<days> <month>] @@ -163,12 +181,14 @@ [31 #December]))) (def: #export (leap_year_days month) + {#.doc (doc "The amount of days of a month (in a leap year).")} (-> Month Nat) (case month #February (inc (..days month)) _ (..days month))) (def: #export year + {#.doc (doc "All the months, ordered by when they come in a year.")} (List Month) (list #January #February diff --git a/stdlib/source/library/lux/tool/compiler/default/init.lux b/stdlib/source/library/lux/tool/compiler/default/init.lux index ecd883cfe..898f0edd3 100644 --- a/stdlib/source/library/lux/tool/compiler/default/init.lux +++ b/stdlib/source/library/lux/tool/compiler/default/init.lux @@ -125,13 +125,13 @@ (///directive.Operation anchor expression directive [Source (Payload directive)]))) (do ///phase.monad - [#let [module (get@ #///.module input)] + [.let [module (get@ #///.module input)] _ (///directive.set_current_module module)] (///directive.lift_analysis (do {! ///phase.monad} [_ (module.create hash module) _ (monad.map ! module.import dependencies) - #let [source (///analysis.source (get@ #///.module input) (get@ #///.code input))] + .let [source (///analysis.source (get@ #///.module input) (get@ #///.code input))] _ (///analysis.set_source_code source)] (in [source [///generation.empty_buffer artifact.empty]]))))) @@ -176,7 +176,7 @@ (///directive.Operation anchor expression directive [Requirements (Payload directive)])))) (do ///phase.monad - [#let [[pre_buffer pre_registry] pre_payoad] + [.let [[pre_buffer pre_registry] pre_payoad] _ (///directive.lift_generation (///generation.set_buffer pre_buffer)) _ (///directive.lift_generation @@ -238,10 +238,10 @@ {#///.dependencies dependencies #///.process (function (_ state archive) (do {! try.monad} - [#let [hash (text\hash (get@ #///.code input))] + [.let [hash (text\hash (get@ #///.code input))] [state [source buffer]] (<| (///phase.run' state) (..begin dependencies hash input)) - #let [module (get@ #///.module input)]] + .let [module (get@ #///.module input)]] (loop [iteration (<| (///phase.run' state) (..iteration archive expander module source buffer ///syntax.no_aliases))] (do ! @@ -250,7 +250,7 @@ #.None (do ! [[state [analysis_module [final_buffer final_registry]]] (///phase.run' state (..end module)) - #let [descriptor {#descriptor.hash hash + .let [descriptor {#descriptor.hash hash #descriptor.name module #descriptor.file (get@ #///.file input) #descriptor.references (set.of_list text.hash dependencies) diff --git a/stdlib/source/library/lux/tool/compiler/default/platform.lux b/stdlib/source/library/lux/tool/compiler/default/platform.lux index 8a3f17237..9e54b2522 100644 --- a/stdlib/source/library/lux/tool/compiler/default/platform.lux +++ b/stdlib/source/library/lux/tool/compiler/default/platform.lux @@ -104,12 +104,12 @@ (do {! ..monad} [_ (ioW.prepare system static module_id) _ (for {@.python (|> output - row.to_list + row.list (list.chunk 128) (monad.map ! (monad.map ! write_artifact!)) (: (Action (List (List Any)))))} (|> output - row.to_list + row.list (monad.map ..monad write_artifact!) (: (Action (List Any))))) document (\ async.monad in @@ -152,7 +152,7 @@ (do ///phase.monad [[registry payload] (///directive.lift_generation (..compile_runtime! platform)) - #let [[descriptor document] [(..runtime_descriptor registry) ..runtime_document]] + .let [[descriptor document] [(..runtime_descriptor registry) ..runtime_document]] archive (///phase.lift (if (archive.reserved? archive archive.runtime_module) (archive.add archive.runtime_module [descriptor document payload] archive) (do try.monad @@ -236,7 +236,7 @@ Import (List Context) (Async (Try [<State+> Archive])))) (do {! (try.with async.monad)} - [#let [state (//init.state (get@ #static.host static) + [.let [state (//init.state (get@ #static.host static) module expander host_analysis @@ -245,7 +245,7 @@ generation_bundle)] _ (ioW.enable (get@ #&file_system platform) static) [archive analysis_state bundles] (ioW.thaw (get@ #host platform) (get@ #&file_system platform) static import compilation_sources) - #let [with_missing_extensions + .let [with_missing_extensions (: (All [<type_vars>] (-> <Platform> (Program expression directive) <State+> (Async (Try <State+>)))) (function (_ platform program state) @@ -333,7 +333,7 @@ (list\fold (function (_ previous) (dictionary.upsert previous ..empty (set.add target))) with_dependence+transitives - (set.to_list backward))))))] + (set.list backward))))))] (|> dependence (update@ #depends_on (update_dependence @@ -370,7 +370,7 @@ {duplicates (Set Module)}) (exception.report ["Importer" (%.text importer)] - ["Duplicates" (%.list %.text (set.to_list duplicates))])) + ["Duplicates" (%.list %.text (set.list duplicates))])) (def: (verify_dependencies importer importee dependence) (-> Module Module Dependence (Try Any)) @@ -448,7 +448,7 @@ (#try.Success [module_id archive]) (do ! [_ (stm.write [archive state] current) - #let [[return signal] (:sharing [<type_vars>] + .let [[return signal] (:sharing [<type_vars>] <Context> initial @@ -496,7 +496,7 @@ lux_module (document.read $.key document)] (in [module lux_module]))) (archive.archived archive)) - #let [additions (|> modules + .let [additions (|> modules (list\map product.left) (set.of_list text.hash))]] (in (update@ [#extension.state @@ -538,7 +538,7 @@ context (function (_ importer import! module_id [archive state] module) (do {! (try.with async.monad)} - [#let [state (..set_current_module module state)] + [.let [state (..set_current_module module state)] input (context.read (get@ #&file_system platform) importer import @@ -550,7 +550,7 @@ all_dependencies (: (Set Module) (set.of_list text.hash (list)))] (do ! - [#let [new_dependencies (get@ #///.dependencies compilation) + [.let [new_dependencies (get@ #///.dependencies compilation) continue! (:sharing [<type_vars>] <Platform> platform @@ -583,7 +583,7 @@ [archive,document+ (|> new_dependencies (list\map (import! module)) (monad.seq ..monad)) - #let [archive (|> archive,document+ + .let [archive (|> archive,document+ (list\map product.left) (list\fold archive.merged archive))]] (in [archive (try.assumed @@ -604,7 +604,7 @@ (#.Right [descriptor document output]) (do ! - [#let [_ (debug.log! (..module_compilation_log module state)) + [.let [_ (debug.log! (..module_compilation_log module state)) descriptor (set@ #descriptor.references all_dependencies descriptor)] _ (..cache_module static platform module_id [descriptor document output])] (case (archive.add module [descriptor document output] archive) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux index fe7de804f..7f539ae4e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case.lux @@ -291,7 +291,7 @@ [idx group variantT] (///extension.lift (meta.tag tag)) _ (//type.with_env (check.check inputT variantT)) - #let [[lefts right?] (/.choice (list.size group) idx)]] + .let [[lefts right?] (/.choice (list.size group) idx)]] (analyse_pattern (#.Some (list.size group)) inputT (` ((~ (code.nat lefts)) (~ (code.bit right?)) (~+ values))) next))) _ diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux index a0d02badc..91052853b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/case/coverage.lux @@ -145,7 +145,7 @@ (#/.Complex (#/.Variant [lefts right? value])) (do ////.monad [value_coverage (determine value) - #let [idx (if right? + .let [idx (if right? (inc lefts) lefts)]] (in (#Variant (if right? @@ -324,7 +324,7 @@ ## merges can be done. [_ (#Alt leftS rightS)] (do {! try.monad} - [#let [fuse_once (: (-> Coverage (List Coverage) + [.let [fuse_once (: (-> Coverage (List Coverage) (Try [(Maybe Coverage) (List Coverage)])) (function (_ coverageA possibilitiesSF) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux index d50f72630..0ebfb304f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/function.lux @@ -81,7 +81,7 @@ (do ! [[input_id inputT] (//type.with_env check.var) [output_id outputT] (//type.with_env check.var) - #let [functionT (#.Function inputT outputT)] + .let [functionT (#.Function inputT outputT)] functionA (recur functionT) _ (//type.with_env (check.check expectedT functionT))] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux index e9e68deb3..3ccfd3551 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/scope.lux @@ -190,7 +190,7 @@ #.End (exception.except ..cannot_get_next_reference_when_there_is_no_scope []))))) -(def: (ref_to_variable ref) +(def: (ref_variable ref) (-> Ref Variable) (case ref (#.Local register) @@ -203,4 +203,4 @@ (-> Scope (List Variable)) (|> scope (get@ [#.captured #.mappings]) - (list\map (function (_ [_ [_ ref]]) (ref_to_variable ref))))) + (list\map (function (_ [_ [_ ref]]) (ref_variable ref))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux index 1a787efec..5e3717c5b 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/analysis/structure.lux @@ -264,7 +264,7 @@ (do {! ///.monad} [tag (///extension.lift (meta.normal tag)) [idx group variantT] (///extension.lift (meta.tag tag)) - #let [case_size (list.size group) + .let [case_size (list.size group) [lefts right?] (/.choice case_size idx)] expectedT (///extension.lift meta.expected_type)] (case expectedT @@ -309,12 +309,12 @@ (do {! ///.monad} [head_k (///extension.lift (meta.normal head_k)) [_ tag_set recordT] (///extension.lift (meta.tag head_k)) - #let [size_record (list.size record) + .let [size_record (list.size record) size_ts (list.size tag_set)] _ (if (n.= size_ts size_record) (in []) (/.except ..record_size_mismatch [size_ts size_record recordT record])) - #let [tuple_range (list.indices size_ts) + .let [tuple_range (list.indices size_ts) tag->idx (dictionary.of_list name.hash (list.zipped/2 tag_set tuple_range))] idx->val (monad.fold ! (function (_ [key val] idx->val) @@ -331,7 +331,7 @@ (: (Dictionary Nat Code) (dictionary.empty n.hash)) record) - #let [ordered_tuple (list\map (function (_ idx) (maybe.assume (dictionary.get idx idx->val))) + .let [ordered_tuple (list\map (function (_ idx) (maybe.assume (dictionary.get idx idx->val))) tuple_range)]] (in [ordered_tuple recordT])) )) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux index 64a9b36b0..a0c430e81 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/js.lux @@ -196,7 +196,7 @@ [($_ <>.and <c>.nat <c>.any) (function (_ extension phase archive [arity abstractionC]) (do phase.monad - [#let [inputT (type.tuple (list.repeat arity Any))] + [.let [inputT (type.tuple (list.repeat arity Any))] abstractionA (analysis/type.with_type (-> inputT Any) (phase archive abstractionC)) _ (analysis/type.infer (for {@.js ffi.Function} diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux index 8d38f4754..87dca360f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/jvm.lux @@ -859,30 +859,30 @@ [reflection_return Return luxT.return] ) -(def: (class_candidate_parents class_loader from_name fromT to_name to_class) +(def: (class_candidate_parents class_loader source_name fromT target_name target_class) (-> java/lang/ClassLoader External .Type External (java/lang/Class java/lang/Object) (Operation (List [[Text .Type] Bit]))) (do {! phase.monad} - [from_class (phase.lift (reflection!.load class_loader from_name)) - mapping (phase.lift (reflection!.correspond from_class fromT))] + [source_class (phase.lift (reflection!.load class_loader source_name)) + mapping (phase.lift (reflection!.correspond source_class fromT))] (monad.map ! (function (_ superJT) (do ! [superJT (phase.lift (reflection!.type superJT)) - #let [super_name (|> superJT ..reflection)] + .let [super_name (|> superJT ..reflection)] super_class (phase.lift (reflection!.load class_loader super_name)) superT (reflection_type mapping superJT)] - (in [[super_name superT] (java/lang/Class::isAssignableFrom super_class to_class)]))) - (case (java/lang/Class::getGenericSuperclass from_class) + (in [[super_name superT] (java/lang/Class::isAssignableFrom super_class target_class)]))) + (case (java/lang/Class::getGenericSuperclass source_class) (#.Some super) - (list& super (array.to_list (java/lang/Class::getGenericInterfaces from_class))) + (list& super (array.list (java/lang/Class::getGenericInterfaces source_class))) #.None - (if (java/lang/reflect/Modifier::isInterface (java/lang/Class::getModifiers from_class)) + (if (java/lang/reflect/Modifier::isInterface (java/lang/Class::getModifiers source_class)) (#.Item (:as java/lang/reflect/Type (ffi.class_for java/lang/Object)) - (array.to_list (java/lang/Class::getGenericInterfaces from_class))) - (array.to_list (java/lang/Class::getGenericInterfaces from_class))))))) + (array.list (java/lang/Class::getGenericInterfaces source_class))) + (array.list (java/lang/Class::getGenericInterfaces source_class))))))) -(def: (inheritance_candidate_parents class_loader fromT to_class toT fromC) +(def: (inheritance_candidate_parents class_loader fromT target_class toT fromC) (-> java/lang/ClassLoader .Type (java/lang/Class java/lang/Object) .Type Code (Operation (List [[Text .Type] Bit]))) (case fromT (^ (#.Primitive _ (list& self_classT super_classT super_interfacesT+))) @@ -892,7 +892,7 @@ [super_name (\ ! map ..reflection (check_jvm superT)) super_class (phase.lift (reflection!.load class_loader super_name))] (in [[super_name superT] - (java/lang/Class::isAssignableFrom super_class to_class)]))) + (java/lang/Class::isAssignableFrom super_class target_class)]))) (list& super_classT super_interfacesT+)) _ @@ -905,18 +905,18 @@ (^ (list fromC)) (do {! phase.monad} [toT (///.lift meta.expected_type) - to_name (\ ! map ..reflection (check_jvm toT)) + target_name (\ ! map ..reflection (check_jvm toT)) [fromT fromA] (typeA.with_inference (analyse archive fromC)) - from_name (\ ! map ..reflection (check_jvm fromT)) + source_name (\ ! map ..reflection (check_jvm fromT)) can_cast? (: (Operation Bit) (`` (cond (~~ (template [<primitive> <object>] [(let [=primitive (reflection.reflection <primitive>)] - (or (and (text\= =primitive from_name) - (or (text\= <object> to_name) - (text\= =primitive to_name))) - (and (text\= <object> from_name) - (text\= =primitive to_name)))) + (or (and (text\= =primitive source_name) + (or (text\= <object> target_name) + (text\= =primitive target_name))) + (and (text\= <object> source_name) + (text\= =primitive target_name)))) (in true)] [reflection.boolean box.boolean] @@ -930,25 +930,25 @@ ## else (do ! - [_ (phase.assertion ..primitives_are_not_objects [from_name] - (not (dictionary.key? ..boxes from_name))) - _ (phase.assertion ..primitives_are_not_objects [to_name] - (not (dictionary.key? ..boxes to_name))) - to_class (phase.lift (reflection!.load class_loader to_name)) - _ (if (text\= ..inheritance_relationship_type_name from_name) + [_ (phase.assertion ..primitives_are_not_objects [source_name] + (not (dictionary.key? ..boxes source_name))) + _ (phase.assertion ..primitives_are_not_objects [target_name] + (not (dictionary.key? ..boxes target_name))) + target_class (phase.lift (reflection!.load class_loader target_name)) + _ (if (text\= ..inheritance_relationship_type_name source_name) (in []) (do ! - [from_class (phase.lift (reflection!.load class_loader from_name))] + [source_class (phase.lift (reflection!.load class_loader source_name))] (phase.assertion ..cannot_cast [fromT toT fromC] - (java/lang/Class::isAssignableFrom from_class to_class))))] - (loop [[current_name currentT] [from_name fromT]] - (if (text\= to_name current_name) + (java/lang/Class::isAssignableFrom source_class target_class))))] + (loop [[current_name currentT] [source_name fromT]] + (if (text\= target_name current_name) (in true) (do ! [candidate_parents (: (Operation (List [[Text .Type] Bit])) (if (text\= ..inheritance_relationship_type_name current_name) - (inheritance_candidate_parents class_loader currentT to_class toT fromC) - (class_candidate_parents class_loader current_name currentT to_name to_class)))] + (inheritance_candidate_parents class_loader currentT target_class toT fromC) + (class_candidate_parents class_loader current_name currentT target_name target_class)))] (case (|> candidate_parents (list.only product.right) (list\map product.left)) @@ -958,8 +958,8 @@ #.End (in false)))))))))] (if can_cast? - (in (#/////analysis.Extension extension_name (list (/////analysis.text from_name) - (/////analysis.text to_name) + (in (#/////analysis.Extension extension_name (list (/////analysis.text source_name) + (/////analysis.text target_name) fromA))) (/////analysis.except ..cannot_cast [fromT toT fromC]))) @@ -1089,10 +1089,10 @@ (-> Aliasing (java/lang/Class java/lang/Object) Text Method_Style (List (Type Value)) java/lang/reflect/Method (Operation Bit)) (do phase.monad [parameters (|> (java/lang/reflect/Method::getGenericParameterTypes method) - array.to_list + array.list (monad.map try.monad reflection!.type) phase.lift) - #let [modifiers (java/lang/reflect/Method::getModifiers method) + .let [modifiers (java/lang/reflect/Method::getModifiers method) correct_class? (java/lang/Object::equals class (java/lang/reflect/Method::getDeclaringClass method)) correct_method? (text\= method_name (java/lang/reflect/Method::getName method)) static_matches? (case method_style @@ -1135,7 +1135,7 @@ (-> Aliasing (java/lang/Class java/lang/Object) (List (Type Value)) (java/lang/reflect/Constructor java/lang/Object) (Operation Bit)) (do phase.monad [parameters (|> (java/lang/reflect/Constructor::getGenericParameterTypes constructor) - array.to_list + array.list (monad.map try.monad reflection!.type) phase.lift)] (in (and (java/lang/Object::equals class (java/lang/reflect/Constructor::getDeclaringClass constructor)) @@ -1155,7 +1155,7 @@ true (list.zipped/2 parameters inputsJT)))))) -(def: idx_to_parameter +(def: index_parameter (-> Nat .Type) (|>> (n.* 2) inc #.Parameter)) @@ -1166,7 +1166,7 @@ list.reversed list.enumeration (list\map (function (_ [idx name]) - [name (idx_to_parameter idx)])) + [name (index_parameter idx)])) list.reversed) num_owner_tvars (list.size owner_tvars) owner_tvarsT (|> lux_tvars (list.take num_owner_tvars) (list\map product.right)) @@ -1182,15 +1182,15 @@ _ (|> (java/lang/Class::getTypeParameters owner) - array.to_list + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName)))) method_tvars (|> (java/lang/reflect/Method::getTypeParameters method) - array.to_list + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName))) [owner_tvarsT mapping] (jvm_type_var_mapping owner_tvars method_tvars)] (do {! phase.monad} [inputsT (|> (java/lang/reflect/Method::getGenericParameterTypes method) - array.to_list + array.list (monad.map ! (|>> reflection!.type phase.lift)) (phase\map (monad.map ! (..reflection_type mapping))) phase\join) @@ -1201,11 +1201,11 @@ (phase\map (..reflection_return mapping)) phase\join) exceptionsT (|> (java/lang/reflect/Method::getGenericExceptionTypes method) - array.to_list + array.list (monad.map ! (|>> reflection!.type phase.lift)) (phase\map (monad.map ! (..reflection_type mapping))) phase\join) - #let [methodT (<| (type.univ_q (dictionary.size mapping)) + .let [methodT (<| (type.univ_q (dictionary.size mapping)) (type.function (case method_style #Static inputsT @@ -1222,24 +1222,24 @@ (-> (java/lang/reflect/Constructor java/lang/Object) (Operation Method_Signature)) (let [owner (java/lang/reflect/Constructor::getDeclaringClass constructor) owner_tvars (|> (java/lang/Class::getTypeParameters owner) - array.to_list + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName))) method_tvars (|> (java/lang/reflect/Constructor::getTypeParameters constructor) - array.to_list + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName))) [owner_tvarsT mapping] (jvm_type_var_mapping owner_tvars method_tvars)] (do {! phase.monad} [inputsT (|> (java/lang/reflect/Constructor::getGenericParameterTypes constructor) - array.to_list + array.list (monad.map ! (|>> reflection!.type phase.lift)) (phase\map (monad.map ! (reflection_type mapping))) phase\join) exceptionsT (|> (java/lang/reflect/Constructor::getGenericExceptionTypes constructor) - array.to_list + array.list (monad.map ! (|>> reflection!.type phase.lift)) (phase\map (monad.map ! (reflection_type mapping))) phase\join) - #let [objectT (#.Primitive (java/lang/Class::getName owner) owner_tvarsT) + .let [objectT (#.Primitive (java/lang/Class::getName owner) owner_tvarsT) constructorT (<| (type.univ_q (dictionary.size mapping)) (type.function inputsT) objectT)]] @@ -1268,7 +1268,7 @@ [(def: <name> (-> <type> (List (Type Var))) (|>> <method> - array.to_list + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName jvm.var))))] [class_type_variables (java/lang/Class java/lang/Object) java/lang/Class::getTypeParameters] @@ -1286,15 +1286,15 @@ (-> java/lang/ClassLoader (List (Type Var)) External (List (Type Var)) Text Method_Style (List (Type Value)) (Operation Method_Signature)) (do {! phase.monad} [class (phase.lift (reflection!.load class_loader class_name)) - #let [expected_class_tvars (class_type_variables class)] + .let [expected_class_tvars (class_type_variables class)] candidates (|> class java/lang/Class::getDeclaredMethods - array.to_list + array.list (list.only (|>> java/lang/reflect/Method::getName (text\= method_name))) (monad.map ! (: (-> java/lang/reflect/Method (Operation Evaluation)) (function (_ method) (do ! - [#let [expected_method_tvars (method_type_variables method) + [.let [expected_method_tvars (method_type_variables method) aliasing (dictionary.merged (..aliasing expected_class_tvars actual_class_tvars) (..aliasing expected_method_tvars actual_method_tvars))] passes? (check_method aliasing class method_name method_style inputsJT method)] @@ -1319,13 +1319,13 @@ (-> java/lang/ClassLoader (List (Type Var)) External (List (Type Var)) (List (Type Value)) (Operation Method_Signature)) (do {! phase.monad} [class (phase.lift (reflection!.load class_loader class_name)) - #let [expected_class_tvars (class_type_variables class)] + .let [expected_class_tvars (class_type_variables class)] candidates (|> class java/lang/Class::getConstructors - array.to_list + array.list (monad.map ! (function (_ constructor) (do ! - [#let [expected_method_tvars (constructor_type_variables constructor) + [.let [expected_method_tvars (constructor_type_variables constructor) aliasing (dictionary.merged (..aliasing expected_class_tvars actual_class_tvars) (..aliasing expected_method_tvars actual_method_tvars))] passes? (check_constructor aliasing class inputsJT constructor)] @@ -1374,7 +1374,7 @@ (function (_ extension_name analyse archive [class_tvars [class method] method_tvars argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_loader class) - #let [argsT (list\map product.left argsTC)] + .let [argsT (list\map product.left argsTC)] [methodT deprecated? exceptionsT] (..method_candidate class_loader class_tvars class method_tvars method #Static argsT) _ (phase.assertion ..deprecated_method [class method methodT] (not deprecated?)) @@ -1392,12 +1392,12 @@ (function (_ extension_name analyse archive [class_tvars [class method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_loader class) - #let [argsT (list\map product.left argsTC)] + .let [argsT (list\map product.left argsTC)] [methodT deprecated? exceptionsT] (..method_candidate class_loader class_tvars class method_tvars method #Virtual argsT) _ (phase.assertion ..deprecated_method [class method methodT] (not deprecated?)) [outputT allA] (inferenceA.general archive analyse methodT (list& objectC (list\map product.right argsTC))) - #let [[objectA argsA] (case allA + .let [[objectA argsA] (case allA (#.Item objectA argsA) [objectA argsA] @@ -1417,7 +1417,7 @@ (function (_ extension_name analyse archive [class_tvars [class method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_loader class) - #let [argsT (list\map product.left argsTC)] + .let [argsT (list\map product.left argsTC)] [methodT deprecated? exceptionsT] (..method_candidate class_loader class_tvars class method_tvars method #Special argsT) _ (phase.assertion ..deprecated_method [class method methodT] (not deprecated?)) @@ -1435,7 +1435,7 @@ (function (_ extension_name analyse archive [class_tvars [class_name method] method_tvars objectC argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_loader class_name) - #let [argsT (list\map product.left argsTC)] + .let [argsT (list\map product.left argsTC)] class (phase.lift (reflection!.load class_loader class_name)) _ (phase.assertion non_interface class_name (java/lang/reflect/Modifier::isInterface (java/lang/Class::getModifiers class))) @@ -1443,7 +1443,7 @@ _ (phase.assertion ..deprecated_method [class_name method methodT] (not deprecated?)) [outputT allA] (inferenceA.general archive analyse methodT (list& objectC (list\map product.right argsTC))) - #let [[objectA argsA] (case allA + .let [[objectA argsA] (case allA (#.Item objectA argsA) [objectA argsA] @@ -1464,7 +1464,7 @@ (function (_ extension_name analyse archive [class_tvars class method_tvars argsTC]) (do phase.monad [_ (..ensure_fresh_class! class_loader class) - #let [argsT (list\map product.left argsTC)] + .let [argsT (list\map product.left argsTC)] [methodT deprecated? exceptionsT] (..constructor_candidate class_loader class_tvars class method_tvars argsT) _ (phase.assertion ..deprecated_method [class ..constructor_method methodT] (not deprecated?)) @@ -1547,23 +1547,23 @@ (-> (java/lang/Class java/lang/Object) (Try (List [Text (Type Method)]))) (|>> java/lang/Class::getDeclaredMethods - array.to_list + array.list <only> (monad.map try.monad (function (_ method) (do {! try.monad} - [#let [type_variables (|> (java/lang/reflect/Method::getTypeParameters method) - array.to_list + [.let [type_variables (|> (java/lang/reflect/Method::getTypeParameters method) + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName jvm.var)))] inputs (|> (java/lang/reflect/Method::getGenericParameterTypes method) - array.to_list + array.list (monad.map ! reflection!.type)) return (|> method java/lang/reflect/Method::getGenericReturnType reflection!.return) exceptions (|> (java/lang/reflect/Method::getGenericExceptionTypes method) - array.to_list + array.list (monad.map ! reflection!.class))] (in [(java/lang/reflect/Method::getName method) (jvm.method [type_variables inputs return exceptions])]))))))] @@ -2059,10 +2059,10 @@ (def: (super_aliasing class_loader class) (-> java/lang/ClassLoader (Type Class) (Operation Aliasing)) (do phase.monad - [#let [[name actual_parameters] (jvm_parser.read_class class)] + [.let [[name actual_parameters] (jvm_parser.read_class class)] class (phase.lift (reflection!.load class_loader name)) - #let [expected_parameters (|> (java/lang/Class::getTypeParameters class) - array.to_list + .let [expected_parameters (|> (java/lang/Class::getTypeParameters class) + array.list (list\map (|>> java/lang/reflect/TypeVariable::getName)))] _ (phase.assertion ..class_parameter_mismatch [expected_parameters actual_parameters] (n.= (list.size expected_parameters) @@ -2100,7 +2100,7 @@ exceptions]) (jvm_alias.method aliasing))]))) methods) - #let [missing_abstract_methods (mismatched_methods overriden_methods required_abstract_methods) + .let [missing_abstract_methods (mismatched_methods overriden_methods required_abstract_methods) invalid_overriden_methods (mismatched_methods available_methods overriden_methods)] _ (phase.assertion ..missing_abstract_methods missing_abstract_methods (list.empty? missing_abstract_methods)) @@ -2127,7 +2127,7 @@ _ (monad.map ! (|>> ..reflection (..ensure_fresh_class! class_loader)) super_interfaces) parameters (typeA.with_env (..parameter_types parameters)) - #let [mapping (list\fold (function (_ [parameterJ parameterT] mapping) + .let [mapping (list\fold (function (_ [parameterJ parameterT] mapping) (dictionary.put (jvm_parser.name parameterJ) parameterT mapping)) @@ -2153,7 +2153,7 @@ (analyse archive term))] (in [type termA]))) constructor_args) - #let [supers (#.Item super_class super_interfaces)] + .let [supers (#.Item super_class super_interfaces)] _ (..require_complete_method_concretion class_loader supers methods) methodsA (monad.map ! (analyse_overriden_method analyse archive selfT mapping supers) methods)] (in (#/////analysis.Extension extension_name diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux index 923880ebd..50c8dfe2a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/lua.lux @@ -228,7 +228,7 @@ [($_ <>.and <code>.nat <code>.any) (function (_ extension phase archive [arity abstractionC]) (do phase.monad - [#let [inputT (type.tuple (list.repeat arity Any))] + [.let [inputT (type.tuple (list.repeat arity Any))] abstractionA (analysis/type.with_type (-> inputT Any) (phase archive abstractionC)) _ (analysis/type.infer ..Function)] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux index b5a81bc65..00a5a803a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/analysis/python.lux @@ -196,7 +196,7 @@ [($_ <>.and <code>.nat <code>.any) (function (_ extension phase archive [arity abstractionC]) (do phase.monad - [#let [inputT (type.tuple (list.repeat arity Any))] + [.let [inputT (type.tuple (list.repeat arity Any))] abstractionA (analysis/type.with_type (-> inputT Any) (phase archive abstractionC)) _ (analysis/type.infer ..Function)] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux index a3265adb0..446c63e08 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/jvm.lux @@ -263,7 +263,7 @@ [parameters (directive.lift_analysis (typeA.with_env (jvm.parameter_types parameters))) - #let [mapping (list\fold (function (_ [parameterJ parameterT] mapping) + .let [mapping (list\fold (function (_ [parameterJ parameterT] mapping) (dictionary.put (parser.name parameterJ) parameterT mapping)) luxT.fresh parameters)] @@ -275,11 +275,11 @@ (monad.map check.monad (|>> ..signature (luxT.check (luxT.class mapping))) super_interfaces))) - #let [selfT (jvm.inheritance_relationship_type (#.Primitive name (list\map product.right parameters)) + .let [selfT (jvm.inheritance_relationship_type (#.Primitive name (list\map product.right parameters)) super_classT super_interfaceT+)] state (extension.lift phase.get_state) - #let [analyse (get@ [#directive.analysis #directive.phase] state) + .let [analyse (get@ [#directive.analysis #directive.phase] state) synthesize (get@ [#directive.synthesis #directive.phase] state) generate (get@ [#directive.generation #directive.phase] state)] methods (monad.map ! (..method_definition [mapping selfT] [analyse synthesize generate]) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux index d12359d68..ce82ca51e 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/directive/lux.lux @@ -88,7 +88,7 @@ (-> Archive Type Code (Operation anchor expression directive [Type expression Any]))) (do phase.monad [state (///.lift phase.get_state) - #let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) + .let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) synthesize (get@ [#/////directive.synthesis #/////directive.phase] state) generate (get@ [#/////directive.generation #/////directive.phase] state)] [_ codeA] (/////directive.lift_analysis @@ -124,7 +124,7 @@ (Operation anchor expression directive [Type expression Any]))) (do {! phase.monad} [state (///.lift phase.get_state) - #let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) + .let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) synthesize (get@ [#/////directive.synthesis #/////directive.phase] state) generate (get@ [#/////directive.generation #/////directive.phase] state)] [_ code//type codeA] (/////directive.lift_analysis @@ -176,7 +176,7 @@ (Operation anchor expression directive [expression Any]))) (do phase.monad [state (///.lift phase.get_state) - #let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) + .let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) synthesize (get@ [#/////directive.synthesis #/////directive.phase] state) generate (get@ [#/////directive.generation #/////directive.phase] state)] [_ codeA] (/////directive.lift_analysis @@ -199,7 +199,7 @@ (-> Expander /////analysis.Bundle (Operation anchor expression directive Any))) (do phase.monad [[bundle state] phase.get_state - #let [eval (/////analysis/evaluation.evaluator expander + .let [eval (/////analysis/evaluation.evaluator expander (get@ [#/////directive.synthesis #/////directive.state] state) (get@ [#/////directive.generation #/////directive.state] state) (get@ [#/////directive.generation #/////directive.phase] state))]] @@ -224,7 +224,7 @@ (do phase.monad [current_module (/////directive.lift_analysis (///.lift meta.current_module_name)) - #let [full_name [current_module short_name]] + .let [full_name [current_module short_name]] [type valueT value] (..definition archive full_name #.None valueC) [_ annotationsT annotations] (evaluate! archive Code annotationsC) _ (/////directive.lift_analysis @@ -244,9 +244,9 @@ (do phase.monad [current_module (/////directive.lift_analysis (///.lift meta.current_module_name)) - #let [full_name [current_module short_name]] + .let [full_name [current_module short_name]] [_ annotationsT annotations] (evaluate! archive Code annotationsC) - #let [annotations (:as Code annotations)] + .let [annotations (:as Code annotations)] [type valueT value] (..definition archive full_name (#.Some .Type) valueC) _ (/////directive.lift_analysis (do phase.monad @@ -269,7 +269,7 @@ (function (_ extension_name phase archive [annotationsC imports]) (do {! phase.monad} [[_ annotationsT annotationsV] (evaluate! archive Code annotationsC) - #let [annotationsV (:as Code annotationsV)] + .let [annotationsV (:as Code annotationsV)] _ (/////directive.lift_analysis (do ! [_ (monad.map ! (function (_ [module alias]) @@ -403,7 +403,7 @@ (^ (list programC)) (do phase.monad [state (///.lift phase.get_state) - #let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) + .let [analyse (get@ [#/////directive.analysis #/////directive.phase] state) synthesize (get@ [#/////directive.synthesis #/////directive.phase] state) generate (get@ [#/////directive.generation #/////directive.phase] state)] programS (prepare_program archive analyse synthesize programC) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux index 33267e376..240bec8b5 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/common.lux @@ -50,7 +50,7 @@ (template [<name> <op>] [(def: (<name> [paramG subjectG]) (Binary Expression) - (<op> subjectG (//runtime.i64//to_number paramG)))] + (<op> subjectG (//runtime.i64//number paramG)))] [i64//left_shifted //runtime.i64//left_shifted] [i64//right_shifted //runtime.i64//right_shifted] @@ -67,7 +67,7 @@ (def: i64//char (Unary Expression) - (|>> //runtime.i64//to_number + (|>> //runtime.i64//number (list) (_.apply/* (_.var "String.fromCharCode")))) @@ -141,7 +141,7 @@ (/.install "*" (binary (product.uncurry //runtime.i64//*))) (/.install "/" (binary (product.uncurry //runtime.i64///))) (/.install "%" (binary (product.uncurry //runtime.i64//%))) - (/.install "f64" (unary //runtime.i64//to_number)) + (/.install "f64" (unary //runtime.i64//number)) (/.install "char" (unary i64//char)) ))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux index 6bb747d54..ff601d308 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/js/host.lux @@ -132,7 +132,7 @@ (function (_ extension phase archive [arity abstractionS]) (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) - #let [variable (: (-> Text (Operation Var)) + .let [variable (: (-> Text (Operation Var)) (|>> generation.gensym (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) (variable "input")) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux index 78c75a17b..61d56f794 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/common.lux @@ -123,7 +123,7 @@ branchG (_.goto @end))]))) conditionalsS)) - #let [table (|> conditionalsG+ + .let [table (|> conditionalsG+ (list\map product.left) list\join) conditionalsG (|> conditionalsG+ @@ -225,7 +225,7 @@ [f64::= f64::< type.double _.dcmpg] ) -(def: (to_string class from) +(def: (::toString class from) (-> (Type Class) (Type Primitive) (Bytecode Any)) (_.invokestatic class "toString" (type.method [(list from) ..$String (list)]))) @@ -248,7 +248,7 @@ ($_ _.compose _.l2i _.i2c - (..to_string ..$Character type.char))] + (..::toString ..$Character type.char))] [f64::i64 (///value.unwrap type.double) @@ -258,7 +258,7 @@ [f64::encode (///value.unwrap type.double) - (..to_string ..$Double type.double)] + (..::toString ..$Double type.double)] [f64::decode ..ensure_string diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux index 8f61e7ea8..60e733c8a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/jvm/host.lux @@ -642,7 +642,7 @@ [($_ <>.and <s>.text <s>.text <s>.text) (function (_ extension_name generate archive [class field unboxed]) (do //////.monad - [#let [$class (type.class class (list))]] + [.let [$class (type.class class (list))]] (case (dictionary.get unboxed ..primitives) (#.Some primitive) (in (_.getstatic $class field primitive)) @@ -659,7 +659,7 @@ (function (_ extension_name generate archive [class field unboxed valueS]) (do //////.monad [valueG (generate archive valueS) - #let [$class (type.class class (list))]] + .let [$class (type.class class (list))]] (case (dictionary.get unboxed ..primitives) (#.Some primitive) (in ($_ _.compose @@ -681,7 +681,7 @@ (function (_ extension_name generate archive [class field unboxed objectS]) (do //////.monad [objectG (generate archive objectS) - #let [$class (type.class class (list)) + .let [$class (type.class class (list)) getG (case (dictionary.get unboxed ..primitives) (#.Some primitive) (_.getfield $class field primitive) @@ -701,7 +701,7 @@ (do //////.monad [valueG (generate archive valueS) objectG (generate archive objectS) - #let [$class (type.class class (list)) + .let [$class (type.class class (list)) putG (case (dictionary.get unboxed ..primitives) (#.Some primitive) (_.putfield $class field primitive) @@ -1011,7 +1011,7 @@ overriden_methods]) (do {! //////.monad} [[context _] (//////generation.with_new_context archive (in [])) - #let [[module_id artifact_id] context + .let [[module_id artifact_id] context anonymous_class_name (///runtime.class_name context) class (type.class anonymous_class_name (list)) total_environment (|> overriden_methods @@ -1021,7 +1021,7 @@ list\join ## Remove duplicates. (set.from_list //////synthesis.hash) - set.to_list) + set.list) global_mapping (|> total_environment ## Give them names as "foreign" variables. list.enumeration diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux index 3c8338304..f1f6ccaa1 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/common.lux @@ -77,7 +77,7 @@ _.nil)) branchG]))) conditionals)) - #let [closure (_.closure (list @input) + .let [closure (_.closure (list @input) (list\fold (function (_ [test then] else) (_.if test (_.return then) else)) (_.return elseG) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux index b728760c0..873a37be7 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/lua/host.lux @@ -170,7 +170,7 @@ (function (_ extension phase archive [arity abstractionS]) (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) - #let [variable (: (-> Text (Operation Var)) + .let [variable (: (-> Text (Operation Var)) (|>> generation.gensym (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux index ca4de50cf..6cc7e61d0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/php/common.lux @@ -81,12 +81,12 @@ _.null)) branchG]))) conditionals)) - #let [foreigns (|> conditionals + .let [foreigns (|> conditionals (list\map (|>> product.right synthesis.path/then //case.dependencies)) (list& (//case.dependencies (synthesis.path/then else))) list.concat (set.of_list _.hash) - set.to_list) + set.list) @expression (_.constant (reference.artifact [context_module context_artifact])) directive (_.define_function @expression (list& (_.parameter @input) (list\map _.reference foreigns)) (list\fold (function (_ [test then] else) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux index 81107aba9..5be155ab3 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/common.lux @@ -75,7 +75,7 @@ _.none)) branchG]))) conditionals)) - #let [closure (_.lambda (list @input) + .let [closure (_.lambda (list @input) (list\fold (function (_ [test then] else) (_.? test then else)) elseG diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux index 57e53f579..87f343233 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/python/host.lux @@ -130,7 +130,7 @@ (function (_ extension phase archive [arity abstractionS]) (do {! ////////phase.monad} [abstractionG (phase archive abstractionS) - #let [variable (: (-> Text (Operation SVar)) + .let [variable (: (-> Text (Operation SVar)) (|>> generation.gensym (\ ! map _.var)))] g!inputs (monad.map ! (function (_ _) (variable "input")) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux index 7eb4e2a5b..c2119b731 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/extension/generation/ruby/common.lux @@ -74,7 +74,7 @@ _.nil)) branchG]))) conditionals)) - #let [closure (_.lambda #.None (list @input) + .let [closure (_.lambda #.None (list @input) (list\fold (function (_ [test then] else) (_.if test (_.return then) else)) (_.return elseG) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/case.lux index 098674e45..43c2cab45 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/case.lux @@ -246,10 +246,10 @@ [initG (expression archive valueS) $output (\ ! map (|>> %.nat (format "lux_case_output") _.var) /////generation.next) pattern_matching! (pattern_matching $output expression archive pathP) - #let [storage (|> pathP + .let [storage (|> pathP ////synthesis/case.storage (get@ #////synthesis/case.bindings) - set.to_list + set.list (list\map (function (_ register) [(..register register) _.nil])))]] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux index fab6fe24c..ad4bedbfa 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/function.lux @@ -67,7 +67,7 @@ (/////generation.with_anchor [@scope 1] (expression archive bodyS))) closureG+ (monad.map ! (expression archive) environment) - #let [@curried (_.var "curried") + .let [@curried (_.var "curried") @missing (_.var "missing") arityG (|> arity .int _.int) @num_args (_.var "num_args") diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux index 5ceb08bc3..61b5cf216 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/common_lisp/loop.lux @@ -62,7 +62,7 @@ (do {! ///////phase.monad} [[tag offset] /////generation.anchor argsO+ (monad.map ! (expression archive) argsS+) - #let [bindings (|> argsO+ + .let [bindings (|> argsO+ list.enumeration (list\map (|>> product.left (n.+ offset) //case.register)) _.args)]] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux index d4b81f29b..f2f326f8f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/function.lux @@ -74,7 +74,7 @@ (/////generation.context archive))] (/////generation.with_anchor [1 scope] (statement expression archive bodyS)))) - #let [arityO (|> arity .int _.i32) + .let [arityO (|> arity .int _.i32) @num_args (_.var "num_args") @scope (..@scope function_name) @self (_.var (///reference.artifact function_name)) @@ -88,7 +88,7 @@ initialize_self! (list.indices arity))] environment (monad.map ! (expression archive) environment) - #let [[definition instantiation] (with_closure @self environment + .let [[definition instantiation] (with_closure @self environment ($_ _.then (_.define @num_args (_.the "length" @@arguments)) (_.cond (list [(|> @num_args (_.= arityO)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux index d351cd6ac..350faeeec 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux @@ -297,7 +297,7 @@ (|> i64 (_.the ..i64_low_field)) (|> i64 (_.the ..i64_low_field) (_.+ i64//2^32))))) -(runtime: (i64//to_number i64) +(runtime: (i64//number i64) (_.return (|> i64 (_.the ..i64_high_field) (_.* i64//2^32) @@ -593,8 +593,8 @@ (let [approximate_result' (i64//of_number approximate) approx_remainder (i64//* parameter approximate_result)] ($_ _.then - (_.define approximate (|> (i64//to_number remainder) - (_./ (i64//to_number parameter)) + (_.define approximate (|> (i64//number remainder) + (_./ (i64//number parameter)) (_.apply/1 (_.var "Math.floor")) (_.apply/2 (_.var "Math.max") (_.i32 +1)))) (_.define log2 (|> approximate @@ -646,7 +646,7 @@ @i64//= @i64//+ @i64//opposite - @i64//to_number + @i64//number @i64//of_number @i64//- @i64//* @@ -659,7 +659,7 @@ (runtime: (text//index start part text) (with_vars [idx] ($_ _.then - (_.define idx (|> text (_.do "indexOf" (list part (i64//to_number start))))) + (_.define idx (|> text (_.do "indexOf" (list part (i64//number start))))) (_.return (_.? (_.= (_.i32 -1) idx) ..none (..some (i64//of_number idx))))))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux index 640543f45..d13e7ebed 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function.lux @@ -102,7 +102,7 @@ [function_context bodyG] (generation.with_new_context archive (generation.with_anchor [@begin ..this_offset] (generate archive bodyS))) - #let [function_class (//runtime.class_name function_context)] + .let [function_class (//runtime.class_name function_context)] [fields methods instance] (..with generate archive @begin function_class environment arity bodyG) class (phase.lift (class.class version.v6_0 ..modifier @@ -111,7 +111,7 @@ fields methods (row.row))) - #let [bytecode (format.run class.writer class)] + .let [bytecode (format.run class.writer class)] _ (generation.execute! [function_class bytecode]) _ (generation.save! function_class #.None [function_class bytecode])] (in instance))) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux index d3e13091a..46b871096 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/function/method/apply.lux @@ -97,7 +97,7 @@ @labelsT (|> _.new_label (list.repeat (dec num_partials)) (monad.seq _.monad)) - #let [cases (|> (list\compose (#.Item [@labelsH @labelsT]) + .let [cases (|> (list\compose (#.Item [@labelsH @labelsT]) (list @default)) list.enumeration (list\map (function (_ [stage @case]) @@ -121,15 +121,15 @@ _.areturn) has_more_than_necessary? - (let [inputs_to_completion (|> function_arity (n.- stage)) - inputs_left (|> apply_arity (n.- inputs_to_completion))] + (let [arity_inputs (|> function_arity (n.- stage)) + additional_inputs (|> apply_arity (n.- arity_inputs))] ($_ _.compose ////reference.this (_.invokevirtual class //reset.name (//reset.type class)) current_partials - (..inputs ..this_offset inputs_to_completion) + (..inputs ..this_offset arity_inputs) (_.invokevirtual class //implementation.name (//implementation.type function_arity)) - (apply (n.+ ..this_offset inputs_to_completion) inputs_left) + (apply (n.+ ..this_offset arity_inputs) additional_inputs) _.areturn)) ## (i.< over_extent (.int stage)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/loop.lux index f8961db37..91c433788 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/loop.lux @@ -51,7 +51,7 @@ ..no_op]) (do ! [fetchG (translate archive updateS) - #let [storeG (_.astore register)]] + .let [storeG (_.astore register)]] (in [fetchG storeG]))))))] (in ($_ _.compose ## It may look weird that first I fetch all the values separately, @@ -78,7 +78,7 @@ initsI+ (monad.map ! (translate archive) initsS+) iterationG (generation.with_anchor [@begin offset] (translate archive iterationS)) - #let [initializationG (|> (list.enumeration initsI+) + .let [initializationG (|> (list.enumeration initsI+) (list\map (function (_ [index initG]) ($_ _.compose initG diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux index 80315db66..a1ae79528 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/jvm/runtime.lux @@ -296,7 +296,7 @@ @tags_match! _.new_label @maybe_nested _.new_label @mismatch! _.new_label - #let [::tag ($_ _.compose + .let [::tag ($_ _.compose (..get ..variant_tag) (//value.unwrap type.int)) ::last? (..get ..variant_last?) @@ -397,7 +397,7 @@ (do _.monad [@loop _.new_label @recursive _.new_label - #let [::left ($_ _.compose + .let [::left ($_ _.compose $lefts _.aaload)]] ($_ _.compose (_.set_label @loop) @@ -416,7 +416,7 @@ [@loop _.new_label @not_tail _.new_label @slice _.new_label - #let [$right ($_ _.compose + .let [$right ($_ _.compose $lefts _.iconst_1 _.iadd) @@ -468,7 +468,7 @@ (do _.monad [@try _.new_label @handler _.new_label - #let [$unsafe ..this + .let [$unsafe ..this unit _.aconst_null ^StringWriter (type.class "java.io.StringWriter" (list)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux index 6d1fda16c..273e1d0ae 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/case.lux @@ -251,7 +251,7 @@ (-> Path (List Var)) (|>> ////synthesis/case.storage (get@ #////synthesis/case.dependencies) - set.to_list + set.list (list\map (function (_ variable) (.case variable (#///////variable.Local register) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux index 28c33a86a..21c78c6f9 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/function.lux @@ -73,7 +73,7 @@ (/////generation.with_anchor [1 @scope] (statement expression archive bodyS)))) closureO+ (monad.map ! (expression archive) environment) - #let [@curried (_.var "curried") + .let [@curried (_.var "curried") arityO (|> arity .int _.int) @num_args (_.var "num_args") @scope (..@scope function_name) @@ -88,7 +88,7 @@ pack (|>> (list) _.array) unpack (_.apply/1 (_.var "table.unpack")) @var_args (_.var "...")] - #let [[definition instantiation] (with_closure closureO+ @self (list @var_args) + .let [[definition instantiation] (with_closure closureO+ @self (list @var_args) ($_ _.then (_.local/1 @curried (pack @var_args)) (_.local/1 @num_args (_.length @curried)) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux index 5d44bcc3c..d9ae9c51f 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/lua/loop.lux @@ -83,7 +83,7 @@ (do {! ///////phase.monad} [[[artifact_module artifact_id] [initsO+ scope!]] (/////generation.with_new_context archive (scope! statement expression archive true [start initsS+ bodyS])) - #let [@loop (_.var (///reference.artifact [artifact_module artifact_id])) + .let [@loop (_.var (///reference.artifact [artifact_module artifact_id])) locals (|> initsO+ list.enumeration (list\map (|>> product.left (n.+ start) //case.register))) @@ -92,7 +92,7 @@ //case.dependencies (set.of_list _.hash) (set.difference (set.of_list _.hash locals)) - set.to_list) + set.list) #.End [(_.function @loop locals scope!) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux index 549d19954..3bbbd7d21 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/case.lux @@ -265,7 +265,7 @@ (-> Path (List Var)) (|>> ////synthesis/case.storage (get@ #////synthesis/case.dependencies) - set.to_list + set.list (list\map (function (_ variable) (.case variable (#///////variable.Local register) @@ -289,7 +289,7 @@ (do {! ///////phase.monad} [[[case_module case_artifact] case!] (/////generation.with_new_context archive (case! statement expression archive [valueS pathP])) - #let [@case (_.constant (///reference.artifact [case_module case_artifact])) + .let [@case (_.constant (///reference.artifact [case_module case_artifact])) @dependencies+ (..dependencies (/////synthesis.path/seq (/////synthesis.path/then valueS) pathP)) directive (_.define_function @case (list\map _.parameter @dependencies+) case!)] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux index 6318a9d88..93a099ce0 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/function.lux @@ -77,7 +77,7 @@ (/////generation.with_anchor [1 @scope] (statement expression archive bodyS)))) closureG+ (monad.map ! (expression archive) environment) - #let [@curried (_.var "curried") + .let [@curried (_.var "curried") arityG (|> arity .int _.int) @num_args (_.var "num_args") @scope (..@scope function_name) @@ -90,7 +90,7 @@ (_.set! (..input post) (_.item (|> post .int _.int) @curried)))) initialize_self! (list.indices arity))] - #let [[definition instantiation] (..with_closure closureG+ @selfG @selfL + .let [[definition instantiation] (..with_closure closureG+ @selfG @selfL ($_ _.then (_.set! @num_args (_.func_num_args/0 [])) (_.set! @curried (_.func_get_args/0 [])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux index 0c3c94f1f..54a001a41 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/php/loop.lux @@ -78,7 +78,7 @@ (do {! ///////phase.monad} [[[loop_module loop_artifact] scope!] (/////generation.with_new_context archive (..scope! statement expression archive [start initsS+ bodyS])) - #let [locals (|> initsS+ + .let [locals (|> initsS+ list.enumeration (list\map (|>> product.left (n.+ start) //case.register _.parameter))) @loop (_.constant (///reference.artifact [loop_module loop_artifact])) @@ -91,7 +91,7 @@ (case (|> (list\map referenced_variables initsS+) (list\fold set.union (referenced_variables bodyS)) (set.difference loop_variables) - set.to_list) + set.list) #.End [(_.define_function @loop (list) scope!) @loop] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux index fa1a42e49..59ccb6098 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/case.lux @@ -299,7 +299,7 @@ (-> Path (List SVar)) (|>> case.storage (get@ #case.dependencies) - set.to_list + set.list (list\map (function (_ variable) (.case variable (#///////variable.Local register) @@ -324,7 +324,7 @@ (do ///////phase.monad [[[case_module case_artifact] pattern_matching!] (/////generation.with_new_context archive (case! true statement expression archive [valueS pathP])) - #let [@case (_.var (///reference.artifact [case_module case_artifact])) + .let [@case (_.var (///reference.artifact [case_module case_artifact])) @dependencies+ (..dependencies (/////synthesis.path/seq (/////synthesis.path/then valueS) pathP)) directive (_.def @case @dependencies+ diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux index fd225dfe4..c7ff46333 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/function.lux @@ -53,7 +53,7 @@ _ (do {! ///////phase.monad} - [#let [directive (_.def @function + [.let [directive (_.def @function (|> (list.enumeration inits) (list\map (|>> product.left ..capture))) ($_ _.then @@ -73,7 +73,7 @@ (/////generation.with_anchor 1 (statement expression archive bodyS))) environment (monad.map ! (expression archive) environment) - #let [@curried (_.var "curried") + .let [@curried (_.var "curried") arityO (|> arity .int _.int) @num_args (_.var "num_args") @self (_.var (///reference.artifact [function_module function_artifact])) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux index 37296dd7c..8f4386405 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/python/loop.lux @@ -78,7 +78,7 @@ [[loop_module loop_artifact] body!] (/////generation.with_new_context archive (/////generation.with_anchor start (statement expression archive bodyS))) - #let [@loop (_.var (///reference.artifact [loop_module loop_artifact])) + .let [@loop (_.var (///reference.artifact [loop_module loop_artifact])) locals (|> initsS+ list.enumeration (list\map (|>> product.left (n.+ start) //case.register))) @@ -90,7 +90,7 @@ //case.dependencies (set.of_list _.hash) (set.difference (set.of_list _.hash locals)) - set.to_list) + set.list) #.End [actual_loop @loop] @@ -112,7 +112,7 @@ [offset /////generation.anchor @temp (//case.gensym "lux_recur_values") argsO+ (monad.map ! (expression archive) argsS+) - #let [re_binds (|> argsO+ + .let [re_binds (|> argsO+ list.enumeration (list\map (function (_ [idx _]) (_.item (_.int (.int idx)) @temp))))]] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux index 850f99475..dfdec59ce 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/function.lux @@ -51,7 +51,7 @@ _ (do ///////phase.monad - [#let [closure_definition (_.set! $function + [.let [closure_definition (_.set! $function (_.function (|> inits list.size list.indices @@ -81,7 +81,7 @@ (/////generation.with_anchor $self (expression archive bodyS)))) closureO+ (monad.map ! (expression archive) environment) - #let [arityO (|> arity .int _.int) + .let [arityO (|> arity .int _.int) $num_args (_.var "num_args") $self (_.var (///reference.artifact [function_module function_artifact])) apply_poly (.function (_ args func) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux index 7de7310d6..18157701d 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/procedure/common.lux @@ -251,7 +251,7 @@ (install "%" (binary int//rem)) (install "=" (binary int//=)) (install "<" (binary int//<)) - (install "to-frac" (unary runtimeT.int//to_float)) + (install "to-frac" (unary runtimeT.int//float)) (install "char" (unary int//char))))) (def: (frac//encode value) @@ -310,7 +310,7 @@ (def: (io//exit input) Unary (r.apply_kw (list) - (list ["status" (runtimeT.int//to_float input)]) + (list ["status" (runtimeT.int//float input)]) (r.global "quit"))) (def: (void code) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux index f71070979..824f53012 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/r/runtime.lux @@ -185,7 +185,7 @@ low (|> low (_.+ f2^32)))))) -(runtime: (i64::to_float input) +(runtime: (i64::float input) (let [high (|> input (_.item (_.string ..i64_high_field)) high_shift) @@ -481,7 +481,7 @@ (_.set! remainder subject) (_.while (|> (|> remainder (i64::< param)) (_.or (|> remainder (i64::= param)))) - (let [calc_rough_estimate (_.apply (list (|> (i64::to_float remainder) (_./ (i64::to_float param)))) + (let [calc_rough_estimate (_.apply (list (|> (i64::float remainder) (_./ (i64::float param)))) (_.var "floor")) calc_approximate_result (i64::of_float approximate) calc_approximate_remainder (|> approximate_result (i64::* param)) @@ -698,7 +698,7 @@ @i64::opposite @i64::-one @i64::unsigned_low - @i64::to_float + @i64::float @i64::* @i64::/ @i64::% @@ -743,7 +743,7 @@ (runtime: (text::index subject param start) (with_vars [idx startF subjectL] ($_ _.then - (_.set! startF (i64::to_float start)) + (_.set! startF (i64::float start)) (_.set! subjectL (text_length subject)) (_.if (|> startF (within? subjectL)) ($_ _.then diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux index e7e831a77..281ea380a 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/function.lux @@ -70,7 +70,7 @@ (/////generation.with_anchor 1 (statement expression archive bodyS))) closureO+ (monad.map ! (expression archive) environment) - #let [function_name (///reference.artifact [function_module function_artifact]) + .let [function_name (///reference.artifact [function_module function_artifact]) @curried (_.local "curried") arityO (|> arity .int _.int) limitO (|> arity dec .int _.int) diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux index 5c255fcc9..2cf1506c7 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/ruby/loop.lux @@ -86,7 +86,7 @@ [offset /////generation.anchor @temp (//case.gensym "lux_recur_values") argsO+ (monad.map ! (expression archive) argsS+) - #let [re_binds (|> argsO+ + .let [re_binds (|> argsO+ list.enumeration (list\map (function (_ [idx _]) (_.item (_.int (.int idx)) @temp))))]] diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/function.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/function.lux index dd19db665..7feb087f2 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/function.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/generation/scheme/function.lux @@ -70,7 +70,7 @@ (/////generation.with_anchor @self (expression archive bodyS)))) closureO+ (monad.map ! (expression archive) environment) - #let [arityO (|> arity .int _.int) + .let [arityO (|> arity .int _.int) apply_poly (.function (_ args func) (_.apply/2 (_.var "apply") func args)) @num_args (_.var "num_args") diff --git a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux index ab798a01b..db9cbdc59 100644 --- a/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux +++ b/stdlib/source/library/lux/tool/compiler/language/lux/phase/synthesis/variable.lux @@ -295,22 +295,22 @@ (#/.Seq pre post) (do try.monad - [#let [baseline (|> redundancy + [.let [baseline (|> redundancy dictionary.keys (set.of_list n.hash))] [redundancy pre] (recur [redundancy pre]) - #let [bindings (|> redundancy + .let [bindings (|> redundancy dictionary.keys (set.of_list n.hash) (set.difference baseline))] [redundancy post] (recur [redundancy post]) - #let [redundants (|> redundancy + .let [redundants (|> redundancy dictionary.entries (list.only (function (_ [register redundant?]) (and (set.member? bindings register) redundant?))) (list\map product.left))]] - (in [(list\fold dictionary.remove redundancy (set.to_list bindings)) + (in [(list\fold dictionary.remove redundancy (set.list bindings)) (|> redundants (list.sort n.>) (list\fold (..remove_local_from_path ..remove_local) (#/.Seq pre post)))])) @@ -367,7 +367,7 @@ [[redundancy input] (optimization' [redundancy input]) redundancy (..declare register redundancy) [redundancy output] (optimization' [redundancy output]) - #let [redundant? (|> redundancy + .let [redundant? (|> redundancy (dictionary.get register) (maybe.else ..necessary!))]] (in [(dictionary.remove register redundancy) @@ -403,7 +403,7 @@ (#/.Scope [start inits iteration]) (do try.monad [[redundancy inits] (..list_optimization optimization' [redundancy inits]) - #let [[extension redundancy] (..extended start (list.size inits) redundancy)] + .let [[extension redundancy] (..extended start (list.size inits) redundancy)] [redundancy iteration] (optimization' [redundancy iteration])] (in [(list\fold dictionary.remove redundancy extension) (#/.Control (#/.Loop (#/.Scope [start inits iteration])))])) diff --git a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux index 76266ad19..cab4eb2d3 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/archive/artifact.lux @@ -81,7 +81,7 @@ (|> registry :representation (get@ #artifacts) - row.to_list + row.list (list.all (|>> (get@ #category) (case> (<tag> name) (#.Some name) _ #.None)))))] diff --git a/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux b/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux index 4d9af7859..ecce5c337 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/cache/dependency.lux @@ -55,13 +55,13 @@ (let [memo (: (Memo Module Ancestry) (function (_ recur module) (do {! state.monad} - [#let [parents (case (archive.find module archive) + [.let [parents (case (archive.find module archive) (#try.Success [descriptor document]) (get@ #descriptor.references descriptor) (#try.Failure error) ..fresh)] - ancestors (monad.map ! recur (set.to_list parents))] + ancestors (monad.map ! recur (set.list parents))] (in (list\fold set.union parents ancestors))))) ancestry (memo.open memo)] (list\fold (function (_ module memory) diff --git a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux index c5ebc6bad..125360e58 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/io/archive.lux @@ -101,7 +101,7 @@ (def: #export (prepare fs static module_id) (-> (file.System Async) Static archive.ID (Async (Try Any))) (do {! async.monad} - [#let [module (..module fs static module_id)] + [.let [module (..module fs static module_id)] module_exists? (\ fs directory? module)] (if module_exists? (in (#try.Success [])) @@ -216,7 +216,7 @@ (Try [(Document .Module) Bundles Output]))) (do {! try.monad} [[definitions bundles] (: (Try [Definitions Bundles Output]) - (loop [input (row.to_list expected) + (loop [input (row.list expected) definitions (: Definitions (dictionary.empty text.hash)) bundles ..empty_bundles @@ -226,12 +226,12 @@ (#.Item [[artifact_id artifact_category] input']) (case (do ! [data (try.of_maybe (dictionary.get (format (%.nat artifact_id) extension) actual)) - #let [context [module_id artifact_id] + .let [context [module_id artifact_id] directive (\ host ingest context data)]] (case artifact_category #artifact.Anonymous (do ! - [#let [output (row.add [artifact_id #.None data] output)] + [.let [output (row.add [artifact_id #.None data] output)] _ (\ host re_learn context #.None directive)] (in [definitions [analysers @@ -260,7 +260,7 @@ (#artifact.Analyser extension) (do ! - [#let [output (row.add [artifact_id #.None data] output)] + [.let [output (row.add [artifact_id #.None data] output)] value (\ host re_load context #.None directive)] (in [definitions [(dictionary.put extension (:as analysis.Handler value) analysers) @@ -271,7 +271,7 @@ (#artifact.Synthesizer extension) (do ! - [#let [output (row.add [artifact_id #.None data] output)] + [.let [output (row.add [artifact_id #.None data] output)] value (\ host re_load context #.None directive)] (in [definitions [analysers @@ -282,7 +282,7 @@ (#artifact.Generator extension) (do ! - [#let [output (row.add [artifact_id #.None data] output)] + [.let [output (row.add [artifact_id #.None data] output)] value (\ host re_load context #.None directive)] (in [definitions [analysers @@ -293,7 +293,7 @@ (#artifact.Directive extension) (do ! - [#let [output (row.add [artifact_id #.None data] output)] + [.let [output (row.add [artifact_id #.None data] output)] value (\ host re_load context #.None directive)] (in [definitions [analysers @@ -304,7 +304,7 @@ (#artifact.Custom name) (do ! - [#let [output (row.add [artifact_id (#.Some name) data] output)] + [.let [output (row.add [artifact_id (#.Some name) data] output)] _ (\ host re_learn context (#.Some name) directive)] (in [definitions [analysers @@ -345,14 +345,14 @@ Bundles])))) (do (try.with async.monad) [actual (cached_artifacts fs static module_id) - #let [expected (|> descriptor (get@ #descriptor.registry) artifact.artifacts)] + .let [expected (|> descriptor (get@ #descriptor.registry) artifact.artifacts)] [document bundles output] (async\in (loaded_document (get@ #static.artifact_extension static) host_environment module_id expected actual document))] (in [[descriptor document output] bundles]))) (def: (purge! fs static [module_name module_id]) (-> (file.System Async) Static [Module archive.ID] (Async (Try Any))) (do {! (try.with async.monad)} - [#let [cache (..module fs static module_id)] + [.let [cache (..module fs static module_id)] _ (|> cache (\ fs directory_files) (\ ! map (monad.map ! (\ fs delete))) @@ -391,7 +391,7 @@ purge (if (|> descriptor (get@ #descriptor.references) - set.to_list + set.list (list.any? purged?)) (dictionary.put module_name module_id purge) purge)))) @@ -429,7 +429,7 @@ (\ try.monad map (dependency.load_order $.key)) (\ try.monad join) async\in) - #let [purge (..full_purge pre_loaded_caches load_order)] + .let [purge (..full_purge pre_loaded_caches load_order)] _ (|> purge dictionary.entries (monad.map ! (..purge! fs static))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager.lux b/stdlib/source/library/lux/tool/compiler/meta/packager.lux index 6cb17c7b6..07ac4be8c 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager.lux @@ -37,6 +37,6 @@ (|> descriptor (get@ #descriptor.registry) artifact.artifacts - row.to_list + row.list (list\map (|>> (get@ #artifact.id))) [module_id])))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux index 3ebdae788..c138ef6ce 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/jvm.lux @@ -158,7 +158,7 @@ (function (_ [artifact custom content] sink) (..write_class static module artifact custom content sink)) sink - (row.to_list output))) + (row.list output))) (def: (read_jar_entry_with_unknown_size input) (-> java/util/jar/JarInputStream [Nat Binary]) @@ -247,7 +247,7 @@ (function (_ host_dependencies archive program) (do {! try.monad} [order (dependency.load_order $.key archive) - #let [buffer (java/io/ByteArrayOutputStream::new (.int ..mebi_byte))] + .let [buffer (java/io/ByteArrayOutputStream::new (.int ..mebi_byte))] sink (|> order (list\map (function (_ [module [module_id [descriptor document output]]]) [module_id output])) @@ -259,7 +259,7 @@ [(set.empty text.hash) (set.empty text.hash) sink])) - #let [_ (do_to sink + .let [_ (do_to sink (java/io/Flushable::flush) (java/io/Closeable::close))]] (in (java/io/ByteArrayOutputStream::toByteArray buffer))))) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux index 6af912b14..081a43829 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/scheme.lux @@ -3,7 +3,7 @@ [lux (#- Module) [type (#+ :sharing)] [abstract - ["." monad (#+ Monad do)]] + ["." monad (#+ do)]] [control ["." try (#+ Try)]] [data @@ -56,7 +56,7 @@ (def: bundle_module (-> Output (Try _.Expression)) - (|>> row.to_list + (|>> row.list (list\map product.right) (monad.fold try.monad (function (_ content so_far) @@ -105,7 +105,7 @@ entry_content (: (Try tar.Content) (|> descriptor (get@ #descriptor.references) - set.to_list + set.list (list.all (function (_ module) (dictionary.get module mapping))) (list\map (|>> ..module_file _.string _.load_relative/1)) (list\fold ..then bundle) @@ -121,7 +121,7 @@ (function (package host_dependencies archive program) (do {! try.monad} [order (dependency.load_order $.key archive) - #let [mapping (|> order + .let [mapping (|> order (list\map (function (_ [module [module_id [descriptor document output]]]) [module module_id])) (dictionary.of_list text.hash) diff --git a/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux index 080765231..0f3f33a29 100644 --- a/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux +++ b/stdlib/source/library/lux/tool/compiler/meta/packager/script.lux @@ -38,7 +38,7 @@ (-> (-> directive directive directive) [archive.ID Output] directive (Try directive))) (|> output - row.to_list + row.list (list\map (|>> product.right product.right)) (monad.fold try.monad (function (_ content so_far) @@ -54,7 +54,7 @@ (sequence so_far))))) so_far))) -(def: #export (package header to_code sequence scope) +(def: #export (package header code sequence scope) (All [directive] (-> directive (-> directive Text) @@ -68,4 +68,4 @@ (list\map (function (_ [module [module_id [descriptor document output]]]) [module_id output])) (monad.fold ! (..write_module sequence) header) - (\ ! map (|>> scope to_code (\ utf8.codec encode))))))) + (\ ! map (|>> scope code (\ utf8.codec encode))))))) diff --git a/stdlib/source/library/lux/tool/compiler/phase.lux b/stdlib/source/library/lux/tool/compiler/phase.lux index 0a0db986e..cfae348ce 100644 --- a/stdlib/source/library/lux/tool/compiler/phase.lux +++ b/stdlib/source/library/lux/tool/compiler/phase.lux @@ -107,9 +107,9 @@ (-> Name Text (Operation s a) (Operation s a))) (do ..monad [_ (in []) - #let [pre (io.run instant.now)] + .let [pre (io.run instant.now)] output operation - #let [_ (|> instant.now + .let [_ (|> instant.now io.run instant.relative (duration.difference (instant.relative pre)) diff --git a/stdlib/source/library/lux/tool/interpreter.lux b/stdlib/source/library/lux/tool/interpreter.lux index c374d9bd1..f60aaf134 100644 --- a/stdlib/source/library/lux/tool/interpreter.lux +++ b/stdlib/source/library/lux/tool/interpreter.lux @@ -102,7 +102,7 @@ (-> Code <Interpretation>)) (do {! phase.monad} [state (extension.lift phase.get_state) - #let [analyse (get@ [#directive.analysis #directive.phase] state) + .let [analyse (get@ [#directive.analysis #directive.phase] state) synthesize (get@ [#directive.synthesis #directive.phase] state) generate (get@ [#directive.generation #directive.phase] state)] [_ codeT codeA] (directive.lift_analysis @@ -171,7 +171,7 @@ (All [anchor expression directive] (-> <Context> (Try [<Context> Text]))) (do try.monad - [#let [[_where _offset _code] (get@ #source context)] + [.let [[_where _offset _code] (get@ #source context)] [source' input] (syntax.parse ..module syntax.no_aliases (text.size _code) (get@ #source context)) [state' representation] (let [## TODO: Simplify ASAP state (:sharing [anchor expression directive] diff --git a/stdlib/source/library/lux/type.lux b/stdlib/source/library/lux/type.lux index 950d71c63..ed808b8e9 100644 --- a/stdlib/source/library/lux/type.lux +++ b/stdlib/source/library/lux/type.lux @@ -245,12 +245,12 @@ _ #.None))) -(def: #export (to_code type) +(def: #export (code type) (-> Type Code) (case type (#.Primitive name params) (` (#.Primitive (~ (code.text name)) - (.list (~+ (list\map to_code params))))) + (.list (~+ (list\map code params))))) (^template [<tag>] [(<tag> idx) @@ -259,8 +259,8 @@ (^template [<tag>] [(<tag> left right) - (` (<tag> (~ (to_code left)) - (~ (to_code right))))]) + (` (<tag> (~ (code left)) + (~ (code right))))]) ([#.Sum] [#.Product] [#.Function] [#.Apply]) (#.Named name sub_type) @@ -268,8 +268,8 @@ (^template [<tag>] [(<tag> env body) - (` (<tag> (.list (~+ (list\map to_code env))) - (~ (to_code body))))]) + (` (<tag> (.list (~+ (list\map code env))) + (~ (code body))))]) ([#.UnivQ] [#.ExQ]) )) @@ -395,7 +395,7 @@ (do meta.monad [location meta.location valueT (meta.type valueN) - #let [_ ("lux io log" + .let [_ ("lux io log" ($_ text\compose (name\encode (name_of ..:log!)) " " (location.format location) text.new_line "Expression: " (case valueC diff --git a/stdlib/source/library/lux/type/abstract.lux b/stdlib/source/library/lux/type/abstract.lux index 66560bc4f..7eb42acb2 100644 --- a/stdlib/source/library/lux/type/abstract.lux +++ b/stdlib/source/library/lux/type/abstract.lux @@ -213,7 +213,7 @@ {primitives (<>.some <code>.any)}) (do meta.monad [current_module meta.current_module_name - #let [type_varsC (list\map code.local_identifier type_vars) + .let [type_varsC (list\map code.local_identifier type_vars) abstraction_declaration (` ((~ (code.local_identifier name)) (~+ type_varsC))) representation_declaration (` ((~ (code.local_identifier (representation_definition_name name))) (~+ type_varsC)))] diff --git a/stdlib/source/library/lux/type/check.lux b/stdlib/source/library/lux/type/check.lux index dcdf4ba58..0b47df0ab 100644 --- a/stdlib/source/library/lux/type/check.lux +++ b/stdlib/source/library/lux/type/check.lux @@ -372,7 +372,7 @@ (do {! ..monad} [ring (..ring id) _ (..assertion "" (n.> 1 (set.size ring))) - _ (monad.map ! (update type) (set.to_list ring))] + _ (monad.map ! (update type) (set.list ring))] then) (do ..monad [?bound (read id)] @@ -444,14 +444,14 @@ [_ (link_3 interpose to idE)] (in interpose))) targetE - (set.to_list ringA))] + (set.list ringA))] (in assumptions)))) (^template [<pattern> <id> <type>] [<pattern> (do ! [ring (..ring <id>) - _ (monad.map ! (update <type>) (set.to_list ring))] + _ (monad.map ! (update <type>) (set.list ring))] (in assumptions))]) ([[(#.Var _) _] idE atype] [[_ (#.Var _)] idA etype]) diff --git a/stdlib/source/library/lux/type/implicit.lux b/stdlib/source/library/lux/type/implicit.lux index 80e2f1ca2..a1d7c160c 100644 --- a/stdlib/source/library/lux/type/implicit.lux +++ b/stdlib/source/library/lux/type/implicit.lux @@ -2,7 +2,7 @@ [library [lux #* [abstract - ["." monad (#+ Monad do)] + ["." monad (#+ do)] ["." equivalence]] [control ["." try] @@ -94,7 +94,7 @@ [this_module_name meta.current_module_name imp_mods (meta.imported_modules this_module_name) tag_lists (monad.map ! meta.tag_lists imp_mods) - #let [tag_lists (|> tag_lists list\join (list\map product.left) list\join) + .let [tag_lists (|> tag_lists list\join (list\map product.left) list\join) candidates (list.only (|>> product.right (text\= simple_name)) tag_lists)]] (case candidates @@ -132,7 +132,7 @@ (Meta (List [Name Type])) (do meta.monad [local_batches meta.locals - #let [total_locals (list\fold (function (_ [name type] table) + .let [total_locals (list\fold (function (_ [name type] table) (try.else table (dictionary.try_put name type table))) (: (Dictionary Text Type) (dictionary.empty text.hash)) @@ -215,7 +215,7 @@ (case (check.run context (do {! check.monad} [[tvars alt_type] (concrete_type alt_type) - #let [[deps alt_type] (type.flat_function alt_type)] + .let [[deps alt_type] (type.flat_function alt_type)] _ (check.check dep alt_type) context' check.context =deps (monad.map ! (provision compiler context') deps)] @@ -264,7 +264,7 @@ (case (<| (check.run context) (do {! check.monad} [[tvars alt_type] (concrete_type alt_type) - #let [[deps alt_type] (type.flat_function alt_type)] + .let [[deps alt_type] (type.flat_function alt_type)] _ (check.check alt_type sig_type) member_type (member_type member_idx alt_type) _ (ensure_function_application! member_type input_types output_type) diff --git a/stdlib/source/library/lux/type/resource.lux b/stdlib/source/library/lux/type/resource.lux index b61fb2d9f..1ddc43d99 100644 --- a/stdlib/source/library/lux/type/resource.lux +++ b/stdlib/source/library/lux/type/resource.lux @@ -137,9 +137,9 @@ (#.Item head tail) (do {! meta.monad} - [#let [max_idx (list\fold n.max head tail)] + [.let [max_idx (list\fold n.max head tail)] g!inputs (<| (monad.seq !) (list.repeat (inc max_idx)) (macro.gensym "input")) - #let [g!outputs (|> (monad.fold maybe.monad + .let [g!outputs (|> (monad.fold maybe.monad (function (_ from to) (do maybe.monad [input (list.item from g!inputs)] @@ -147,7 +147,7 @@ (: (Row Code) row.empty) swaps) maybe.assume - row.to_list) + row.list) g!inputsT+ (list\map (|>> (~) (..Key ..Commutative) (`)) g!inputs) g!outputsT+ (list\map (|>> (~) (..Key ..Commutative) (`)) g!outputs)]] (in (list (` (: (All [(~ g!!) (~+ g!inputs) (~ g!context)] diff --git a/stdlib/source/library/lux/type/unit.lux b/stdlib/source/library/lux/type/unit.lux index 941c52167..b04ad62e9 100644 --- a/stdlib/source/library/lux/type/unit.lux +++ b/stdlib/source/library/lux/type/unit.lux @@ -90,7 +90,7 @@ {annotations (<>.else |annotations|.empty |annotations|.parser)}) (do meta.monad [@ meta.current_module_name - #let [g!type (code.local_identifier type_name)]] + .let [g!type (code.local_identifier type_name)]] (in (list (` (type: (~+ (|export|.format export)) (~ g!type) (~ (|annotations|.format annotations)) (primitive (~ (code.text (%.name [@ type_name])))))) @@ -121,7 +121,7 @@ {annotations (<>.else |annotations|.empty |annotations|.parser)}) (do meta.monad [@ meta.current_module_name - #let [g!scale (code.local_identifier type_name)]] + .let [g!scale (code.local_identifier type_name)]] (in (list (` (type: (~+ (|export|.format export)) ((~ g!scale) (~' u)) (~ (|annotations|.format annotations)) (primitive (~ (code.text (%.name [@ type_name]))) [(~' u)]))) @@ -143,7 +143,7 @@ [(~ (code.nat numerator)) (~ (code.nat denominator))]))) )))) -(def: #export (re_scale from to quantity) +(def: #export (re_scaled from to quantity) (All [si so u] (-> (Scale si) (Scale so) (Qty (si u)) (Qty (so u)))) (let [[numerator denominator] (ratio./ (\ from ratio) (\ to ratio))] diff --git a/stdlib/source/library/lux/world/db/jdbc/input.lux b/stdlib/source/library/lux/world/db/jdbc/input.lux index 10cf48c86..6033224eb 100644 --- a/stdlib/source/library/lux/world/db/jdbc/input.lux +++ b/stdlib/source/library/lux/world/db/jdbc/input.lux @@ -97,7 +97,7 @@ (function (_ value [idx statement]) (do try.monad [_ (<setter> (.int idx) - (<constructor> (instant.to_millis value)) + (<constructor> (instant.millis value)) statement)] (in [(.inc idx) statement]))))] diff --git a/stdlib/source/library/lux/world/file.lux b/stdlib/source/library/lux/world/file.lux index f3ce90305..2d09acf8a 100644 --- a/stdlib/source/library/lux/world/file.lux +++ b/stdlib/source/library/lux/world/file.lux @@ -230,7 +230,7 @@ (case ?children (#.Some children) (|> children - array.to_list + array.list (monad.only ! (|>> <method>)) (\ ! map (monad.map ! (|>> java/io/File::getAbsolutePath))) (\ ! join)) @@ -258,9 +258,9 @@ (def: (read path) (do (try.with io.monad) - [#let [file (java/io/File::new path)] + [.let [file (java/io/File::new path)] size (java/io/File::length file) - #let [data (binary.create (.nat size))] + .let [data (binary.create (.nat size))] stream (java/io/FileInputStream::new file) bytes_read (java/io/InputStream::read data stream) _ (java/lang/AutoCloseable::close stream)] @@ -276,7 +276,7 @@ (def: (modify time_stamp path) (|> path java/io/File::new - (java/io/File::setLastModified (|> time_stamp instant.relative duration.to_millis)))) + (java/io/File::setLastModified (|> time_stamp instant.relative duration.millis)))) (~~ (template [<name> <flag>] [(def: (<name> data path) @@ -428,7 +428,7 @@ (def: (make_directory path) (do async.monad - [#let [node_fs (..node_fs [])] + [.let [node_fs (..node_fs [])] outcome (with_async write! (Try Any) (Fs::access [path (|> node_fs Fs::constants FsConstants::F_OK) @@ -445,11 +445,11 @@ (~~ (template [<name> <method>] [(def: (<name> path) (do {! (try.with async.monad)} - [#let [node_fs (..node_fs [])] + [.let [node_fs (..node_fs [])] subs (with_async write! (Try (Array ffi.String)) (Fs::readdir [path (..value_callback write!)] node_fs))] (|> subs - array.to_list + array.list (list\map (|>> (format path ..js_separator))) (monad.map ! (function (_ sub) (\ ! map (|>> (<method> []) [sub]) @@ -504,7 +504,7 @@ (def: (delete path) (do (try.with async.monad) - [#let [node_fs (..node_fs [])] + [.let [node_fs (..node_fs [])] stats (with_async write! (Try Stats) (Fs::stat [path (..value_callback write!)] node_fs))] (with_async write! (Try Any) @@ -514,7 +514,7 @@ (def: (modify time_stamp path) (with_async write! (Try Any) - (let [when (|> time_stamp instant.relative duration.to_millis i.frac)] + (let [when (|> time_stamp instant.relative duration.millis i.frac)] (Fs::utimes [path when when (..any_callback write!)] (..node_fs []))))) @@ -596,7 +596,7 @@ (let [! (try.with io.monad)] (|> path os::listdir - (\ ! map (|>> array.to_list + (\ ! map (|>> array.list (list\map (|>> (format path ..python_separator))) (monad.map ! (function (_ sub) (\ ! map (|>> [sub]) (<method> [sub])))) @@ -637,7 +637,7 @@ (os::rmdir [path])))) (def: (modify time_stamp path) - (let [when (|> time_stamp instant.relative duration.to_millis (i./ +1,000))] + (let [when (|> time_stamp instant.relative duration.millis (i./ +1,000))] (os::utime [path (..tuple [when when])]))) (~~ (template [<name> <mode>] @@ -723,7 +723,7 @@ [self (RubyDir::open [path]) children (RubyDir::children [] self) output (loop [input (|> children - array.to_list + array.list (list\map (|>> (format path ..ruby_separator)))) output (: (List ..Path) (list))] @@ -777,7 +777,7 @@ (def: (modify moment path) (let [moment (|> moment instant.relative - duration.to_millis + duration.millis i.frac (f./ +1,000.0) RubyTime::at)] @@ -885,7 +885,7 @@ ## (def: (modify moment) ## (do {! (try.with io.monad)} - ## [verdict (..touch [path (|> moment instant.relative duration.to_millis (i./ +1,000))])] + ## [verdict (..touch [path (|> moment instant.relative duration.millis (i./ +1,000))])] ## (if (bit\= false (:as Bit verdict)) ## (\ io.monad in (exception.except ..cannot_find_file [path])) ## (in [])))) @@ -916,7 +916,7 @@ ## (do {! (try.with io.monad)} ## [children (..scandir [path])] ## (loop [input (|> children - ## array.to_list + ## array.list ## (list.only (function (_ child) ## (not (or (text\= "." child) ## (text\= ".." child)))))) @@ -963,7 +963,7 @@ ## (def: (make_file path) ## (do {! (try.with io.monad)} - ## [verdict (..touch [path (|> instant.now io.run instant.relative duration.to_millis (i./ +1,000))])] + ## [verdict (..touch [path (|> instant.now io.run instant.relative duration.millis (i./ +1,000))])] ## (\ io.monad in ## (if verdict ## (#try.Success (..file path)) diff --git a/stdlib/source/library/lux/world/file/watch.lux b/stdlib/source/library/lux/world/file/watch.lux index bfe64cca1..5800e68e1 100644 --- a/stdlib/source/library/lux/world/file/watch.lux +++ b/stdlib/source/library/lux/world/file/watch.lux @@ -149,7 +149,7 @@ (List //.Path)]]))) (do {! (try.with async.monad)} [current_files (..poll_files fs directory) - #let [creations (if (..creation? concern) + .let [creations (if (..creation? concern) (list.only (|>> product.left (dictionary.key? file_tracker) not) current_files) (list)) @@ -236,7 +236,7 @@ (dictionary.of_list text.hash)) tracker))] (in (#try.Success []))) - #let [[creations modifications deletions] + .let [[creations modifications deletions] (list\fold (function (_ [_ [creations modifications deletions]] [all_creations all_modifications all_deletions]) [(list\compose creations all_creations) @@ -378,7 +378,7 @@ [valid? (java/nio/file/WatchKey::reset key)] (if valid? (do ! - [#let [path (|> key + [.let [path (|> key java/nio/file/WatchKey::watchable (:as java/nio/file/Path) java/nio/file/Path::toString @@ -410,7 +410,7 @@ (do (try.with io.monad) [watcher (java/nio/file/FileSystem::newWatchService (java/nio/file/FileSystems::getDefault)) - #let [tracker (stm.var (: (Dictionary //.Path [Concern java/nio/file/WatchKey]) + .let [tracker (stm.var (: (Dictionary //.Path [Concern java/nio/file/WatchKey]) (dictionary.empty text.hash))) stop (: (-> //.Path (Async (Try Concern))) diff --git a/stdlib/source/library/lux/world/net/http/client.lux b/stdlib/source/library/lux/world/net/http/client.lux index 0861d7d96..fd79fc81b 100644 --- a/stdlib/source/library/lux/world/net/http/client.lux +++ b/stdlib/source/library/lux/world/net/http/client.lux @@ -121,7 +121,7 @@ (if partial? (loop [so_far +0] (do {! (try.with io.monad)} - [#let [remaining (i.- so_far (.int buffer_size))] + [.let [remaining (i.- so_far (.int buffer_size))] bytes_read (java/io/BufferedInputStream::read buffer so_far remaining input)] (case bytes_read -1 (do ! @@ -134,7 +134,7 @@ (loop [so_far +0 output (\ binary.monoid identity)] (do {! (try.with io.monad)} - [#let [remaining (i.- so_far (.int buffer_size))] + [.let [remaining (i.- so_far (.int buffer_size))] bytes_read (java/io/BufferedInputStream::read buffer so_far remaining input)] (case bytes_read -1 (do ! @@ -177,7 +177,7 @@ (: (IO (Try (//.Response IO))) (do {! (try.with io.monad)} [connection (|> url java/net/URL::new java/net/URL::openConnection) - #let [connection (:as java/net/HttpURLConnection connection)] + .let [connection (:as java/net/HttpURLConnection connection)] _ (java/net/HttpURLConnection::setRequestMethod (..jvm_method method) connection) _ (monad.map ! (function (_ [name value]) (java/net/URLConnection::setRequestProperty name value connection)) diff --git a/stdlib/source/library/lux/world/net/http/route.lux b/stdlib/source/library/lux/world/net/http/route.lux index a390c51bb..0dd3f6c5b 100644 --- a/stdlib/source/library/lux/world/net/http/route.lux +++ b/stdlib/source/library/lux/world/net/http/route.lux @@ -68,7 +68,7 @@ (function (_ request) (do async.monad [response (primary request) - #let [[status message] response]] + .let [[status message] response]] (if (n.= //status.not_found status) (alternative request) (in response))))) diff --git a/stdlib/source/library/lux/world/program.lux b/stdlib/source/library/lux/world/program.lux index f73621cae..460acdc66 100644 --- a/stdlib/source/library/lux/world/program.lux +++ b/stdlib/source/library/lux/world/program.lux @@ -315,23 +315,23 @@ (case (ffi.constant Object [process env]) (#.Some process/env) (|> (Object::entries [process/env]) - array.to_list + array.list (list\map (|>> (array.read 0) maybe.assume))) #.None (list)) (list))) - @.python (\ io.monad map array.to_list (os/environ::keys [])) + @.python (\ io.monad map array.list (os/environ::keys [])) ## Lua offers no way to get all the environment variables available. @.lua (io.io (list)) @.ruby (|> (RubyEnv::keys []) - array.to_list + array.list io.io) ## @.php (do io.monad ## [environment (..getenv/0 [])] ## (in (|> environment ## ..array_keys - ## array.to_list + ## array.list ## (list\map (function (_ variable) ## [variable ("php array read" (:as Nat variable) environment)])) ## (dictionary.of_list text.hash)))) @@ -414,7 +414,7 @@ (io.io <default>)) @.python (os::getcwd []) @.lua (do io.monad - [#let [default <default>] + [.let [default <default>] on_windows (..run_command default "cd")] (if (is? default on_windows) (..run_command default "pwd") diff --git a/stdlib/source/library/lux/world/shell.lux b/stdlib/source/library/lux/world/shell.lux index 4f389ce78..696a0a730 100644 --- a/stdlib/source/library/lux/world/shell.lux +++ b/stdlib/source/library/lux/world/shell.lux @@ -232,7 +232,7 @@ [jvm_input (java/lang/Process::getInputStream process) jvm_error (java/lang/Process::getErrorStream process) jvm_output (java/lang/Process::getOutputStream process) - #let [jvm_input (|> jvm_input + .let [jvm_input (|> jvm_input java/io/InputStreamReader::new java/io/BufferedReader::new) jvm_error (|> jvm_error @@ -291,7 +291,7 @@ (def: (execute [environment working_directory command arguments]) (do {! (try.with io.monad)} - [#let [builder (|> (list& command arguments) + [.let [builder (|> (list& command arguments) ..jvm::arguments_array java/lang/ProcessBuilder::new (java/lang/ProcessBuilder::directory (java/io/File::new working_directory)))] |