aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux.lux
diff options
context:
space:
mode:
authorEduardo Julian2021-08-25 16:47:50 -0400
committerEduardo Julian2021-08-25 16:47:50 -0400
commitb216900093c905b3b20dd45c69e577b192e2f7a3 (patch)
tree4d6ac7d257752a8c54ca77dd58df9753ce357ab6 /stdlib/source/library/lux.lux
parent36303d6cb2ce3ab9e36d045b9516c997bd461862 (diff)
Updates to the Lua compiler.
Diffstat (limited to 'stdlib/source/library/lux.lux')
-rw-r--r--stdlib/source/library/lux.lux923
1 files changed, 131 insertions, 792 deletions
diff --git a/stdlib/source/library/lux.lux b/stdlib/source/library/lux.lux
index 9770f131c..389635abc 100644
--- a/stdlib/source/library/lux.lux
+++ b/stdlib/source/library/lux.lux
@@ -13,11 +13,6 @@
[dummy_location (9 #1 (0 #0))]
#0)
-("lux def" __paragraph
- ("lux text concat" \n \n)
- [dummy_location (9 #1 (0 #0))]
- #0)
-
("lux def" prelude_module
"library/lux"
[dummy_location (9 #1 (0 #0))]
@@ -30,11 +25,7 @@
(9 #1 ["library/lux" "Any"]
(8 #0 (0 #0) (4 #0 1))))
[dummy_location
- (9 #1 (0 #1 [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 ("lux text concat"
- ("lux text concat" "The type of things whose type is irrelevant." __paragraph)
- "It can be used to write functions or data-structures that can take, or return, anything."))]]
- (0 #0)))]
+ (9 #1 (0 #0))]
#1)
... (type: .public Nothing
@@ -44,11 +35,7 @@
(9 #1 ["library/lux" "Nothing"]
(7 #0 (0 #0) (4 #0 1))))
[dummy_location
- (9 #1 (0 #1 [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 ("lux text concat"
- ("lux text concat" "The type of things whose type is undefined." __paragraph)
- "Useful for expressions that cause errors or other 'extraordinary' conditions."))]]
- (0 #0)))]
+ (9 #1 (0 #0))]
#1)
... (type: .public (List a)
@@ -65,9 +52,7 @@
[dummy_location
(9 #1 (0 #1 [[dummy_location (7 #0 ["library/lux" "type_args"])]
[dummy_location (9 #0 (0 #1 [dummy_location (5 #0 "a")] (0 #0)))]]
- (0 #1 [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "A potentially empty list of values.")]]
- (0 #0))))]
+ (0 #0)))]
["End" "Item"]
#1)
@@ -76,9 +61,7 @@
(9 #1 ["library/lux" "Bit"]
(0 #0 "#Bit" #End)))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "Your standard, run-of-the-mill boolean values (as bits).")]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" I64
@@ -87,9 +70,7 @@
(7 #0 (0 #0)
(0 #0 "#I64" (#Item (4 #0 1) #End)))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "64-bit integers without any semantics.")]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Nat
@@ -97,11 +78,7 @@
(9 #1 ["library/lux" "Nat"]
(0 #0 "#I64" (#Item (0 #0 "#Nat" #End) #End))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 ("lux text concat"
- ("lux text concat" "Natural numbers (unsigned integers)." __paragraph)
- "They start at zero (0) and extend in the positive direction."))]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Int
@@ -109,9 +86,7 @@
(9 #1 ["library/lux" "Int"]
(0 #0 "#I64" (#Item (0 #0 "#Int" #End) #End))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "Your standard, run-of-the-mill integer numbers.")]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Rev
@@ -119,11 +94,7 @@
(9 #1 ["library/lux" "Rev"]
(0 #0 "#I64" (#Item (0 #0 "#Rev" #End) #End))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 ("lux text concat"
- ("lux text concat" "Fractional numbers that live in the interval [0,1)." __paragraph)
- "Useful for probability, and other domains that work within that interval."))]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Frac
@@ -131,9 +102,7 @@
(9 #1 ["library/lux" "Frac"]
(0 #0 "#Frac" #End)))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "Your standard, run-of-the-mill floating-point (fractional) numbers.")]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Text
@@ -141,9 +110,7 @@
(9 #1 ["library/lux" "Text"]
(0 #0 "#Text" #End)))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "Your standard, run-of-the-mill string values.")]]
- #End))]
+ (9 #1 #End)]
#1)
("lux def" Name
@@ -151,9 +118,7 @@
(9 #1 ["library/lux" "Name"]
(2 #0 Text Text)))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "A name. It is used as part of Lux syntax to represent identifiers and tags.")]]
- #End))]
+ (9 #1 #End)]
#1)
... (type: .public (Maybe a)
@@ -169,9 +134,7 @@
[dummy_location
(9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "type_args"])]
[dummy_location (9 #0 (#Item [dummy_location (5 #0 "a")] #End))]]
- (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "A potentially missing value.")]]
- #End)))]
+ #End))]
["None" "Some"]
#1)
@@ -231,11 +194,9 @@
("lux type check type" (9 #0 Type List)))}
("lux type check type" (9 #0 (4 #0 1) (4 #0 0)))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "This type represents the data-structures that are used to specify types themselves.")]]
- (#Item [[dummy_location (7 #0 ["library/lux" "type_rec?"])]
- [dummy_location (0 #0 #1)]]
- #End)))]
+ (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "type_rec?"])]
+ [dummy_location (0 #0 #1)]]
+ #End))]
["Primitive" "Sum" "Product" "Function" "Parameter" "Var" "Ex" "UnivQ" "ExQ" "Apply" "Named"]
#1)
@@ -247,9 +208,7 @@
(#Named ["library/lux" "Location"]
(#Product Text (#Product Nat Nat)))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "Locations are for specifying the location of Code nodes in Lux files during compilation.")]]
- #End))]
+ (9 #1 #End)]
["module" "line" "column"]
#1)
@@ -263,11 +222,9 @@
(#Product (#Parameter 3)
(#Parameter 1)))))
[dummy_location
- (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "doc"])]
- [dummy_location (5 #0 "The type of things that can be annotated with meta-data of arbitrary types.")]]
- (#Item [[dummy_location (7 #0 ["library/lux" "type_args"])]
- [dummy_location (9 #0 (#Item [dummy_location (5 #0 "m")] (#Item [dummy_location (5 #0 "v")] #End)))]]
- #End)))]
+ (9 #1 (#Item [[dummy_location (7 #0 ["library/lux" "type_args"])]
+ [dummy_location (9 #0 (#Item [dummy_location (5 #0 "m")] (#Item [dummy_location (5 #0 "v")] #End)))]]
+ #End))]
["meta" "datum"]
#1)
@@ -331,41 +288,31 @@
(#Apply (#Apply w Code') w)}
("lux type check type" (#Apply Location Ann))))
[dummy_location
- (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
- [dummy_location (#Text "The type of Code nodes for Lux syntax.")]]
- #End))]
+ (#Record #End)]
#1)
("lux def" private
#0
[dummy_location
- (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
- [dummy_location (#Text "The export policy for private/local definitions.")]]
- #End))]
+ (#Record #End)]
#1)
("lux def" public
#1
[dummy_location
- (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
- [dummy_location (#Text "The export policy for public/global definitions.")]]
- #End))]
+ (#Record #End)]
#1)
("lux def" local
#0
[dummy_location
- (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
- [dummy_location (#Text "The export policy for private/local definitions.")]]
- #End))]
+ (#Record #End)]
#1)
("lux def" global
#1
[dummy_location
- (#Record (#Item [[dummy_location (#Tag ["library/lux" "doc"])]
- [dummy_location (#Text "The export policy for public/global definitions.")]]
- #End))]
+ (#Record #End)]
#1)
("lux def" _ann
@@ -462,10 +409,8 @@
("lux type check type"
(#Named ["library/lux" "Definition"]
(#Product Bit (#Product Type (#Product Code Any)))))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "Represents all the data associated with a definition: its type, its annotations, and its value.")]
- #End))
- #1)
+ (record$ #End)
+ .public)
... (type: .public Alias
... Name)
@@ -474,7 +419,7 @@
(#Named ["library/lux" "Alias"]
Name))
(record$ #End)
- #1)
+ .public)
... (type: .public Global
... (#Alias Alias)
@@ -483,11 +428,9 @@
(#Named ["library/lux" "Global"]
(#Sum Alias
Definition))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "Represents all the data associated with a global constant.")]
- #End))
+ (record$ #End)
["Alias" "Definition"]
- #1)
+ .public)
... (type: .public (Bindings k v)
... {#counter Nat
@@ -506,7 +449,7 @@
(tuple$ (#Item (text$ "k") (#Item (text$ "v") #End)))]
#End))
["counter" "mappings"]
- #1)
+ .public)
... (type: .public Ref
... (#Local Nat)
@@ -519,7 +462,7 @@
Nat))
(record$ #End)
["Local" "Captured"]
- #1)
+ .public)
... (type: .public Scope
... {#name (List Text)
@@ -538,7 +481,7 @@
(#Apply (#Product Type Ref) (#Apply Text Bindings))))))
(record$ #End)
["name" "inner" "locals" "captured"]
- #1)
+ .public)
("lux def" Code_List
("lux type check type"
@@ -559,11 +502,9 @@
(#Parameter 1)))))
(record$ (#Item [(tag$ ["library/lux" "type_args"])
(tuple$ (#Item (text$ "l") (#Item (text$ "r") #End)))]
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ "A choice between two values of different types.")]
- #End)))
+ #End))
["Left" "Right"]
- #1)
+ .public)
... (type: .public Source
... [Location Nat Text])
@@ -572,7 +513,7 @@
(#Named ["library/lux" "Source"]
(#Product Location (#Product Nat Text))))
(record$ #End)
- #1)
+ .public)
... (type: .public Module_State
... #Active
@@ -590,7 +531,7 @@
Any)))
(record$ #End)
["Active" "Compiled" "Cached"]
- #1)
+ .public)
... (type: .public Module
... {#module_hash Nat
@@ -628,11 +569,9 @@
(#Apply Code Maybe)
Module_State))
))))))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "All the information contained within a Lux module.")]
- #End))
+ (record$ #End)
["module_hash" "module_aliases" "definitions" "imports" "tags" "types" "module_annotations" "module_state"]
- #1)
+ .public)
... (type: .public Type_Context
... {#ex_counter Nat
@@ -649,7 +588,7 @@
List))))
(record$ #End)
["ex_counter" "var_counter" "var_bindings"]
- #1)
+ .public)
... (type: .public Mode
... #Build
@@ -663,11 +602,9 @@
Any
... Interpreter
Any)))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "A sign that shows the conditions under which the compiler is running.")]
- #End))
+ (record$ #End)
["Build" "Eval" "Interpreter"]
- #1)
+ .public)
... (type: .public Info
... {#target Text
@@ -683,11 +620,9 @@
Text
... mode
Mode)))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "Information about the current version and type of compiler that is running.")]
- #End))
+ (record$ #End)
["target" "version" "mode"]
- #1)
+ .public)
... (type: .public Lux
... {#info Info
@@ -750,15 +685,9 @@
... host
Any))))))))))))))}
(#Apply (#Parameter 1) (#Parameter 0))))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "Represents the state of the Lux compiler during a run." __paragraph)
- ("lux text concat"
- ("lux text concat" "It is provided to macros during their invocation, so they can access compiler data." __paragraph)
- "Caveat emptor: Avoid fiddling with it, unless you know what you're doing.")))]
- #End))
+ (record$ #End)
["info" "source" "location" "current_module" "modules" "scopes" "type_context" "expected" "seed" "scope_type_vars" "extensions" "eval" "host"]
- #1)
+ .public)
... (type: .public (Meta a)
... (-> Lux (Either Text [Lux a])))
@@ -769,14 +698,10 @@
(#Function Lux
(#Apply (#Product Lux (#Parameter 1))
(#Apply Text Either))))))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "Computations that can have access to the state of the compiler." __paragraph)
- "These computations may fail, or modify the state of the compiler."))]
- (#Item [(tag$ ["library/lux" "type_args"])
- (tuple$ (#Item (text$ "a") #End))]
- #End)))
- #1)
+ (record$ (#Item [(tag$ ["library/lux" "type_args"])
+ (tuple$ (#Item (text$ "a") #End))]
+ #End))
+ .public)
... (type: .public Macro'
... (-> (List Code) (Meta (List Code))))
@@ -785,7 +710,7 @@
(#Named ["library/lux" "Macro'"]
(#Function Code_List (#Apply Code_List Meta))))
(record$ #End)
- #1)
+ .public)
... (type: .public Macro
... (primitive "#Macro"))
@@ -793,10 +718,8 @@
("lux type check type"
(#Named ["library/lux" "Macro"]
(#Primitive "#Macro" #End)))
- (record$ (#Item [(tag$ ["library/lux" "doc"])
- (text$ "Functions that run at compile-time and allow you to transform and extend the language in powerful ways.")]
- #End))
- #1)
+ (record$ #End)
+ .public)
... Base functions & macros
("lux def" in_meta
@@ -988,13 +911,7 @@
#0)
(macro:' .public (comment tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Throws away any code given to it." __paragraph)
- ("lux text concat"
- ("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)
+ #End
(in_meta #End))
(macro:' .private ($' tokens)
@@ -1166,15 +1083,7 @@
(list\mix (function'' [_ acc] ("lux i64 +" 1 acc)) 0 list))
(macro:' .public (All tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Universal quantification." __paragraph)
- ("lux text concat"
- ("lux text concat" "(All [a] (-> a a))" __paragraph)
- ("lux text concat"
- ("lux text concat" "... A name can be provided, to specify a recursive type." __paragraph)
- "(All List [a] (Union Any [a (List a)]))"))))]
- #End)
+ #End
(let'' [self_name tokens] ({(#Item [_ (#Identifier "" self_name)] tokens)
[self_name tokens]
@@ -1211,15 +1120,7 @@
tokens)))
(macro:' .public (Ex tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Existential quantification." __paragraph)
- ("lux text concat"
- ("lux text concat" "(Ex [a] [(Codec Text a) a])" __paragraph)
- ("lux text concat"
- ("lux text concat" "... A name can be provided, to specify a recursive type." __paragraph)
- "(Ex Self [a] [(Codec Text a) a (List (Self a))])"))))]
- #End)
+ #End
(let'' [self_name tokens] ({(#Item [_ (#Identifier "" self_name)] tokens)
[self_name tokens]
@@ -1264,13 +1165,7 @@
list))
(macro:' .public (-> tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Function types:" __paragraph)
- ("lux text concat"
- ("lux text concat" "(-> Int Int Int)" __paragraph)
- "... This is the type of a function that takes 2 Ints and returns an Int.")))]
- #End)
+ #End
({(#Item output inputs)
(in_meta (#Item (list\mix ("lux type check" (#Function Code (#Function Code Code))
(function'' [i o] (form$ (#Item (tag$ ["library/lux" "Function"]) (#Item i (#Item o #End))))))
@@ -1283,11 +1178,7 @@
(list\reversed tokens)))
(macro:' .public (list xs)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... List-construction macro." __paragraph)
- "(list +1 +2 +3)"))]
- #End)
+ #End
(in_meta (#Item (list\mix (function'' [head tail]
(form$ (#Item (tag$ ["library/lux" "Item"])
(#Item (tuple$ (#Item [head (#Item [tail #End])]))
@@ -1297,13 +1188,7 @@
#End)))
(macro:' .public (list& xs)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... List-construction macro, with the last element being a tail-list." __paragraph)
- ("lux text concat"
- ("lux text concat" "... In other words, this macro prepends elements to another list." __paragraph)
- "(list& +1 +2 +3 (list +4 +5 +6))")))]
- #End)
+ #End
({(#Item last init)
(in_meta (list (list\mix (function'' [head tail]
(form$ (list (tag$ ["library/lux" "Item"])
@@ -1316,15 +1201,7 @@
(list\reversed xs)))
(macro:' .public (Union tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Union types:" __paragraph)
- ("lux text concat"
- ("lux text concat" "(Union Text Int Bit)" __paragraph)
- ("lux text concat"
- ("lux text concat" "... Nothing." __paragraph)
- "(Union)"))))]
- #End)
+ #End
({#End
(in_meta (list (identifier$ ["library/lux" "Nothing"])))
@@ -1335,15 +1212,7 @@
(list\reversed tokens)))
(macro:' .public (Tuple tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Tuple types:" __paragraph)
- ("lux text concat"
- ("lux text concat" "(Tuple Text Int Bit)" __paragraph)
- ("lux text concat"
- ("lux text concat" "... Any." __paragraph)
- "(&)"))))]
- #End)
+ #End
({#End
(in_meta (list (identifier$ ["library/lux" "Any"])))
@@ -1412,16 +1281,12 @@
tokens))
(def:''' .public Or
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ "An alias for the Union type constructor.")]
- #End)
+ #End
Macro
..Union)
(def:''' .public And
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ "An alias for the Tuple type constructor.")]
- #End)
+ #End
Macro
..Tuple)
@@ -1507,15 +1372,7 @@
(func left right)))
(macro:' .public (_$ tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Left-association for the application of binary functions over variadic arguments." ..\n)
- ("lux text concat"
- ("lux text concat" "(_$ text\composite ''Hello, '' name ''. How are you?'')" ..\n)
- ("lux text concat"
- ("lux text concat" "... =>" ..\n)
- "(text\composite (text\composite ''Hello, '' name) ''. How are you?'')"))))]
- #End)
+ #End
({(#Item op tokens')
({(#Item first nexts)
(in_meta (list (list\mix (function\flipped (right_associativity op)) first nexts)))
@@ -1529,15 +1386,7 @@
tokens))
(macro:' .public ($_ tokens)
- (#Item [(tag$ ["library/lux" "doc"])
- (text$ ("lux text concat"
- ("lux text concat" "... Right-association for the application of binary functions over variadic arguments." ..\n)
- ("lux text concat"
- ("lux text concat" "($_ text\composite ''Hello, '' name ''. How are you?'')" ..\n)
- ("lux text concat"
- ("lux text concat" "... =>" ..\n)
- "(text\composite ''Hello, '' (text\composite name ''. How are you?''))"))))]
- #End)
+ #End
({(#Item op tokens')
({(#Item last prevs)
(in_meta (list (list\mix (right_associativity op) last prevs)))
@@ -1670,11 +1519,7 @@
xs)))
(macro:' .public (if tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "Picks which expression to evaluate based on a bit test value." __paragraph
- "(if #1 ''Oh, yeah!'' ''Aw hell naw!'')" __paragraph
- "=> ''Oh, yeah!''"))])
+ (list)
({(#Item test (#Item then (#Item else #End)))
(in_meta (list (form$ (list (record$ (list [(bit$ #1) then]
[(bit$ #0) else]))
@@ -1885,11 +1730,7 @@
[replace? token]))
(macro:' .public (primitive tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Macro to treat define new primitive types." __paragraph
- "(primitive ''java.lang.Object'')" __paragraph
- "(primitive ''java.util.List'' [(primitive ''java.lang.Long'')])"))])
+ (list)
({(#Item [_ (#Text class_name)] #End)
(in_meta (list (form$ (list (tag$ ["library/lux" "Primitive"]) (text$ class_name) (tag$ ["library/lux" "End"])))))
@@ -1916,11 +1757,7 @@
state))
(macro:' .public (` tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Hygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." __paragraph
- "... All unprefixed macros will receive their parent module's prefix if imported; otherwise will receive the prefix of the module on which the quasi-quote is being used." __paragraph
- "(` (def: (~ name) (function ((~' _) (~+ args)) (~ body))))"))])
+ (list)
({(#Item template #End)
(do meta_monad
[current_module current_module_name
@@ -1934,10 +1771,7 @@
tokens))
(macro:' .public (`' tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." __paragraph
- "(`' (def: (~ name) (function (_ (~+ args)) (~ body))))"))])
+ (list)
({(#Item template #End)
(do meta_monad
[=template (untemplated #1 "" template)]
@@ -1948,10 +1782,7 @@
tokens))
(macro:' .public (' tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Quotation as a macro." __paragraph
- "(' YOLO)"))])
+ (list)
({(#Item template #End)
(do meta_monad
[=template (untemplated #0 "" template)]
@@ -1962,12 +1793,7 @@
tokens))
(macro:' .public (|> tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Piping macro." __paragraph
- "(|> elems (list\each int\encoded) (interposed '' '') (mix text\composite ''''))" __paragraph
- "... =>" __paragraph
- "(mix text\composite '''' (interposed '' '' (list\each int\encoded elems)))"))])
+ (list)
({(#Item [init apps])
(in_meta (list (list\mix ("lux type check" (-> Code Code Code)
(function' [app acc]
@@ -1988,12 +1814,7 @@
tokens))
(macro:' .public (<| tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Reverse piping macro." __paragraph
- "(<| (mix text\composite '''') (interposed '' '') (list\each int\encoded) elems)" __paragraph
- "... =>" __paragraph
- "(mix text\composite '''' (interposed '' '' (list\each int\encoded elems)))"))])
+ (list)
({(#Item [init apps])
(in_meta (list (list\mix ("lux type check" (-> Code Code Code)
(function' [app acc]
@@ -2122,13 +1943,6 @@
(low_bits sample))
#0))))
-(def:''' .private (n/<= reference sample)
- (list)
- (-> Nat Nat Bit)
- (if (n/< reference sample)
- #1
- ("lux i64 =" reference sample)))
-
(def:''' .private (list\conjoint xs)
#End
(All [a]
@@ -2136,13 +1950,7 @@
(list\mix list\composite #End (list\reversed xs)))
(macro:' .public (template tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... By specifying a pattern (with holes), and the input data to fill those holes, repeats the pattern as many times as necessary." __paragraph
- "(template [<name> <diff>]" ..\n
- " " "[(def: .public <name> (-> Int Int) (+ <diff>))]" __paragraph
- " " "[++ +1]" ..\n
- " " "[-- -1]"))])
+ (list)
({(#Item [[_ (#Tuple bindings)] (#Item [[_ (#Tuple templates)] data])])
({[(#Some bindings') (#Some data')]
(let' [apply ("lux type check" (-> Replacement_Environment ($' List Code))
@@ -2267,11 +2075,7 @@
(|> n (n/% div) ("lux i64 =" 0)))
(def:''' .public (not x)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Bit negation." __paragraph
- "(not #1) => #0" __paragraph
- "(not #0) => #1"))])
+ (list)
(-> Bit Bit)
(if x #0 #1))
@@ -2534,10 +2338,7 @@
type))
(macro:' .public (type tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Takes a type expression and returns its representation as data-structure." __paragraph
- "(type (All [a] (Maybe (List a))))"))])
+ (list)
({(#Item type #End)
(do meta_monad
[type+ (full_expansion type)]
@@ -2553,10 +2354,7 @@
tokens))
(macro:' .public (: tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... The type-annotation macro." __paragraph
- "(: (List Int) (list +1 +2 +3))"))])
+ (list)
({(#Item type (#Item value #End))
(in_meta (list (` ("lux type check" (type (~ type)) (~ value)))))
@@ -2565,10 +2363,7 @@
tokens))
(macro:' .public (:as tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... The type-coercion macro." __paragraph
- "(:as Dinosaur (list +1 +2 +3))"))])
+ (list)
({(#Item type (#Item value #End))
(in_meta (list (` ("lux type as" (type (~ type)) (~ value)))))
@@ -2610,11 +2405,6 @@
state))
(macro:' .public (Rec tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Parameter-less recursive types." __paragraph
- "... A name has to be given to the whole type, to use it within its body." __paragraph
- "(Rec Self [Int (List Self)])"))])
({(#Item [_ (#Identifier "" name)] (#Item body #End))
(let' [body' (|> body
nested_quantification
@@ -2626,14 +2416,7 @@
tokens))
(macro:' .public (exec tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Sequential execution of expressions (great for side-effects)." __paragraph
- "(exec" ..\n
- " " "(log! ''#1'')" ..\n
- " " "(log! ''#2'')" ..\n
- " " "(log! ''#3'')" ..\n
- "''YOLO'')"))])
+ (list)
({(#Item value actions)
(let' [dummy (local_identifier$ "")]
(in_meta (list (list\mix ("lux type check" (-> Code Code Code)
@@ -2720,15 +2503,7 @@
branches))
(macro:' .public (case tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... The pattern-matching macro." ..\n
- "... Allows the usage of macros within the patterns to provide custom syntax." ..\n
- "(case (: (List Int) (list +1 +2 +3))" ..\n
- " " "(#Item x (#Item y (#Item z #End)))" ..\n
- " " "(#Some ($_ * x y z))" __paragraph
- " " "_" ..\n
- " " "#None)"))])
+ (list)
({(#Item value branches)
(do meta_monad
[expansion (expander branches)]
@@ -2739,16 +2514,7 @@
tokens))
(macro:' .public (^ tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Macro-expanding patterns." ..\n
- "... It's a special macro meant to be used with 'case'." ..\n
- "(case (: (List Int) (list +1 +2 +3))" ..\n
- " (^ (list x y z))" ..\n
- " (#Some ($_ * x y z))"
- __paragraph
- " _" ..\n
- " #None)"))])
+ (list)
(case tokens
(#Item [_ (#Form (#Item pattern #End))] (#Item body branches))
(do meta_monad
@@ -2764,20 +2530,7 @@
(failure "Wrong syntax for ^ macro")))
(macro:' .public (^or tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Or-patterns." ..\n
- "... It's a special macro meant to be used with 'case'." ..\n
- "(type: Weekday #Monday #Tuesday #Wednesday #Thursday #Friday #Saturday #Sunday)"
- __paragraph
- "(def: (weekend? day)" ..\n
- " (-> Weekday Bit)" ..\n
- " (case day" ..\n
- " (^or #Saturday #Sunday)" ..\n
- " #1"
- __paragraph
- " _" ..\n
- " #0))"))])
+ (list)
(case tokens
(^ (list& [_ (#Form patterns)] body branches))
(case patterns
@@ -2802,13 +2555,7 @@
#0))
(macro:' .public (let tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Creates local bindings." ..\n
- "... Can (optionally) use pattern-matching macros when binding." ..\n
- "(let [x (foo bar)" ..\n
- " y (baz quux)]" ..\n
- " (op x y))"))])
+ (list)
(case tokens
(^ (list [_ (#Tuple bindings)] body))
(if (multiple? 2 (list\size bindings))
@@ -2828,15 +2575,7 @@
(failure "Wrong syntax for let")))
(macro:' .public (function tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Syntax for creating functions." ..\n
- "... Allows for giving the function itself a name, for the sake of recursion." ..\n
- "(: (All [a b] (-> a b a))" ..\n
- " (function (_ x y) x))"
- __paragraph
- "(: (All [a b] (-> a b a))" ..\n
- " (function (constant x y) x))"))])
+ (list)
(case (: (Maybe [Text Code (List Code) Code])
(case tokens
(^ (list [_ (#Form (list& [_ (#Identifier ["" name])] head tail))] body))
@@ -3093,17 +2832,7 @@
))
(macro:' .public (def: tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Defines global constants/functions." ..\n
- "(def: (pair_list pair)" ..\n
- " (-> [Code Code] (List Code))" ..\n
- " (let [[left right] pair]" ..\n
- " (list left right)))"
- __paragraph
- "(def: branching_exponent" ..\n
- " Int" ..\n
- " +5)"))])
+ (list)
(case (definitionP tokens)
(#Some [export_policy name parameters annotations ?type body])
(let [body (case parameters
@@ -3191,18 +2920,7 @@
))
(macro:' .public (macro: tokens)
- (list [(tag$ ["library/lux" "doc"])
- (text$ ($_ "lux text concat"
- "... Macro-definition macro." ..\n
- "(macro: .public (name_of tokens)" ..\n
- " (case tokens" ..\n
- " (^template [<tag>]" ..\n
- " [(^ (list [_ (<tag> [module name])]))" ..\n
- " (in (list (` [(~ (text$ module)) (~ (text$ name))])))])" ..\n
- " ([#Identifier] [#Tag])"
- __paragraph
- " _" ..\n
- " (failure ''Wrong syntax for name_of'')))"))])
+ (list)
(case (macroP tokens)
(#Some [export_policy name args annotations body])
(let [name (local_identifier$ name)
@@ -3238,9 +2956,8 @@
(#Some y)
(#Some y))))
-(template [<name> <form> <message> <documentation>]
+(template [<name> <form> <message>]
[(macro: .public (<name> tokens)
- {#.doc <documentation>}
(case (list\reversed tokens)
(^ (list& last init))
(in_meta (list (list\mix (: (-> Code Code Code)
@@ -3251,28 +2968,18 @@
_
(failure <message>)))]
- [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses." "Short-circuiting 'and': (and #1 #0 #1) ... => #0"]
- [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses." "Short-circuiting 'or': (or #1 #0 #1) ... => #1"])
+ [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses."]
+ [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses."])
(def: (index part text)
(-> Text Text (Maybe Nat))
("lux text index" 0 part text))
(def: .public (panic! message)
- {#.doc (text$ ($_ "lux text concat"
- "... Causes an error, with the given error message." ..\n
- "(panic! ''OH NO!'')"))}
(-> Text Nothing)
("lux io error" message))
-(macro: (else tokens state)
- {#.doc (text$ ($_ "lux text concat"
- "... Allows you to provide a default value that will be used" ..\n
- "... if a (Maybe x) value turns out to be #.None."
- __paragraph
- "(else +20 (#.Some +10)) ... => +10"
- __paragraph
- "(else +20 #.None) ... => +20"))}
+(macro: (maybe\else tokens state)
(case tokens
(^ (list else maybe))
(let [g!temp (: Code [dummy_location (#Identifier ["" ""])])
@@ -3285,7 +2992,7 @@
(#Right [state (list code)]))
_
- (#Left "Wrong syntax for else")))
+ (#Left "Wrong syntax for maybe\else")))
(def: (text\all_split_by splitter input)
(-> Text Text (List Text))
@@ -3504,22 +3211,6 @@
(#Left "Not expecting any type.")))))
(macro: .public (implementation tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Express a value that implements an interface." ..\n
- "(: (Order Int)" ..\n
- " (implementation" ..\n
- " (def: &equivalence equivalence)" ..\n
- " (def: (< test subject)" ..\n
- " (< test subject))" ..\n
- " (def: (<= test subject)" ..\n
- " (or (< test subject)" ..\n
- " (= test subject)))" ..\n
- " (def: (> test subject)" ..\n
- " (> test subject))" ..\n
- " (def: (>= test subject)" ..\n
- " (or (> test subject)" ..\n
- " (= test subject)))" ..\n
- " ))"))}
(do meta_monad
[tokens' (monad\each meta_monad expansion tokens)
struct_type ..expected_type
@@ -3572,56 +3263,40 @@
_
(#Item tokens)))
-(def:' .private (implementationP tokens)
- (-> (List Code) (Maybe [Code Text (List Code) (List [Code Code]) Code (List Code)]))
- (|> (do maybe_monad
- [% (enhanced_declarationP tokens)
- .let' [[tokens [export_policy name parameters]] %]
- % (annotationsP tokens)
- .let' [[tokens annotations] %]
- % (anyP tokens)
- .let' [[tokens type] %]
- tokens (remainderP tokens)]
- (in [export_policy name parameters annotations type tokens]))
- ... (^ (list _export_policy _declaration _annotations _type _body))
- ... (^ (list _declaration _annotations _type _body))
- (maybe\else' (do maybe_monad
- [% (enhanced_local_declarationP tokens)
- .let' [[tokens [name parameters]] %]
- % (anyP tokens)
- .let' [[tokens type] %]
- tokens (remainderP tokens)]
- (in [(` ..private) name parameters #End type tokens])))
- ... (^ (list _declaration _type _body))
- (maybe\else' (do maybe_monad
- [% (anyP tokens)
- .let' [[tokens export_policy] %]
- % (enhanced_local_declarationP tokens)
- .let' [[tokens [name parameters]] %]
- % (anyP tokens)
- .let' [[tokens type] %]
- tokens (remainderP tokens)]
- (in [export_policy name parameters #End type tokens])))
- ... (^ (list _export_policy _declaration _type _body))
- ))
+(def: (implementationP tokens)
+ (-> (List Code) (Maybe [Code Text (List Code) (List [Code Code]) Code (List Code)]))
+ (|> (do maybe_monad
+ [% (enhanced_declarationP tokens)
+ .let' [[tokens [export_policy name parameters]] %]
+ % (annotationsP tokens)
+ .let' [[tokens annotations] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [export_policy name parameters annotations type tokens]))
+ ... (^ (list _export_policy _declaration _annotations _type _body))
+ ... (^ (list _declaration _annotations _type _body))
+ (maybe\else' (do maybe_monad
+ [% (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [(` ..private) name parameters #End type tokens])))
+ ... (^ (list _declaration _type _body))
+ (maybe\else' (do maybe_monad
+ [% (anyP tokens)
+ .let' [[tokens export_policy] %]
+ % (enhanced_local_declarationP tokens)
+ .let' [[tokens [name parameters]] %]
+ % (anyP tokens)
+ .let' [[tokens type] %]
+ tokens (remainderP tokens)]
+ (in [export_policy name parameters #End type tokens])))
+ ... (^ (list _export_policy _declaration _type _body))
+ ))
(macro: .public (implementation: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Interface implementation." ..\n
- "(implementation: .public order" ..\n
- " (Order Int)" ..\n
- ..\n
- " (def: &equivalence equivalence)" ..\n
- " (def: (< test subject)" ..\n
- " (< test subject))" ..\n
- " (def: (<= test subject)" ..\n
- " (or (< test subject)" ..\n
- " (= test subject)))" ..\n
- " (def: (> test subject)" ..\n
- " (> test subject))" ..\n
- " (def: (>= test subject)" ..\n
- " (or (> test subject)" ..\n
- " (= test subject))))"))}
(case (implementationP tokens)
(#Some [export_policy name args annotations type definitions])
(let [usage (case args
@@ -3815,12 +3490,6 @@
it))
(macro: .public (type: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... The type-definition macro." ..\n
- "(type: (List a)" ..\n
- " {#.doc (example (: (List Nat) (list 0 1 2 3)))}" ..\n
- " #End" ..\n
- " (#Item a (List a)))"))}
(case (typeP tokens)
(#Some [export_policy rec? name args meta type_codes])
(do meta_monad
@@ -3899,13 +3568,6 @@
))
(macro: .public (interface: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Interface definition." ..\n
- "(interface: .public (Order a)" ..\n
- " (: (Equivalence a)" ..\n
- " &equivalence)" ..\n
- " (: (-> a a Bit)" ..\n
- " <))"))}
(case (interfaceP tokens)
(#Some [export_policy name args annotations methods])
(do meta_monad
@@ -3943,7 +3605,6 @@
(template [<name> <to>]
[(def: .public (<name> value)
- {#.doc "Safe type-casting for I64 values."}
(-> (I64 Any) <to>)
(:as <to> value))]
@@ -4074,7 +3735,6 @@
(replaced ..contextual_reference context)))
(def: .public module_separator
- {#.doc "Character used to separate the parts of module names."}
"/")
(def: parallel_hierarchy_sigil
@@ -4478,12 +4138,6 @@
))
(macro: .public (^open tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Same as the 'open' macro, but meant to be used as a pattern-matching macro for generating local bindings." ..\n
- "... Takes an 'alias' text for the generated local bindings." ..\n
- "(def: .public (range (^open ''.'') minimum additional)" ..\n
- " (All [a] (-> (Enum a) a a (List a)))" ..\n
- " (range' <= succ minimum additional))"))}
(case tokens
(^ (list& [_ (#Form (list [_ (#Text alias)]))] body branches))
(do meta_monad
@@ -4529,13 +4183,6 @@
(failure "Wrong syntax for ^open")))
(macro: .public (cond tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Branching structures with multiple test conditions." ..\n
- "(cond (even? num) ''even''" ..\n
- " (odd? num) ''odd''"
- __paragraph
- " ... else_branch" ..\n
- " ''???'')"))}
(if ("lux i64 =" 0 (n/% 2 (list\size tokens)))
(failure "cond requires an uneven number of arguments.")
(case (list\reversed tokens)
@@ -4564,16 +4211,6 @@
(enumeration' 0 xs))
(macro: .public (value@ tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Accesses the value of a record at a given tag." ..\n
- "(value@ #field my_record)"
- __paragraph
- "... Can also work with multiple levels of nesting:" ..\n
- "(value@ [#foo #bar #baz] my_record)"
- __paragraph
- "... And, if only the slot/path is given, generates an accessor function:" ..\n
- "(let [getter (value@ [#foo #bar #baz])]" ..\n
- " (getter my_record))"))}
(case tokens
(^ (list [_ (#Tag slot')] record))
(do meta_monad
@@ -4643,17 +4280,6 @@
#0)))))))
(macro: .public (open: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Opens a implementation and generates a definition for each of its members (including nested members)."
- __paragraph
- "... For example:" ..\n
- "(open: ''i:.'' number)"
- __paragraph
- "... Will generate:" ..\n
- "(def: i:+ (\ number +))" ..\n
- "(def: i:- (\ number -))" ..\n
- "(def: i:* (\ number *))" ..\n
- "..."))}
(case tokens
(^ (list [_ (#Text alias)] struct))
(case struct
@@ -4686,22 +4312,12 @@
(failure "Wrong syntax for open:")))
(macro: .public (|>> tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n
- "(|>> (list\each int\encoded) (interposed '' '') (mix text\composite ''''))" ..\n
- "... =>" ..\n
- "(function (_ <arg>) (mix text\composite '''' (interposed '' '' (list\each int\encoded <arg>))))"))}
(do meta_monad
[g!_ (..identifier "_")
g!arg (..identifier "arg")]
(in_meta (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens))))))))
(macro: .public (<<| tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..\n
- "(<<| (mix text\composite '''') (interposed '' '') (list\each int\encoded))" ..\n
- "... =>" ..\n
- "(function (_ <arg>) (mix text\composite '''' (interposed '' '' (list\each int\encoded <arg>))))"))}
(do meta_monad
[g!_ (..identifier "_")
g!arg (..identifier "arg")]
@@ -4793,7 +4409,7 @@
(def: (refer_code module_name module_alias' [r_defs r_opens])
(-> Text (Maybe Text) Refer Code)
- (let [module_alias (..else module_name module_alias')
+ (let [module_alias (..maybe\else module_name module_alias')
localizations (: (List Code)
(case r_defs
#All
@@ -4819,23 +4435,6 @@
(~+ openings)))))
(macro: .public (module: tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Module_definition macro."
- __paragraph
- "... Can take optional annotations and allows the specification of modules to import."
- __paragraph
- "... Example" ..\n
- "(.module: {#.doc ''Some documentation...''}" ..\n
- " [lux #*" ..\n
- " [control" ..\n
- " [''M'' monad #*]]" ..\n
- " [data" ..\n
- " maybe" ..\n
- " [''.'' name (''#/.'' codec)]]" ..\n
- " [macro" ..\n
- " code]]" ..\n
- " [//" ..\n
- " [type (''.'' equivalence)]])"))}
(do meta_monad
[.let [[_meta _imports] (: [(List [Code Code]) (List Code)]
(case tokens
@@ -4849,7 +4448,7 @@
.let [=imports (|> imports
(list\each (: (-> Importation Code)
(function (_ [module_name m_alias =refer])
- (` [(~ (text$ module_name)) (~ (text$ (..else "" m_alias)))]))))
+ (` [(~ (text$ module_name)) (~ (text$ (..maybe\else "" m_alias)))]))))
tuple$)
=refers (list\each (: (-> Importation Code)
(function (_ [module_name m_alias =refer])
@@ -4861,12 +4460,6 @@
(in (#Item =module =refers))))
(macro: .public (\ tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Allows accessing the value of a implementation's member." ..\n
- "(\ codec encoded)"
- __paragraph
- "... Also allows using that value as a function." ..\n
- "(\ codec encoded +123)"))}
(case tokens
(^ (list struct [_ (#Identifier member)]))
(in_meta (list (` (let [(^open (~ (text$ ..self_reference))) (~ struct)] (~ (identifier$ member))))))
@@ -4878,16 +4471,6 @@
(failure "Wrong syntax for \")))
(macro: .public (with@ tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Sets the value of a record at a given tag." ..\n
- "(with@ #name ''Lux'' lang)"
- __paragraph
- "... Can also work with multiple levels of nesting:" ..\n
- "(with@ [#foo #bar #baz] value my_record)"
- __paragraph
- "... And, if only the slot/path and (optionally) the value are given, generates a mutator function:" ..\n
- "(let [setter (with@ [#foo #bar #baz] value)] (setter my_record))" ..\n
- "(let [setter (with@ [#foo #bar #baz])] (setter value my_record))"))}
(case tokens
(^ (list [_ (#Tag slot')] value record))
(do meta_monad
@@ -4967,16 +4550,6 @@
(failure "Wrong syntax for with@")))
(macro: .public (revised@ tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Modifies the value of a record at a given tag, based on some function." ..\n
- "(revised@ #age ++ person)"
- __paragraph
- "... Can also work with multiple levels of nesting:" ..\n
- "(revised@ [#foo #bar #baz] func my_record)"
- __paragraph
- "... And, if only the slot/path and (optionally) the value are given, generates a mutator function:" ..\n
- "(let [updater (revised@ [#foo #bar #baz] func)] (updater my_record))" ..\n
- "(let [updater (revised@ [#foo #bar #baz])] (updater func my_record))"))}
(case tokens
(^ (list [_ (#Tag slot')] fun record))
(do meta_monad
@@ -5042,40 +4615,6 @@
(failure "Wrong syntax for revised@")))
(macro: .public (^template tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... It's similar to template, but meant to be used during pattern-matching." ..\n
- "(def: (reduced env type)" ..\n
- " (-> (List Type) Type Type)" ..\n
- " (case type" ..\n
- " (#.Primitive name params)" ..\n
- " (#.Primitive name (list\each (reduced env) params))"
- __paragraph
- " (^template [<tag>]" ..\n
- " [(<tag> left right)" ..\n
- " (<tag> (reduced env left) (reduced env right))])" ..\n
- " ([#.Sum] [#.Product])"
- __paragraph
- " (^template [<tag>]" ..\n
- " [(<tag> left right)" ..\n
- " (<tag> (reduced env left) (reduced env right))])" ..\n
- " ([#.Function] [#.Apply])"
- __paragraph
- " (^template [<tag>]" ..\n
- " [(<tag> old_env def)" ..\n
- " (case old_env" ..\n
- " #.End" ..\n
- " (<tag> env def)"
- __paragraph
- " _" ..\n
- " type)])" ..\n
- " ([#.UnivQ] [#.ExQ])"
- __paragraph
- " (#.Parameter idx)" ..\n
- " (else type (list.item idx env))"
- __paragraph
- " _" ..\n
- " type" ..\n
- " ))"))}
(case tokens
(^ (list& [_ (#Form (list [_ (#Tuple bindings)]
[_ (#Tuple templates)]))]
@@ -5145,14 +4684,13 @@
_
(#Documentation_Example code)))
-(template [<name> <extension> <doc>]
+(template [<name> <extension>]
[(def: .public <name>
- {#.doc <doc>}
(All [s] (-> (I64 s) (I64 s)))
(|>> (<extension> 1)))]
- [++ "lux i64 +" "Increment function."]
- [-- "lux i64 -" "Decrement function."]
+ [++ "lux i64 +"]
+ [-- "lux i64 -"]
)
(def: tag\encoded
@@ -5232,20 +4770,9 @@
(let [baseline (baseline_column example)
[location _] example
[_ text] (..example_documentation (with@ #column baseline location) baseline example)]
- (text\composite text __paragraph))))
+ (text\composite text "\n\n"))))
(macro: .public (example tokens)
- {#.doc (text$ ($_ "lux text concat"
- "... Creates code documentation, embedding text as comments and properly formatting the forms it's being given."
- __paragraph
- "... For Example:" ..\n
- "(example ''Allows arbitrary looping, using the 'recur' form to re-start the loop.''" ..\n
- " ''Can be used in monadic code to create monadic loops.''" ..\n
- " (loop [count +0" ..\n
- " x init]" ..\n
- " (if (< +10 count)" ..\n
- " (recur (++ count) (f x))" ..\n
- " x)))"))}
(in_meta (list (` [(~ location_code)
(#.Text (~ (|> tokens
(list\each (|>> ..documentation_fragment ..fragment_documentation))
@@ -5298,21 +4825,6 @@
(identifier$ [module name])))
(macro: .public (loop tokens)
- {#.doc (example "Allows arbitrary looping, using the 'recur' form to re-start the loop."
- "Can be used in monadic code to create monadic loops."
- (loop [count +0
- x init]
- (if (< +10 count)
- (recur (++ count) (f x))
- x))
-
- "Loops can also be given custom names."
- (loop my_loop
- [count +0
- x init]
- (if (< +10 count)
- (my_loop (++ count) (f x))
- x)))}
(let [?params (case tokens
(^ (list name [_ (#Tuple bindings)] body))
(#Some [name bindings body])
@@ -5355,10 +4867,6 @@
(failure "Wrong syntax for loop"))))
(macro: .public (^slots tokens)
- {#.doc (example "Allows you to extract record members as local variables with the same names."
- "For example:"
- (let [(^slots [#foo #bar #baz]) quux]
- (f foo bar baz)))}
(case tokens
(^ (list& [_ (#Form (list [_ (#Tuple (list& hslot' tslots'))]))] body branches))
(do meta_monad
@@ -5433,25 +4941,6 @@
(in (list [location (#Record =pairs)])))))
(macro: .public (with_expansions tokens)
- {#.doc (example "Controlled macro-expansion."
- "Bind an arbitraty number of Code nodes resulting from macro-expansion to local bindings."
- "Wherever a binding appears, the bound Code nodes will be spliced in there."
- (test: "Code operations & implementations"
- (with_expansions
- [<tests> (template [<expr> <text>]
- [(compare <text> (\ codec encoded <expr>))]
-
- [(bit #1) "#1"]
- [(int +123) "+123"]
- [(frac +123.0) "+123.0"]
- [(text "123") "'123'"]
- [(tag ["yolo" "lol"]) "#yolo.lol"]
- [(identifier ["yolo" "lol"]) "yolo.lol"]
- [(form (list (bit #1))) "(#1)"]
- [(tuple (list (bit #1))) "[#1]"]
- [(record (list [(bit #1) (int +123)])) "{#1 +123}"]
- )]
- (test_all <tests>))))}
(case tokens
(^ (list& [_ (#Tuple bindings)] bodies))
(case bindings
@@ -5551,27 +5040,6 @@
))
(macro: .public (static tokens)
- {#.doc (example "Resolves the names of definitions to their values at compile-time, assuming their values are either:"
- "* Bit"
- "* Nat"
- "* Int"
- "* Rev"
- "* Frac"
- "* Text"
- (def: my_nat 123)
- (def: my_text "456")
- (and (case [my_nat my_text]
- (^ (static [..my_nat ..my_text]))
- true
-
- _
- false)
- (case [my_nat my_text]
- (^ [(static ..my_nat) (static ..my_text)])
- true
-
- _
- false)))}
(case tokens
(^ (list pattern))
(do meta_monad
@@ -5626,26 +5094,6 @@
(list init_pattern inner_pattern_body)))
(macro: .public (^multi tokens)
- {#.doc (example "Multi-level pattern matching."
- "Useful in situations where the result of a branch depends on further refinements on the values being matched."
- "For example:"
- (case (split (size static) uri)
- (^multi (#Some [chunk uri'])
- {(text\= static chunk) #1})
- (match_uri endpoint? parts' uri')
-
- _
- (#Left (format "Static part " (%t static) " does not match URI: " uri)))
-
- "Short-cuts can be taken when using bit tests."
- "The example above can be rewritten as..."
- (case (split (size static) uri)
- (^multi (#Some [chunk uri'])
- (text\= static chunk))
- (match_uri endpoint? parts' uri')
-
- _
- (#Left (format "Static part " (%t static) " does not match URI: " uri))))}
(case tokens
(^ (list& [_meta (#Form levels)] body next_branches))
(do meta_monad
@@ -5686,10 +5134,6 @@
(text\composite "Wrong syntax for ")))
(macro: .public (name_of tokens)
- {#.doc (example "Given an identifier or a tag, gives back a 2 tuple with the module and name parts, both as Text."
- (name_of #.doc)
- "=>"
- ["library/lux" "doc"])}
(case tokens
(^template [<tag>]
[(^ (list [_ (<tag> [module name])]))
@@ -5709,15 +5153,6 @@
(#Right [state scope_type_vars])))
(macro: .public (:parameter tokens)
- {#.doc (example "NOTE: Please stay away from this macro. It's very likely to be removed in a future version of Lux."
- "Allows you to refer to the type-variables in a polymorphic function's type, by their index."
- "In the example below, 0 corresponds to the 'a' variable."
- (def: .public (of_list list)
- (All [a] (-> (List a) (Row a)))
- (list\mix add
- (: (Row (:parameter 0))
- empty)
- list)))}
(case tokens
(^ (list [_ (#Nat idx)]))
(do meta_monad
@@ -5733,22 +5168,10 @@
(failure (..wrong_syntax_error (name_of ..$)))))
(def: .public (same? reference sample)
- {#.doc (example "Tests whether the 2 values are identical (not just 'equal')."
- "This one should succeed:"
- (let [value +5]
- (same? value value))
-
- "This one should fail:"
- (same? +5 (+ +2 +3)))}
(All [a] (-> a a Bit))
("lux is" reference sample))
(macro: .public (^@ tokens)
- {#.doc (example "Allows you to simultaneously bind and de-structure a value."
- (def: (hash (^@ set [Hash<a> _]))
- (list\mix (function (_ elem acc) (+ (\ Hash<a> hash elem) acc))
- 0
- (to_list set))))}
(case tokens
(^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] pattern))] body branches))
(let [g!whole (local_identifier$ name)]
@@ -5760,10 +5183,6 @@
(failure (..wrong_syntax_error (name_of ..^@)))))
(macro: .public (^|> tokens)
- {#.doc (example "Pipes the value being pattern-matched against prior to binding it to a variable."
- (case input
- (^|> value [++ (% 10) (max 1)])
- (foo value)))}
(case tokens
(^ (list& [_meta (#Form (list [_ (#Identifier ["" name])] [_ (#Tuple steps)]))] body branches))
(let [g!name (local_identifier$ name)]
@@ -5776,10 +5195,6 @@
(failure (..wrong_syntax_error (name_of ..^|>)))))
(macro: .public (:expected tokens)
- {#.doc (example "Coerces the given expression to the type of whatever is expected."
- (: Dinosaur
- (:expected (: (List Nat)
- (list 1 2 3)))))}
(case tokens
(^ (list expr))
(do meta_monad
@@ -5790,18 +5205,11 @@
(failure (..wrong_syntax_error (name_of ..:expected)))))
(def: location
- {#.doc "The location of the current expression being analyzed."}
(Meta Location)
(function (_ compiler)
(#Right [compiler (value@ #location compiler)])))
(macro: .public (undefined tokens)
- {#.doc (example "Meant to be used as a stand-in for functions with undefined implementations."
- "Undefined expressions will type-check against everything, so they make good dummy implementations."
- "However, if an undefined expression is ever evaluated, it will raise a runtime error."
- (def: (square x)
- (-> Int Int)
- (undefined)))}
(case tokens
#End
(do meta_monad
@@ -5815,17 +5223,6 @@
(failure (..wrong_syntax_error (name_of ..undefined)))))
(macro: .public (:of tokens)
- {#.doc (example "Generates the type corresponding to a given expression."
- "Example #1:"
- (let [my_num +123]
- (:of my_num))
- "=="
- Int
- "-------------------"
- "Example #2:"
- (:of +123)
- "=="
- Int)}
(case tokens
(^ (list [_ (#Identifier var_name)]))
(do meta_monad
@@ -5882,10 +5279,6 @@
))
(macro: .public (template: tokens)
- {#.doc (example "Define macros in the style of template and ^template."
- "For simple macros that do not need any fancy features."
- (template: (square x)
- (* x x)))}
(case (templateP tokens)
(#Some [export_policy name args anns input_templates])
(do meta_monad
@@ -5914,21 +5307,9 @@
(failure (..wrong_syntax_error (name_of ..template:)))))
(macro: .public (as_is tokens compiler)
- {#.doc (example "Given a (potentially empty) list of codes, just returns them immediately, without any work done."
- "This may seen useless, but it has its utility when dealing with controlled-macro-expansion macros."
- (with_expansions [<operands> (as_is 1
- 2
- 3
- 4)]
- (+ <operands>)))}
(#Right [compiler tokens]))
(macro: .public (char tokens compiler)
- {#.doc (example "If given a 1-character text literal, yields the char-code of the sole character."
- (: Nat
- (char "A"))
- "=>"
- 65)}
(case tokens
(^multi (^ (list [_ (#Text input)]))
(|> input "lux text size" ("lux i64 =" 1)))
@@ -5989,12 +5370,6 @@
(target_pick target options' default)))))
(macro: .public (for tokens)
- {#.doc (example "Selects the appropriate code for a given target-platform when compiling Lux to it."
- (def: js "JavaScript")
- (for {"JVM" (do jvm stuff)
- ..js (do js stuff)}
- (do default stuff))
- "Look-up the available targets in library/lux/target.")}
(do meta_monad
[target ..target]
(case tokens
@@ -6007,14 +5382,6 @@
_
(failure (..wrong_syntax_error (name_of ..for))))))
-(template [<name>]
- [(def: (<name> [left right])
- (All [left right] (-> [left right] <name>))
- <name>)]
-
- [left]
- [right])
-
(def: (embedded_expansions code)
(-> Code (Meta [(List [Code Code]) Code]))
(case code
@@ -6027,8 +5394,8 @@
[[ann (<tag> parts)]
(do meta_monad
[=parts (monad\each meta_monad embedded_expansions parts)]
- (in [(list\mix list\composite (list) (list\each left =parts))
- [ann (<tag> (list\each right =parts))]]))])
+ (in [(list\mix list\composite (list) (list\each product\left =parts))
+ [ann (<tag> (list\each product\right =parts))]]))])
([#Form] [#Tuple])
[ann (#Record kvs)]
@@ -6042,17 +5409,13 @@
[val_labels val_labelled] =val]]
(in [(list\composite key_labels val_labels) [key_labelled val_labelled]])))
kvs)]
- (in [(list\mix list\composite (list) (list\each left =kvs))
- [ann (#Record (list\each right =kvs))]]))
+ (in [(list\mix list\composite (list) (list\each product\left =kvs))
+ [ann (#Record (list\each product\right =kvs))]]))
_
(in_meta [(list) code])))
(macro: .public (`` tokens)
- {#.doc (example "Delimits a controlled (spliced) macro-expansion."
- "Uses a (~~) special form to specify where to expand."
- (`` (some expression
- (~~ (some macro which may yield 0 or more results)))))}
(case tokens
(^ (list raw))
(do meta_monad
@@ -6146,14 +5509,6 @@
)))
(macro: .public (^code tokens)
- {#.doc (example "Generates pattern-matching code for Code values in a way that looks like code-templating."
- (: (Maybe Nat)
- (case (` (#0 123 +456.789))
- (^code (#0 (~ [_ (#.Nat number)]) +456.789))
- (#.Some number)
-
- _
- #.None)))}
(case tokens
(^ (list& [_meta (#Form (list template))] body branches))
(do meta_monad
@@ -6169,19 +5524,14 @@
(failure (..wrong_syntax_error (name_of ..^code)))))
(def: .public false
- {#.doc "The boolean FALSE value."}
Bit
#0)
(def: .public true
- {#.doc "The boolean TRUE value."}
Bit
#1)
(macro: .public (:let tokens)
- {#.doc (example "Local bindings for types."
- (:let [side (Either Int Frac)]
- (List [side side])))}
(case tokens
(^ (list [_ (#Tuple bindings)] bodyT))
(if (multiple? 2 (list\size bindings))
@@ -6197,17 +5547,6 @@
(..failure (..wrong_syntax_error (name_of ..:let)))))
(macro: .public (try tokens)
- {#.doc (example (: Foo
- (case (: (Either Text Bar)
- (try (: Bar
- (risky computation which may panic))))
- (#.Right success)
- (: Foo
- (do something after success))
-
- (#.Left error)
- (: Foo
- (recover from error)))))}
(case tokens
(^ (list expression))
(do meta_monad