From 9ccc8ea44ebe4f9a3d40c8e94b55f77c0d815099 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 20 Aug 2018 23:23:02 -0400 Subject: Some refactoring. --- stdlib/source/lux.lux | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index bf92eb4db..d64b83bd3 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -19,7 +19,7 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type does not matter. + [dummy-cursor (5 "The type of things whose type is irrelevant. It can be used to write functions or data-structures that can take, or return, anything.")]] (0)))))]) @@ -35,7 +35,7 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type is unknown or undefined. + [dummy-cursor (5 "The type of things whose type is undefined. Useful for expressions that cause errors or other \"extraordinary\" conditions.")]] (0)))))]) -- cgit v1.2.3 From f74614ad4173cc7df1dd22944fddebf5a03bab27 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 21 Aug 2018 22:48:17 -0400 Subject: - Added single-line comment parsing. - Added tag parsing. - Added tracking. --- stdlib/source/lux.lux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index d64b83bd3..1114b069c 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5945,7 +5945,7 @@ (^ (list (~+ (list/map (|>> [""] identifier$) args)))) (#.Right [(~ g!compiler) (list (~+ (list/map (function (_ template) - (` (` (~ (replace-syntax rep-env template))))) + (` (`' (~ (replace-syntax rep-env template))))) input-templates)))]) (~ g!_) -- cgit v1.2.3 From b60d60ef6c0c70821991991fe716935e73038832 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 22 Aug 2018 19:42:17 -0400 Subject: No more multi-line text. --- stdlib/source/lux.lux | 769 +++++++++++++++++++++++++------------------------- 1 file changed, 383 insertions(+), 386 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 1114b069c..1b64aa22b 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -19,9 +19,9 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type is irrelevant. - - It can be used to write functions or data-structures that can take, or return, anything.")]] + [dummy-cursor (5 ("lux text concat" + "The type of things whose type is irrelevant.\n\n" + "It can be used to write functions or data-structures that can take, or return, anything."))]] (0)))))]) ## (type: Nothing @@ -35,9 +35,9 @@ (1 [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "The type of things whose type is undefined. - - Useful for expressions that cause errors or other \"extraordinary\" conditions.")]] + [dummy-cursor (5 ("lux text concat" + "The type of things whose type is undefined.\n\n" + "Useful for expressions that cause errors or other \"extraordinary\" conditions."))]] (0)))))]) ## (type: (List a) @@ -98,9 +98,9 @@ (#Cons [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "Natural numbers (unsigned integers). - - They start at zero (0) and extend in the positive direction.")]] + [dummy-cursor (5 ("lux text concat" + "Natural numbers (unsigned integers).\n\n" + "They start at zero (0) and extend in the positive direction."))]] #Nil))))]) ("lux def" Int @@ -124,9 +124,9 @@ (#Cons [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "Fractional numbers that live in the interval [0,1). - - Useful for probability, and other domains that work within that interval.")]] + [dummy-cursor (5 ("lux text concat" + "Fractional numbers that live in the interval [0,1).\n\n" + "Useful for probability, and other domains that work within that interval."))]] #Nil))))]) ("lux def" Frac @@ -162,9 +162,9 @@ (#Cons [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 "A name. - - It is used as part of Lux syntax to represent identifiers and tags.")]] + [dummy-cursor (5 ("lux text concat" + "A name.\n\n" + "It is used as part of Lux syntax to represent identifiers and tags."))]] #Nil))))]) ## (type: (Maybe a) @@ -747,11 +747,11 @@ (#Cons (text$ "host") #Nil)))))))))))))] (#Cons [(tag$ ["lux" "doc"]) - (text$ "Represents the state of the Lux compiler during a run. - - It is provided to macros during their invocation, so they can access compiler data. - - Caveat emptor: Avoid fiddling with it, unless you know what you're doing.")] + (text$ ("lux text concat" + "Represents the state of the Lux compiler during a run.\n\n" + ("lux text concat" + "It is provided to macros during their invocation, so they can access compiler data.\n\n" + "Caveat emptor: Avoid fiddling with it, unless you know what you're doing.")))] default-def-meta-exported)))) ## (type: (Meta a) @@ -763,9 +763,9 @@ (#Apply (#Product Lux (#Parameter 1)) (#Apply Text Either))))) (record$ (#Cons [(tag$ ["lux" "doc"]) - (text$ "Computations that can have access to the state of the compiler. - - These computations may fail, or modify the state of the compiler.")] + (text$ ("lux text concat" + "Computations that can have access to the state of the compiler.\n\n" + "These computations may fail, or modify the state of the compiler."))] (#Cons [(tag$ ["lux" "type-args"]) (tuple$ (#Cons (text$ "a") #Nil))] default-def-meta-exported)))) @@ -1027,9 +1027,11 @@ (macro:' #export (comment tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Throws away any code given to it. - ## Great for commenting-out code, while retaining syntax high-lighting and formatting in your text editor. - (comment +1 +2 +3 +4)")] + (text$ ("lux text concat" + "## Throws away any code given to it.\n\n" + ("lux text concat" + "## Great for commenting-out code, while retaining syntax high-lighting and formatting in your text editor.\n\n" + "(comment +1 +2 +3 +4)")))] #Nil) (return #Nil)) @@ -1219,14 +1221,13 @@ (macro:' #export (All tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Universal quantification. - (All [a] - (-> a a)) - - ## A name can be provided, to specify a recursive type. - (All List [a] - (| Any - [a (List a)]))")] + (text$ ("lux text concat" + "## Universal quantification.\n\n" + ("lux text concat" + "(All [a] (-> a a))\n\n" + ("lux text concat" + "## A name can be provided, to specify a recursive type.\n\n" + "(All List [a] (| Any [a (List a)]))"))))] #Nil) (let'' [self-name tokens] ({(#Cons [_ (#Identifier "" self-name)] tokens) [self-name tokens] @@ -1264,16 +1265,13 @@ (macro:' #export (Ex tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Existential quantification. - (Ex [a] - [(Codec Text a) - a]) - - ## A name can be provided, to specify a recursive type. - (Ex Self [a] - [(Codec Text a) - a - (List (Self a))])")] + (text$ ("lux text concat" + "## Existential quantification.\n\n" + ("lux text concat" + "(Ex [a] [(Codec Text a) a])\n\n" + ("lux text concat" + "## A name can be provided, to specify a recursive type.\n\n" + "(Ex Self [a] [(Codec Text a) a (List (Self a))])"))))] #Nil) (let'' [self-name tokens] ({(#Cons [_ (#Identifier "" self-name)] tokens) [self-name tokens] @@ -1319,10 +1317,11 @@ (macro:' #export (-> tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Function types: - (-> Int Int Int) - - ## This is the type of a function that takes 2 Ints and returns an Int.")] + (text$ ("lux text concat" + "## Function types:\n\n" + ("lux text concat" + "(-> Int Int Int)\n\n" + "## This is the type of a function that takes 2 Ints and returns an Int.")))] #Nil) ({(#Cons output inputs) (return (#Cons (list/fold ("lux check" (#Function Code (#Function Code Code)) @@ -1337,8 +1336,9 @@ (macro:' #export (list xs) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## List-construction macro. - (list +1 +2 +3)")] + (text$ ("lux text concat" + "## List-construction macro.\n\n" + "(list +1 +2 +3)"))] #Nil) (return (#Cons (list/fold (function'' [head tail] (form$ (#Cons (tag$ ["lux" "Cons"]) @@ -1350,9 +1350,11 @@ (macro:' #export (list& xs) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## List-construction macro, with the last element being a tail-list. - ## In other words, this macro prepends elements to another list. - (list& +1 +2 +3 (list +4 +5 +6))")] + (text$ ("lux text concat" + "## List-construction macro, with the last element being a tail-list.\n\n" + ("lux text concat" + "## In other words, this macro prepends elements to another list.\n\n" + "(list& +1 +2 +3 (list +4 +5 +6))")))] #Nil) ({(#Cons last init) (return (list (list/fold (function'' [head tail] @@ -1367,11 +1369,13 @@ (macro:' #export (& tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Tuple types: - (& Text Int Bit) - - ## Any. - (&)")] + (text$ ("lux text concat" + "## Tuple types:\n\n" + ("lux text concat" + "(& Text Int Bit)\n\n" + ("lux text concat" + "## Any.\n\n" + "(&)"))))] #Nil) ({#Nil (return (list (identifier$ ["lux" "Any"]))) @@ -1384,11 +1388,13 @@ (macro:' #export (| tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Variant types: - (| Text Int Bit) - - ## Nothing. - (|)")] + (text$ ("lux text concat" + "## Variant types:\n\n" + ("lux text concat" + "(| Text Int Bit)\n\n" + ("lux text concat" + "## Nothing.\n\n" + "(|)"))))] #Nil) ({#Nil (return (list (identifier$ ["lux" "Nothing"]))) @@ -1563,11 +1569,13 @@ (macro:' #export (_$ tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Left-association for the application of binary functions over variadic arguments. - (_$ text/compose \"Hello, \" name \".\\nHow are you?\") - - ## => - (text/compose (text/compose \"Hello, \" name) \".\\nHow are you?\")")] + (text$ ("lux text concat" + "## Left-association for the application of binary functions over variadic arguments.\n\n" + ("lux text concat" + "(_$ text/compose \"Hello, \" name \".\\nHow are you?\")\n\n" + ("lux text concat" + "## =>\n\n" + "(text/compose (text/compose \"Hello, \" name) \".\\nHow are you?\")"))))] #Nil) ({(#Cons op tokens') ({(#Cons first nexts) @@ -1583,11 +1591,13 @@ (macro:' #export ($_ tokens) (#Cons [(tag$ ["lux" "doc"]) - (text$ "## Right-association for the application of binary functions over variadic arguments. - ($_ text/compose \"Hello, \" name \".\\nHow are you?\") - - ## => - (text/compose \"Hello, \" (text/compose name \".\\nHow are you?\"))")] + (text$ ("lux text concat" + "## Right-association for the application of binary functions over variadic arguments.\n\n" + ("lux text concat" + "($_ text/compose \"Hello, \" name \".\\nHow are you?\")\n\n" + ("lux text concat" + "## =>\n\n" + "(text/compose \"Hello, \" (text/compose name \".\\nHow are you?\"))"))))] #Nil) ({(#Cons op tokens') ({(#Cons last prevs) @@ -1715,13 +1725,10 @@ (macro:' #export (if tokens) (list [(tag$ ["lux" "doc"]) - (text$ "Picks which expression to evaluate based on a bit test value. - - (if #1 - \"Oh, yeah!\" - \"Aw hell naw!\") - - => \"Oh, yeah!\"")]) + (text$ ($_ "lux text concat" + "Picks which expression to evaluate based on a bit test value." "\n\n" + "(if #1 \"Oh, yeah!\" \"Aw hell naw!\")" "\n\n" + "=> \"Oh, yeah!\""))]) ({(#Cons test (#Cons then (#Cons else #Nil))) (return (list (form$ (list (record$ (list [(bit$ #1) then] [(bit$ #0) else])) @@ -1759,9 +1766,9 @@ (def:''' #export (log! message) (list [(tag$ ["lux" "doc"]) - (text$ "Logs message to standard output. - - Useful for debugging.")]) + (text$ ($_ "lux text concat" + "Logs message to standard output." "\n\n" + "Useful for debugging."))]) (-> Text Any) ("lux io log" message)) @@ -1966,10 +1973,10 @@ (macro:' #export (primitive tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Macro to treat define new primitive types. - (primitive \"java.lang.Object\") - - (primitive \"java.util.List\" [(primitive \"java.lang.Long\")])")]) + (text$ ($_ "lux text concat" + "## Macro to treat define new primitive types." "\n\n" + "(primitive \"java.lang.Object\")" "\n\n" + "(primitive \"java.util.List\" [(primitive \"java.lang.Long\")])"))]) ({(#Cons [_ (#Text class-name)] #Nil) (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (tag$ ["lux" "Nil"]))))) @@ -1997,11 +2004,10 @@ (macro:' #export (` tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Hygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms. - ## 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. - (` (def: (~ name) - (function ((~' _) (~+ args)) - (~ body))))")]) + (text$ ($_ "lux text concat" + "## Hygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." "\n\n" + "## 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." "\n\n" + "(` (def: (~ name) (function ((~' _) (~+ args)) (~ body))))"))]) ({(#Cons template #Nil) (do Monad [current-module current-module-name @@ -2016,10 +2022,9 @@ (macro:' #export (`' tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms. - (`' (def: (~ name) - (function (_ (~+ args)) - (~ body))))")]) + (text$ ($_ "lux text concat" + "## Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." "\n\n" + "(`' (def: (~ name) (function (_ (~+ args)) (~ body))))"))]) ({(#Cons template #Nil) (do Monad [=template (untemplate #1 "" template)] @@ -2031,8 +2036,9 @@ (macro:' #export (' tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Quotation as a macro. - (' \"YOLO\")")]) + (text$ ($_ "lux text concat" + "## Quotation as a macro." "\n\n" + "(' \"YOLO\")"))]) ({(#Cons template #Nil) (do Monad [=template (untemplate #0 "" template)] @@ -2044,13 +2050,11 @@ (macro:' #export (|> tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Piping macro. - (|> elems (list/map int/encode) (interpose \" \") (fold text/compose \"\")) - - ## => - (fold text/compose \"\" - (interpose \" \" - (list/map int/encode elems)))")]) + (text$ ($_ "lux text concat" + "## Piping macro." "\n\n" + "(|> elems (list/map int/encode) (interpose \" \") (fold text/compose \"\"))" "\n\n" + "## =>" "\n\n" + "(fold text/compose \"\" (interpose \" \" (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) (function' [app acc] @@ -2072,13 +2076,11 @@ (macro:' #export (<| tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Reverse piping macro. - (<| (fold text/compose \"\") (interpose \" \") (list/map int/encode) elems) - - ## => - (fold text/compose \"\" - (interpose \" \" - (list/map int/encode elems)))")]) + (text$ ($_ "lux text concat" + "## Reverse piping macro." "\n\n" + "(<| (fold text/compose \"\") (interpose \" \") (list/map int/encode) elems)" "\n\n" + "## =>" "\n\n" + "(fold text/compose \"\" (interpose \" \" (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) (function' [app acc] @@ -2249,14 +2251,12 @@ (macro:' #export (do-template tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## By specifying a pattern (with holes), and the input data to fill those holes, repeats the pattern as many times as necessary. - (do-template [ ] - [(def: #export - (-> Int Int) - (i/+ ))] - - [inc +1] - [dec -1])")]) + (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." "\n\n" + "(do-template [ ]" "\n" + " " "[(def: #export (-> Int Int) (i/+ ))]" "\n\n" + " " "[inc +1]" "\n" + " " "[dec -1]"))]) ({(#Cons [[_ (#Tuple bindings)] (#Cons [[_ (#Tuple templates)] data])]) ({[(#Some bindings') (#Some data')] (let' [apply ("lux check" (-> RepEnv ($' List Code)) @@ -2602,11 +2602,10 @@ (def:''' #export (not x) (list [(tag$ ["lux" "doc"]) - (text$ "## Bit negation. - - (not #1) => #0 - - (not #0) => #1")]) + (text$ ($_ "lux text concat" + "## Bit negation." "\n\n" + "(not #1) => #0" "\n\n" + "(not #0) => #1"))]) (-> Bit Bit) (if x #0 #1)) @@ -2815,8 +2814,9 @@ (macro:' #export (type tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Takes a type expression and returns it's representation as data-structure. - (type (All [a] (Maybe (List a))))")]) + (text$ ($_ "lux text concat" + "## Takes a type expression and returns it's representation as data-structure." "\n\n" + "(type (All [a] (Maybe (List a))))"))]) ({(#Cons type #Nil) (do Monad [type+ (macro-expand-all type)] @@ -2833,8 +2833,9 @@ (macro:' #export (: tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## The type-annotation macro. - (: (List Int) (list +1 +2 +3))")]) + (text$ ($_ "lux text concat" + "## The type-annotation macro." "\n\n" + "(: (List Int) (list +1 +2 +3))"))]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux check" (type (~ type)) (~ value))))) @@ -2844,8 +2845,9 @@ (macro:' #export (:coerce tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## The type-coercion macro. - (:coerce Dinosaur (list +1 +2 +3))")]) + (text$ ($_ "lux text concat" + "## The type-coercion macro." "\n\n" + "(:coerce Dinosaur (list +1 +2 +3))"))]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux coerce" (type (~ type)) (~ value))))) @@ -2941,10 +2943,10 @@ (macro:' #export (Rec tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Parameter-less recursive types. - ## A name has to be given to the whole type, to use it within its body. - (Rec Self - [Int (List Self)])")]) + (text$ ($_ "lux text concat" + "## Parameter-less recursive types." "\n\n" + "## A name has to be given to the whole type, to use it within its body." "\n\n" + "(Rec Self [Int (List Self)])"))]) ({(#Cons [_ (#Identifier "" name)] (#Cons body #Nil)) (let' [body' (replace-syntax (list [name (` (#.Apply (~ (make-parameter 1)) (~ (make-parameter 0))))]) (update-parameters body))] @@ -2956,12 +2958,13 @@ (macro:' #export (exec tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Sequential execution of expressions (great for side-effects). - (exec - (log! \"#1\") - (log! \"#2\") - (log! \"#3\") - \"YOLO\")")]) + (text$ ($_ "lux text concat" + "## Sequential execution of expressions (great for side-effects)." "\n\n" + "(exec" "\n" + " " "(log! \"#1\")" "\n" + " " "(log! \"#2\")" "\n" + " " "(log! \"#3\")" "\n" + "\"YOLO\")"))]) ({(#Cons value actions) (let' [dummy (identifier$ ["" ""])] (return (list (list/fold ("lux check" (-> Code Code Code) @@ -3113,14 +3116,14 @@ (macro:' #export (case tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## The pattern-matching macro. - ## Allows the usage of macros within the patterns to provide custom syntax. - (case (: (List Int) (list +1 +2 +3)) - (#Cons x (#Cons y (#Cons z #Nil))) - (#Some ($_ i/* x y z)) - - _ - #None)")]) + (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" + " " "(#Cons x (#Cons y (#Cons z #Nil)))" "\n" + " " "(#Some ($_ i/* x y z))" "\n\n" + " " "_" "\n" + " " "#None)"))]) ({(#Cons value branches) (do Monad [expansion (expander branches)] @@ -3132,14 +3135,15 @@ (macro:' #export (^ tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Macro-expanding patterns. - ## It's a special macro meant to be used with 'case'. - (case (: (List Int) (list +1 +2 +3)) - (^ (list x y z)) - (#Some ($_ i/* x y z)) - - _ - #None)")]) + (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 ($_ i/* x y z))" + "\n\n" + " _" "\n" + " #None)"))]) (case tokens (#Cons [_ (#Form (#Cons pattern #Nil))] (#Cons body branches)) (do Monad @@ -3156,25 +3160,19 @@ (macro:' #export (^or tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Or-patterns. - ## It's a special macro meant to be used with 'case'. - (type: Weekday - #Monday - #Tuesday - #Wednesday - #Thursday - #Friday - #Saturday - #Sunday) - - (def: (weekend? day) - (-> Weekday Bit) - (case day - (^or #Saturday #Sunday) - #1 - - _ - #0))")]) + (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)" + "\n\n" + "(def: (weekend? day)" "\n" + " (-> Weekday Bit)" "\n" + " (case day" "\n" + " (^or #Saturday #Sunday)" "\n" + " #1" + "\n\n" + " _" "\n" + " #0))"))]) (case tokens (^ (list& [_ (#Form patterns)] body branches)) (case patterns @@ -3200,11 +3198,12 @@ (macro:' #export (let tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Creates local bindings. - ## Can (optionally) use pattern-matching macros when binding. - (let [x (foo bar) - y (baz quux)] - (op x y))")]) + (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))"))]) (case tokens (^ (list [_ (#Tuple bindings)] body)) (if (multiple? 2 (list/size bindings)) @@ -3225,13 +3224,14 @@ (macro:' #export (function tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Syntax for creating functions. - ## Allows for giving the function itself a name, for the sake of recursion. - (: (All [a b] (-> a b a)) - (function (_ x y) x)) - - (: (All [a b] (-> a b a)) - (function (const x y) x))")]) + (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))" + "\n\n" + "(: (All [a b] (-> a b a))" "\n" + " (function (const x y) x))"))]) (case (: (Maybe [Text Code (List Code) Code]) (case tokens (^ (list [_ (#Form (list& [_ (#Identifier ["" name])] head tail))] body)) @@ -3343,15 +3343,16 @@ (macro:' #export (def: tokens) (list [(tag$ ["lux" "doc"]) - (text$ "## Defines global constants/functions. - (def: (rejoin-pair pair) - (-> [Code Code] (List Code)) - (let [[left right] pair] - (list left right))) - - (def: branching-exponent - Int - +5)")]) + (text$ ($_ "lux text concat" + "## Defines global constants/functions." "\n" + "(def: (rejoin-pair pair)" "\n" + " (-> [Code Code] (List Code))" "\n" + " (let [[left right] pair]" "\n" + " (list left right)))" + "\n\n" + "(def: branching-exponent" "\n" + " Int" "\n" + " +5)"))]) (let [[export? tokens'] (export^ tokens) parts (: (Maybe [Code (List Code) (Maybe Code) Code (List [Code Code])]) (case tokens' @@ -3427,17 +3428,17 @@ (macro:' #export (macro: tokens) (list [(tag$ ["lux" "doc"]) - (text$ "Macro-definition macro. - - (macro: #export (name-of tokens) - (case tokens - (^template [] - (^ (list [_ ( [prefix name])])) - (return (list (` [(~ (text$ prefix)) (~ (text$ name))])))) - ([#Identifier] [#Tag]) - - _ - (fail \"Wrong syntax for name-of\")))")]) + (text$ ($_ "lux text concat" + "## Macro-definition macro." "\n" + "(macro: #export (name-of tokens)" "\n" + " (case tokens" "\n" + " (^template []" "\n" + " (^ (list [_ ( [prefix name])]))" "\n" + " (return (list (` [(~ (text$ prefix)) (~ (text$ name))]))))" "\n" + " ([#Identifier] [#Tag])" + "\n\n" + " _" "\n" + " (fail \"Wrong syntax for name-of\")))"))]) (let [[exported? tokens] (export^ tokens) name+args+meta+body?? (: (Maybe [Name (List Code) Code Code]) (case tokens @@ -3474,18 +3475,19 @@ (fail "Wrong syntax for macro:")))) (macro: #export (signature: tokens) - {#.doc "## Definition of signatures ala ML. - (signature: #export (Ord a) - (: (Equivalence a) - eq) - (: (-> a a Bit) - <) - (: (-> a a Bit) - <=) - (: (-> a a Bit) - >) - (: (-> a a Bit) - >=))"} + {#.doc (text$ ($_ "lux text concat" + "## Definition of signatures ala ML." "\n" + "(signature: #export (Ord a)" "\n" + " (: (Equivalence a)" "\n" + " eq)" "\n" + " (: (-> a a Bit)" "\n" + " <)" "\n" + " (: (-> a a Bit)" "\n" + " <=)" "\n" + " (: (-> a a Bit)" "\n" + " >)" "\n" + " (: (-> a a Bit)" "\n" + " >=))"))} (let [[exported? tokens'] (export^ tokens) ?parts (: (Maybe [Name (List Code) Code (List Code)]) (case tokens' @@ -3600,17 +3602,20 @@ ("lux text clip" text from to)) (def: #export (error! message) - {#.doc "## Causes an error, with the given error message. - (error! \"OH NO!\")"} + {#.doc (text$ ($_ "lux text concat" + "## Causes an error, with the given error message." "\n" + "(error! \"OH NO!\")"))} (-> Text Nothing) ("lux io error" message)) (macro: (default tokens state) - {#.doc "## Allows you to provide a default value that will be used - ## if a (Maybe x) value turns out to be #.None. - (default +20 (#.Some +10)) => +10 - - (default +20 #.None) => +20"} + {#.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." + "\n\n" + "(default +20 (#.Some +10)) ## => +10" + "\n\n" + "(default +20 #.None) ## => +20"))} (case tokens (^ (list else maybe)) (let [g!temp (: Code [dummy-cursor (#Identifier ["" ""])]) @@ -3883,19 +3888,20 @@ (|> parts list/reverse (list/fold text/compose ""))) (macro: #export (structure: tokens) - {#.doc "## Definition of structures ala ML. - (structure: #export Ord (Ord Int) - (def: eq Equivalence) - (def: (< test subject) - (lux.< test subject)) - (def: (<= test subject) - (or (lux.< test subject) - (lux.= test subject))) - (def: (lux.> test subject) - (lux.> test subject)) - (def: (lux.>= test subject) - (or (lux.> test subject) - (lux.= test subject))))"} + {#.doc (text$ ($_ "lux text concat" + "## Definition of structures ala ML." "\n" + "(structure: #export Ord (Ord Int)" "\n" + " (def: eq Equivalence)" "\n" + " (def: (< test subject)" "\n" + " (lux.i/< test subject))" "\n" + " (def: (<= test subject)" "\n" + " (or (lux.i/< test subject)" "\n" + " (lux.i/= test subject)))" "\n" + " (def: (> test subject)" "\n" + " (lux.i/> test subject))" "\n" + " (def: (>= test subject)" "\n" + " (or (lux.i/> test subject)" "\n" + " (lux.i/= test subject))))"))} (let [[exported? tokens'] (export^ tokens) ?parts (: (Maybe [Code (List Code) Code Code (List Code)]) (case tokens' @@ -3961,17 +3967,14 @@ (fail "Wrong syntax for structure:")))) (def: #export (id x) - {#.doc "Identity function. - - Does nothing to it's argument and just returns it."} + {#.doc "Identity function. Does nothing to it's argument and just returns it."} (All [a] (-> a a)) x) (macro: #export (type: tokens) - {#.doc "## The type-definition macro. - (type: (List a) - #Nil - (#Cons a (List a)))"} + {#.doc (text$ ($_ "lux text concat" + "## The type-definition macro." "\n" + "(type: (List a) #Nil (#Cons a (List a)))"))} (let [[exported? tokens'] (export^ tokens) [rec? tokens'] (case tokens' (#Cons [_ (#Tag [_ "rec"])] tokens') @@ -4202,7 +4205,7 @@ 0 prefix _ ($_ text/compose prefix "/" clean))] (return output)) - (fail ($_ text/compose + (fail ($_ "lux text concat" "Cannot climb the module hierarchy...\n" "Importing module: " module "\n" " Relative Root: " relative-root "\n")))))) @@ -4488,11 +4491,12 @@ )) (macro: #export (^open tokens) - {#.doc "## Same as the \"open\" macro, but meant to be used as a pattern-matching macro for generating local bindings. - ## Takes an \"alias\" text for the generated local bindings. - (def: #export (range (^open \".\") from to) - (All [a] (-> (Enum a) a a (List a))) - (range' <= succ from to))"} + {#.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: #export (range (^open \".\") from to)" "\n" + " (All [a] (-> (Enum a) a a (List a)))" "\n" + " (range' <= succ from to))"))} (case tokens (^ (list& [_ (#Form (list [_ (#Text alias)]))] body branches)) (do Monad @@ -4538,11 +4542,13 @@ (fail "Wrong syntax for ^open"))) (macro: #export (cond tokens) - {#.doc "## Branching structures with multiple test conditions. - (cond (n/even? num) \"even\" - (n/odd? num) \"odd\" - ## else-branch - \"???\")"} + {#.doc (text$ ($_ "lux text concat" + "## Branching structures with multiple test conditions." "\n" + "(cond (n/even? num) \"even\"" "\n" + " (n/odd? num) \"odd\"" + "\n\n" + " ## else-branch" "\n" + " \"???\")"))} (if (n/= 0 (n/% 2 (list/size tokens))) (fail "cond requires an uneven number of arguments.") (case (list/reverse tokens) @@ -4571,16 +4577,16 @@ (enumerate' 0 xs)) (macro: #export (get@ tokens) - {#.doc "## Accesses the value of a record at a given tag. - (get@ #field my-record) - - ## Can also work with multiple levels of nesting: - (get@ [#foo #bar #baz] my-record) - - ## And, if only the slot/path is given, generates an - ## accessor function: - (let [getter (get@ [#foo #bar #baz])] - (getter my-record))"} + {#.doc (text$ ($_ "lux text concat" + "## Accesses the value of a record at a given tag." "\n" + "(get@ #field my-record)" + "\n\n" + "## Can also work with multiple levels of nesting:" "\n" + "(get@ [#foo #bar #baz] my-record)" + "\n\n" + "## And, if only the slot/path is given, generates an accessor function:" "\n" + "(let [getter (get@ [#foo #bar #baz])]" "\n" + " (getter my-record))"))} (case tokens (^ (list [_ (#Tag slot')] record)) (do Monad @@ -4639,14 +4645,17 @@ [(~ cursor-code) (#.Record #Nil)]))))))) (macro: #export (open: tokens) - {#.doc "## Opens a structure and generates a definition for each of its members (including nested members). - ## For example: - (open: \"i:.\" Number) - ## Will generate: - (def: i:+ (:: Number +)) - (def: i:- (:: Number -)) - (def: i:* (:: Number *)) - ..."} + {#.doc (text$ ($_ "lux text concat" + "## Opens a structure and generates a definition for each of its members (including nested members)." + "\n\n" + "## For example:" "\n" + "(open: \"i:.\" Number)" + "\n\n" + "## Will generate:" "\n" + "(def: i:+ (:: Number +))" "\n" + "(def: i:- (:: Number -))" "\n" + "(def: i:* (:: Number *))" "\n" + "..."))} (case tokens (^ (list [_ (#Text alias)] struct)) (case struct @@ -4678,26 +4687,22 @@ (fail "Wrong syntax for open:"))) (macro: #export (|>> tokens) - {#.doc "## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it. - (|>> (list/map int/encode) (interpose \" \") (fold text/compose \"\")) - ## => - (function (_ ) - (fold text/compose \"\" - (interpose \" \" - (list/map int/encode ))))"} + {#.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/map int/encode) (interpose \" \") (fold text/compose \"\"))" "\n" + "## =>" "\n" + "(function (_ ) (fold text/compose \"\" (interpose \" \" (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") g!arg (gensym "arg")] (return (list (` (function ((~ g!_) (~ g!arg)) (|> (~ g!arg) (~+ tokens)))))))) (macro: #export (<<| tokens) - {#.doc "## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it. - (<<| (fold text/compose \"\") (interpose \" \") (list/map int/encode)) - ## => - (function (_ ) - (fold text/compose \"\" - (interpose \" \" - (list/map int/encode ))))"} + {#.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" + "(<<| (fold text/compose \"\") (interpose \" \") (list/map int/encode))" "\n" + "## =>" "\n" + "(function (_ ) (fold text/compose \"\" (interpose \" \" (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") g!arg (gensym "arg")] @@ -4821,26 +4826,23 @@ (~+ openings))))) (macro: #export (module: tokens) - {#.doc "Module-definition macro. - - Can take optional annotations and allows the specification of modules to import. - - ## Examples - (.module: {#.doc \"Some documentation...\"} - [lux #* - [control - [\"M\" monad #*]] - [data - maybe - [\".\" name (\"name/.\" Codec)] - [\".\" text (\"text/.\" Monoid)] - [collection - [list (\"list/.\" Monad)]]] - meta - [macro - code]] - [// - [type (\".\" Equivalence)]])"} + {#.doc (text$ ($_ "lux text concat" + "## Module-definition macro." + "\n\n" + "## Can take optional annotations and allows the specification of modules to import." + "\n\n" + "## Example" "\n" + "(.module: {#.doc \"Some documentation...\"}" "\n" + " [lux #*" "\n" + " [control" "\n" + " [\"M\" monad #*]]" "\n" + " [data" "\n" + " maybe" "\n" + " [\".\" name (\"name/.\" Codec)]]" "\n" + " [macro" "\n" + " code]]" "\n" + " [//" "\n" + " [type (\".\" Equivalence)]])"))} (do Monad [#let [[_meta _imports] (: [(List [Code Code]) (List Code)] (case tokens @@ -4866,11 +4868,12 @@ (wrap (#Cons =module =refers)))) (macro: #export (:: tokens) - {#.doc "## Allows accessing the value of a structure's member. - (:: Codec encode) - - ## Also allows using that value as a function. - (:: Codec encode +123)"} + {#.doc (text$ ($_ "lux text concat" + "## Allows accessing the value of a structure's member." "\n" + "(:: Codec encode)" + "\n\n" + "## Also allows using that value as a function." "\n" + "(:: Codec encode +123)"))} (case tokens (^ (list struct [_ (#Identifier member)])) (return (list (` (let [(^open ".") (~ struct)] (~ (identifier$ member)))))) @@ -4882,19 +4885,16 @@ (fail "Wrong syntax for ::"))) (macro: #export (set@ tokens) - {#.doc "## Sets the value of a record at a given tag. - (set@ #name \"Lux\" lang) - - ## Can also work with multiple levels of nesting: - (set@ [#foo #bar #baz] value my-record) - - ## And, if only the slot/path and (optionally) the value are given, generates a - ## mutator function: - (let [setter (set@ [#foo #bar #baz] value)] - (setter my-record)) - - (let [setter (set@ [#foo #bar #baz])] - (setter value my-record))"} + {#.doc (text$ ($_ "lux text concat" + "## Sets the value of a record at a given tag." "\n" + "(set@ #name \"Lux\" lang)" + "\n\n" + "## Can also work with multiple levels of nesting:" "\n" + "(set@ [#foo #bar #baz] value my-record)" + "\n\n" + "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" "\n" + "(let [setter (set@ [#foo #bar #baz] value)] (setter my-record))" "\n" + "(let [setter (set@ [#foo #bar #baz])] (setter value my-record))"))} (case tokens (^ (list [_ (#Tag slot')] value record)) (do Monad @@ -4972,19 +4972,16 @@ (fail "Wrong syntax for set@"))) (macro: #export (update@ tokens) - {#.doc "## Modifies the value of a record at a given tag, based on some function. - (update@ #age inc person) - - ## Can also work with multiple levels of nesting: - (update@ [#foo #bar #baz] func my-record) - - ## And, if only the slot/path and (optionally) the value are given, generates a - ## mutator function: - (let [updater (update@ [#foo #bar #baz] func)] - (updater my-record)) - - (let [updater (update@ [#foo #bar #baz])] - (updater func my-record))"} + {#.doc (text$ ($_ "lux text concat" + "## Modifies the value of a record at a given tag, based on some function." "\n" + "(update@ #age inc person)" + "\n\n" + "## Can also work with multiple levels of nesting:" "\n" + "(update@ [#foo #bar #baz] func my-record)" + "\n\n" + "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" "\n" + "(let [updater (update@ [#foo #bar #baz] func)] (updater my-record))" "\n" + "(let [updater (update@ [#foo #bar #baz])] (updater func my-record))"))} (case tokens (^ (list [_ (#Tag slot')] fun record)) (do Monad @@ -5048,41 +5045,40 @@ (fail "Wrong syntax for update@"))) (macro: #export (^template tokens) - {#.doc "## It's similar to do-template, but meant to be used during pattern-matching. - (def: (beta-reduce env type) - (-> (List Type) Type Type) - (case type - (#.Primitive name params) - (#.Primitive name (list/map (beta-reduce env) params)) - - (^template [] - ( left right) - ( (beta-reduce env left) (beta-reduce env right))) - ([#.Sum] [#.Product]) - - (^template [] - ( left right) - ( (beta-reduce env left) (beta-reduce env right))) - ([#.Function] - [#.Apply]) - - (^template [] - ( old-env def) - (case old-env - #.Nil - ( env def) - - _ - type)) - ([#.UnivQ] - [#.ExQ]) - - (#.Parameter idx) - (default type (list.nth idx env)) - - _ - type - ))"} + {#.doc (text$ ($_ "lux text concat" + "## It's similar to do-template, but meant to be used during pattern-matching." "\n" + "(def: (beta-reduce env type)" "\n" + " (-> (List Type) Type Type)" "\n" + " (case type" "\n" + " (#.Primitive name params)" "\n" + " (#.Primitive name (list/map (beta-reduce env) params))" + "\n\n" + " (^template []" "\n" + " ( left right)" "\n" + " ( (beta-reduce env left) (beta-reduce env right)))" "\n" + " ([#.Sum] [#.Product])" + "\n\n" + " (^template []" "\n" + " ( left right)" "\n" + " ( (beta-reduce env left) (beta-reduce env right)))" "\n" + " ([#.Function] [#.Apply])" + "\n\n" + " (^template []" "\n" + " ( old-env def)" "\n" + " (case old-env" "\n" + " #.Nil" "\n" + " ( env def)" + "\n\n" + " _" "\n" + " type))" "\n" + " ([#.UnivQ] [#.ExQ])" + "\n\n" + " (#.Parameter idx)" "\n" + " (default type (list.nth idx env))" + "\n\n" + " _" "\n" + " type" "\n" + " ))"))} (case tokens (^ (list& [_ (#Form (list& [_ (#Tuple bindings)] templates))] [_ (#Form data)] @@ -5282,16 +5278,17 @@ (text/compose text "\n\n")))) (macro: #export (doc tokens) - {#.doc "## Creates code documentation, embedding text as comments and properly formatting the forms it's being given. - - ## For Example: - (doc \"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 (inc count) (f x)) - x)))"} + {#.doc (text$ ($_ "lux text concat" + "## Creates code documentation, embedding text as comments and properly formatting the forms it's being given." + "\n\n" + "## For Example:" "\n" + "(doc \"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 (inc count) (f x))" "\n" + " x)))"))} (return (list (` [(~ cursor-code) (#.Text (~ (|> tokens (list/map (|>> identify-doc-fragment doc-fragment->Text)) -- cgit v1.2.3 From 5e13ae0ad68947249a98dc69ab513bdbeca1697e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 22 Aug 2018 22:50:33 -0400 Subject: No more escaping of horizontal-tab. --- stdlib/source/lux.lux | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 1b64aa22b..5ffe8d939 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5154,17 +5154,7 @@ (def: (text/encode original) (-> Text Text) - (let [escaped (|> original - (replace-all "\t" "\\t") - (replace-all "\v" "\\v") - (replace-all "\b" "\\b") - (replace-all "\n" "\\n") - (replace-all "\r" "\\r") - (replace-all "\f" "\\f") - (replace-all "\"" "\\\"") - (replace-all "\\" "\\\\") - )] - ($_ text/compose "\"" escaped "\""))) + ($_ text/compose "\"" original "\"")) (do-template [ ] [(def: #export ( value) -- cgit v1.2.3 From a89088576c4e586d3dad18f82eb451ff4eaa14fb Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 00:03:26 -0400 Subject: No more escaping of double-quotes. --- stdlib/source/lux.lux | 127 ++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 61 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 5ffe8d939..5e14a9806 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1,3 +1,8 @@ +("lux def" double-quote + ("lux check" (0 "#Text" (0)) + ("lux int char" +34)) + [["" 0 0] (10 (0))]) + ("lux def" dummy-cursor ("lux check" (2 (0 "#Text" (0)) (2 (0 "#I64" (1 (0 "#Nat" (0)) (0))) @@ -37,7 +42,7 @@ (1 [[dummy-cursor (7 ["lux" "doc"])] [dummy-cursor (5 ("lux text concat" "The type of things whose type is undefined.\n\n" - "Useful for expressions that cause errors or other \"extraordinary\" conditions."))]] + "Useful for expressions that cause errors or other 'extraordinary' conditions."))]] (0)))))]) ## (type: (List a) @@ -1572,10 +1577,10 @@ (text$ ("lux text concat" "## Left-association for the application of binary functions over variadic arguments.\n\n" ("lux text concat" - "(_$ text/compose \"Hello, \" name \".\\nHow are you?\")\n\n" + "(_$ text/compose ''Hello, '' name ''.\\nHow are you?'')\n\n" ("lux text concat" "## =>\n\n" - "(text/compose (text/compose \"Hello, \" name) \".\\nHow are you?\")"))))] + "(text/compose (text/compose ''Hello, '' name) ''.\\nHow are you?'')"))))] #Nil) ({(#Cons op tokens') ({(#Cons first nexts) @@ -1594,10 +1599,10 @@ (text$ ("lux text concat" "## Right-association for the application of binary functions over variadic arguments.\n\n" ("lux text concat" - "($_ text/compose \"Hello, \" name \".\\nHow are you?\")\n\n" + "($_ text/compose ''Hello, '' name ''.\\nHow are you?'')\n\n" ("lux text concat" "## =>\n\n" - "(text/compose \"Hello, \" (text/compose name \".\\nHow are you?\"))"))))] + "(text/compose ''Hello, '' (text/compose name ''.\\nHow are you?''))"))))] #Nil) ({(#Cons op tokens') ({(#Cons last prevs) @@ -1727,8 +1732,8 @@ (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" "Picks which expression to evaluate based on a bit test value." "\n\n" - "(if #1 \"Oh, yeah!\" \"Aw hell naw!\")" "\n\n" - "=> \"Oh, yeah!\""))]) + "(if #1 ''Oh, yeah!'' ''Aw hell naw!'')" "\n\n" + "=> ''Oh, yeah!''"))]) ({(#Cons test (#Cons then (#Cons else #Nil))) (return (list (form$ (list (record$ (list [(bit$ #1) then] [(bit$ #0) else])) @@ -1975,8 +1980,8 @@ (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" "## Macro to treat define new primitive types." "\n\n" - "(primitive \"java.lang.Object\")" "\n\n" - "(primitive \"java.util.List\" [(primitive \"java.lang.Long\")])"))]) + "(primitive ''java.lang.Object'')" "\n\n" + "(primitive ''java.util.List'' [(primitive ''java.lang.Long'')])"))]) ({(#Cons [_ (#Text class-name)] #Nil) (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (tag$ ["lux" "Nil"]))))) @@ -2038,7 +2043,7 @@ (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" "## Quotation as a macro." "\n\n" - "(' \"YOLO\")"))]) + "(' YOLO)"))]) ({(#Cons template #Nil) (do Monad [=template (untemplate #0 "" template)] @@ -2052,9 +2057,9 @@ (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" "## Piping macro." "\n\n" - "(|> elems (list/map int/encode) (interpose \" \") (fold text/compose \"\"))" "\n\n" + "(|> elems (list/map int/encode) (interpose '' '') (fold text/compose ''''))" "\n\n" "## =>" "\n\n" - "(fold text/compose \"\" (interpose \" \" (list/map int/encode elems)))"))]) + "(fold text/compose '''' (interpose '' '' (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) (function' [app acc] @@ -2078,9 +2083,9 @@ (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" "## Reverse piping macro." "\n\n" - "(<| (fold text/compose \"\") (interpose \" \") (list/map int/encode) elems)" "\n\n" + "(<| (fold text/compose '''') (interpose '' '') (list/map int/encode) elems)" "\n\n" "## =>" "\n\n" - "(fold text/compose \"\" (interpose \" \" (list/map int/encode elems)))"))]) + "(fold text/compose '''' (interpose '' '' (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) (function' [app acc] @@ -2961,10 +2966,10 @@ (text$ ($_ "lux text concat" "## Sequential execution of expressions (great for side-effects)." "\n\n" "(exec" "\n" - " " "(log! \"#1\")" "\n" - " " "(log! \"#2\")" "\n" - " " "(log! \"#3\")" "\n" - "\"YOLO\")"))]) + " " "(log! ''#1'')" "\n" + " " "(log! ''#2'')" "\n" + " " "(log! ''#3'')" "\n" + "''YOLO'')"))]) ({(#Cons value actions) (let' [dummy (identifier$ ["" ""])] (return (list (list/fold ("lux check" (-> Code Code Code) @@ -3046,7 +3051,7 @@ (frac/encode value) [_ (#Text value)] - ($_ text/compose "\"" value "\"") + ($_ text/compose ..double-quote value ..double-quote) [_ (#Identifier [prefix name])] (if (text/= "" prefix) @@ -3107,11 +3112,11 @@ (do Monad [] (wrap (list))) _ - (fail ($_ text/compose "\"lux.case\" expects an even number of tokens: " (|> branches - (list/map code-to-text) - (interpose " ") - list/reverse - (list/fold text/compose ""))))} + (fail ($_ text/compose "'lux.case' expects an even number of tokens: " (|> branches + (list/map code-to-text) + (interpose " ") + list/reverse + (list/fold text/compose ""))))} branches)) (macro:' #export (case tokens) @@ -3438,7 +3443,7 @@ " ([#Identifier] [#Tag])" "\n\n" " _" "\n" - " (fail \"Wrong syntax for name-of\")))"))]) + " (fail ''Wrong syntax for name-of'')))"))]) (let [[exported? tokens] (export^ tokens) name+args+meta+body?? (: (Maybe [Name (List Code) Code Code]) (case tokens @@ -3568,8 +3573,8 @@ _ (fail )))] - [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses." "Short-circuiting \"and\".\n(and #1 #0 #1) ## => #0"] - [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses." "Short-circuiting \"or\".\n(or #1 #0 #1) ## => #1"]) + [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses." "Short-circuiting 'and'.\n(and #1 #0 #1) ## => #0"] + [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses." "Short-circuiting 'or'.\n(or #1 #0 #1) ## => #1"]) (def: (index-of part text) (-> Text Text (Maybe Nat)) @@ -3604,7 +3609,7 @@ (def: #export (error! message) {#.doc (text$ ($_ "lux text concat" "## Causes an error, with the given error message." "\n" - "(error! \"OH NO!\")"))} + "(error! ''OH NO!'')"))} (-> Text Nothing) ("lux io error" message)) @@ -3851,7 +3856,7 @@ (#Left "Not expecting any type."))))) (macro: #export (structure tokens) - {#.doc "Not meant to be used directly. Prefer \"structure:\"."} + {#.doc "Not meant to be used directly. Prefer 'structure:'."} (do Monad [tokens' (monad/map Monad macro-expand tokens) struct-type get-expected-type @@ -3961,7 +3966,7 @@ (structure (~+ definitions))))))) #None - (fail "Cannot infer name, so struct must have a name other than \"_\"!")) + (fail "Cannot infer name, so struct must have a name other than '_'!")) #None (fail "Wrong syntax for structure:")))) @@ -4492,9 +4497,9 @@ (macro: #export (^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: #export (range (^open \".\") from to)" "\n" + "## 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: #export (range (^open ''.'') from to)" "\n" " (All [a] (-> (Enum a) a a (List a)))" "\n" " (range' <= succ from to))"))} (case tokens @@ -4509,7 +4514,7 @@ struct-evidence (resolve-type-tags init-type)] (case struct-evidence #None - (fail (text/compose "Can only \"open\" structs: " (type/encode init-type))) + (fail (text/compose "Can only 'open' structs: " (type/encode init-type))) (#Some tags&members) (do Monad @@ -4544,11 +4549,11 @@ (macro: #export (cond tokens) {#.doc (text$ ($_ "lux text concat" "## Branching structures with multiple test conditions." "\n" - "(cond (n/even? num) \"even\"" "\n" - " (n/odd? num) \"odd\"" + "(cond (n/even? num) ''even''" "\n" + " (n/odd? num) ''odd''" "\n\n" " ## else-branch" "\n" - " \"???\")"))} + " ''???'')"))} (if (n/= 0 (n/% 2 (list/size tokens))) (fail "cond requires an uneven number of arguments.") (case (list/reverse tokens) @@ -4649,7 +4654,7 @@ "## Opens a structure and generates a definition for each of its members (including nested members)." "\n\n" "## For example:" "\n" - "(open: \"i:.\" Number)" + "(open: ''i:.'' Number)" "\n\n" "## Will generate:" "\n" "(def: i:+ (:: Number +))" "\n" @@ -4674,7 +4679,7 @@ (return (list/join decls'))) _ - (fail (text/compose "Can only \"open:\" structs: " (type/encode struct-type))))) + (fail (text/compose "Can only 'open:' structs: " (type/encode struct-type))))) _ (do Monad @@ -4689,9 +4694,9 @@ (macro: #export (|>> 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/map int/encode) (interpose \" \") (fold text/compose \"\"))" "\n" + "(|>> (list/map int/encode) (interpose '' '') (fold text/compose ''''))" "\n" "## =>" "\n" - "(function (_ ) (fold text/compose \"\" (interpose \" \" (list/map int/encode ))))"))} + "(function (_ ) (fold text/compose '''' (interpose '' '' (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") g!arg (gensym "arg")] @@ -4700,9 +4705,9 @@ (macro: #export (<<| 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" - "(<<| (fold text/compose \"\") (interpose \" \") (list/map int/encode))" "\n" + "(<<| (fold text/compose '''') (interpose '' '') (list/map int/encode))" "\n" "## =>" "\n" - "(function (_ ) (fold text/compose \"\" (interpose \" \" (list/map int/encode ))))"))} + "(function (_ ) (fold text/compose '''' (interpose '' '' (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") g!arg (gensym "arg")] @@ -4832,17 +4837,17 @@ "## Can take optional annotations and allows the specification of modules to import." "\n\n" "## Example" "\n" - "(.module: {#.doc \"Some documentation...\"}" "\n" + "(.module: {#.doc ''Some documentation...''}" "\n" " [lux #*" "\n" " [control" "\n" - " [\"M\" monad #*]]" "\n" + " [''M'' monad #*]]" "\n" " [data" "\n" " maybe" "\n" - " [\".\" name (\"name/.\" Codec)]]" "\n" + " [''.'' name (''name/.'' Codec)]]" "\n" " [macro" "\n" " code]]" "\n" " [//" "\n" - " [type (\".\" Equivalence)]])"))} + " [type (''.'' Equivalence)]])"))} (do Monad [#let [[_meta _imports] (: [(List [Code Code]) (List Code)] (case tokens @@ -4887,7 +4892,7 @@ (macro: #export (set@ tokens) {#.doc (text$ ($_ "lux text concat" "## Sets the value of a record at a given tag." "\n" - "(set@ #name \"Lux\" lang)" + "(set@ #name ''Lux'' lang)" "\n\n" "## Can also work with multiple levels of nesting:" "\n" "(set@ [#foo #bar #baz] value my-record)" @@ -5154,7 +5159,7 @@ (def: (text/encode original) (-> Text Text) - ($_ text/compose "\"" original "\"")) + ($_ text/compose ..double-quote original ..double-quote)) (do-template [ ] [(def: #export ( value) @@ -5272,8 +5277,8 @@ "## Creates code documentation, embedding text as comments and properly formatting the forms it's being given." "\n\n" "## For Example:" "\n" - "(doc \"Allows arbitrary looping, using the \\\"recur\\\" form to re-start the loop.\"" "\n" - " \"Can be used in monadic code to create monadic loops.\"" "\n" + "(doc ''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" @@ -5337,7 +5342,7 @@ (identifier$ [module name]))) (macro: #export (loop tokens) - {#.doc (doc "Allows arbitrary looping, using the \"recur\" form to re-start the loop." + {#.doc (doc "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] @@ -5480,18 +5485,18 @@ (compare (:: Code/encode encode )) (compare #1 (:: Equivalence = ))] - [(bit #1) "#1" [_ (#.Bit #1)]] - [(bit #0) "#0" [_ (#.Bit #0)]] + [(bit #1) "#1" [_ (#.Bit #1)]] + [(bit #0) "#0" [_ (#.Bit #0)]] [(int +123) "+123" [_ (#.Int +123)]] [(frac +123.0) "+123.0" [_ (#.Frac +123.0)]] - [(text "\n") "\"\\n\"" [_ (#.Text "\n")]] - [(tag ["yolo" "lol"]) "#yolo.lol" [_ (#.Tag ["yolo" "lol"])]] - [(identifier ["yolo" "lol"]) "yolo.lol" [_ (#.Identifier ["yolo" "lol"])]] + [(text "\n") "'\\n'" [_ (#.Text "\n")]] + [(tag ["yolo" "lol"]) "#yolo.lol" [_ (#.Tag ["yolo" "lol"])]] + [(identifier ["yolo" "lol"]) "yolo.lol" [_ (#.Identifier ["yolo" "lol"])]] [(form (list (bit #1) (int +123))) "(#1 +123)" (^ [_ (#.Form (list [_ (#.Bit #1)] [_ (#.Int +123)]))])] [(tuple (list (bit #1) (int +123))) "[#1 +123]" (^ [_ (#.Tuple (list [_ (#.Bit #1)] [_ (#.Int +123)]))])] [(record (list [(bit #1) (int +123)])) "{#1 +123}" (^ [_ (#.Record (list [[_ (#.Bit #1)] [_ (#.Int +123)]]))])] - [(local-tag "lol") "#lol" [_ (#.Tag ["" "lol"])]] - [(local-identifier "lol") "lol" [_ (#.Identifier ["" "lol"])]] + [(local-tag "lol") "#lol" [_ (#.Tag ["" "lol"])]] + [(local-identifier "lol") "lol" [_ (#.Identifier ["" "lol"])]] )] (test-all ))))} (case tokens @@ -5597,7 +5602,7 @@ (wrap (list pattern'))) _ - (fail "Wrong syntax for \"static\"."))) + (fail "Wrong syntax for 'static'."))) (type: Multi-Level-Case [Code (List [Code Code])]) @@ -5750,7 +5755,7 @@ (fail "Wrong syntax for $"))) (def: #export (is? reference sample) - {#.doc (doc "Tests whether the 2 values are identical (not just \"equal\")." + {#.doc (doc "Tests whether the 2 values are identical (not just 'equal')." "This one should succeed:" (let [value +5] (is? value value)) -- cgit v1.2.3 From bc251026c21590da76085bc0bc9abeaa5ec242b6 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 00:56:59 -0400 Subject: No more escaping of new-line. --- stdlib/source/lux.lux | 496 +++++++++++++++++++++++++------------------------- 1 file changed, 252 insertions(+), 244 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 5e14a9806..0417c9a4d 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -3,6 +3,16 @@ ("lux int char" +34)) [["" 0 0] (10 (0))]) +("lux def" new-line + ("lux check" (0 "#Text" (0)) + ("lux int char" +10)) + [["" 0 0] (10 (0))]) + +("lux def" __paragraph + ("lux check" (0 "#Text" (0)) + ("lux text concat" new-line new-line)) + [["" 0 0] (10 (0))]) + ("lux def" dummy-cursor ("lux check" (2 (0 "#Text" (0)) (2 (0 "#I64" (1 (0 "#Nat" (0)) (0))) @@ -25,7 +35,7 @@ [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] [dummy-cursor (5 ("lux text concat" - "The type of things whose type is irrelevant.\n\n" + ("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)))))]) @@ -41,7 +51,7 @@ [dummy-cursor (0 #1)]] (1 [[dummy-cursor (7 ["lux" "doc"])] [dummy-cursor (5 ("lux text concat" - "The type of things whose type is undefined.\n\n" + ("lux text concat" "The type of things whose type is undefined." __paragraph) "Useful for expressions that cause errors or other 'extraordinary' conditions."))]] (0)))))]) @@ -104,7 +114,7 @@ [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] [dummy-cursor (5 ("lux text concat" - "Natural numbers (unsigned integers).\n\n" + ("lux text concat" "Natural numbers (unsigned integers)." __paragraph) "They start at zero (0) and extend in the positive direction."))]] #Nil))))]) @@ -130,7 +140,7 @@ [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] [dummy-cursor (5 ("lux text concat" - "Fractional numbers that live in the interval [0,1).\n\n" + ("lux text concat" "Fractional numbers that live in the interval [0,1)." __paragraph) "Useful for probability, and other domains that work within that interval."))]] #Nil))))]) @@ -167,9 +177,7 @@ (#Cons [[dummy-cursor (7 ["lux" "export?"])] [dummy-cursor (0 #1)]] (#Cons [[dummy-cursor (7 ["lux" "doc"])] - [dummy-cursor (5 ("lux text concat" - "A name.\n\n" - "It is used as part of Lux syntax to represent identifiers and tags."))]] + [dummy-cursor (5 "A name. It is used as part of Lux syntax to represent identifiers and tags.")]] #Nil))))]) ## (type: (Maybe a) @@ -753,9 +761,9 @@ #Nil)))))))))))))] (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "Represents the state of the Lux compiler during a run.\n\n" + ("lux text concat" "Represents the state of the Lux compiler during a run." __paragraph) ("lux text concat" - "It is provided to macros during their invocation, so they can access compiler data.\n\n" + ("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.")))] default-def-meta-exported)))) @@ -769,7 +777,7 @@ (#Apply Text Either))))) (record$ (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "Computations that can have access to the state of the compiler.\n\n" + ("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."))] (#Cons [(tag$ ["lux" "type-args"]) (tuple$ (#Cons (text$ "a") #Nil))] @@ -1033,9 +1041,9 @@ (macro:' #export (comment tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Throws away any code given to it.\n\n" + ("lux text concat" "## Throws away any code given to it." __paragraph) ("lux text concat" - "## Great for commenting-out code, while retaining syntax high-lighting and formatting in your text editor.\n\n" + ("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)")))] #Nil) (return #Nil)) @@ -1227,11 +1235,11 @@ (macro:' #export (All tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Universal quantification.\n\n" + ("lux text concat" "## Universal quantification." __paragraph) ("lux text concat" - "(All [a] (-> a a))\n\n" + ("lux text concat" "(All [a] (-> a a))" __paragraph) ("lux text concat" - "## A name can be provided, to specify a recursive type.\n\n" + ("lux text concat" "## A name can be provided, to specify a recursive type." __paragraph) "(All List [a] (| Any [a (List a)]))"))))] #Nil) (let'' [self-name tokens] ({(#Cons [_ (#Identifier "" self-name)] tokens) @@ -1271,11 +1279,11 @@ (macro:' #export (Ex tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Existential quantification.\n\n" + ("lux text concat" "## Existential quantification." __paragraph) ("lux text concat" - "(Ex [a] [(Codec Text a) a])\n\n" + ("lux text concat" "(Ex [a] [(Codec Text a) a])" __paragraph) ("lux text concat" - "## A name can be provided, to specify a recursive type.\n\n" + ("lux text concat" "## A name can be provided, to specify a recursive type." __paragraph) "(Ex Self [a] [(Codec Text a) a (List (Self a))])"))))] #Nil) (let'' [self-name tokens] ({(#Cons [_ (#Identifier "" self-name)] tokens) @@ -1323,9 +1331,9 @@ (macro:' #export (-> tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Function types:\n\n" + ("lux text concat" "## Function types:" __paragraph) ("lux text concat" - "(-> Int Int Int)\n\n" + ("lux text concat" "(-> Int Int Int)" __paragraph) "## This is the type of a function that takes 2 Ints and returns an Int.")))] #Nil) ({(#Cons output inputs) @@ -1342,7 +1350,7 @@ (macro:' #export (list xs) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## List-construction macro.\n\n" + ("lux text concat" "## List-construction macro." __paragraph) "(list +1 +2 +3)"))] #Nil) (return (#Cons (list/fold (function'' [head tail] @@ -1356,9 +1364,9 @@ (macro:' #export (list& xs) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## List-construction macro, with the last element being a tail-list.\n\n" + ("lux text concat" "## List-construction macro, with the last element being a tail-list." __paragraph) ("lux text concat" - "## In other words, this macro prepends elements to another list.\n\n" + ("lux text concat" "## In other words, this macro prepends elements to another list." __paragraph) "(list& +1 +2 +3 (list +4 +5 +6))")))] #Nil) ({(#Cons last init) @@ -1375,11 +1383,11 @@ (macro:' #export (& tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Tuple types:\n\n" + ("lux text concat" "## Tuple types:" __paragraph) ("lux text concat" - "(& Text Int Bit)\n\n" + ("lux text concat" "(& Text Int Bit)" __paragraph) ("lux text concat" - "## Any.\n\n" + ("lux text concat" "## Any." __paragraph) "(&)"))))] #Nil) ({#Nil @@ -1394,11 +1402,11 @@ (macro:' #export (| tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Variant types:\n\n" + ("lux text concat" "## Variant types:" __paragraph) ("lux text concat" - "(| Text Int Bit)\n\n" + ("lux text concat" "(| Text Int Bit)" __paragraph) ("lux text concat" - "## Nothing.\n\n" + ("lux text concat" "## Nothing." __paragraph) "(|)"))))] #Nil) ({#Nil @@ -1575,12 +1583,12 @@ (macro:' #export (_$ tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Left-association for the application of binary functions over variadic arguments.\n\n" + ("lux text concat" "## Left-association for the application of binary functions over variadic arguments." ..new-line) ("lux text concat" - "(_$ text/compose ''Hello, '' name ''.\\nHow are you?'')\n\n" + ("lux text concat" "(_$ text/compose ''Hello, '' name ''. How are you?'')" ..new-line) ("lux text concat" - "## =>\n\n" - "(text/compose (text/compose ''Hello, '' name) ''.\\nHow are you?'')"))))] + ("lux text concat" "## =>" ..new-line) + "(text/compose (text/compose ''Hello, '' name) ''. How are you?'')"))))] #Nil) ({(#Cons op tokens') ({(#Cons first nexts) @@ -1597,12 +1605,12 @@ (macro:' #export ($_ tokens) (#Cons [(tag$ ["lux" "doc"]) (text$ ("lux text concat" - "## Right-association for the application of binary functions over variadic arguments.\n\n" + ("lux text concat" "## Right-association for the application of binary functions over variadic arguments." ..new-line) ("lux text concat" - "($_ text/compose ''Hello, '' name ''.\\nHow are you?'')\n\n" + ("lux text concat" "($_ text/compose ''Hello, '' name ''. How are you?'')" ..new-line) ("lux text concat" - "## =>\n\n" - "(text/compose ''Hello, '' (text/compose name ''.\\nHow are you?''))"))))] + ("lux text concat" "## =>" ..new-line) + "(text/compose ''Hello, '' (text/compose name ''. How are you?''))"))))] #Nil) ({(#Cons op tokens') ({(#Cons last prevs) @@ -1731,8 +1739,8 @@ (macro:' #export (if tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "Picks which expression to evaluate based on a bit test value." "\n\n" - "(if #1 ''Oh, yeah!'' ''Aw hell naw!'')" "\n\n" + "Picks which expression to evaluate based on a bit test value." __paragraph + "(if #1 ''Oh, yeah!'' ''Aw hell naw!'')" __paragraph "=> ''Oh, yeah!''"))]) ({(#Cons test (#Cons then (#Cons else #Nil))) (return (list (form$ (list (record$ (list [(bit$ #1) then] @@ -1772,7 +1780,7 @@ (def:''' #export (log! message) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "Logs message to standard output." "\n\n" + "Logs message to standard output." __paragraph "Useful for debugging."))]) (-> Text Any) ("lux io log" message)) @@ -1979,8 +1987,8 @@ (macro:' #export (primitive tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Macro to treat define new primitive types." "\n\n" - "(primitive ''java.lang.Object'')" "\n\n" + "## Macro to treat define new primitive types." __paragraph + "(primitive ''java.lang.Object'')" __paragraph "(primitive ''java.util.List'' [(primitive ''java.lang.Long'')])"))]) ({(#Cons [_ (#Text class-name)] #Nil) (return (list (form$ (list (tag$ ["lux" "Primitive"]) (text$ class-name) (tag$ ["lux" "Nil"]))))) @@ -2010,8 +2018,8 @@ (macro:' #export (` tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Hygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." "\n\n" - "## 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." "\n\n" + "## 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))))"))]) ({(#Cons template #Nil) (do Monad @@ -2028,7 +2036,7 @@ (macro:' #export (`' tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." "\n\n" + "## Unhygienic quasi-quotation as a macro. Unquote (~) and unquote-splice (~+) must also be used as forms." __paragraph "(`' (def: (~ name) (function (_ (~+ args)) (~ body))))"))]) ({(#Cons template #Nil) (do Monad @@ -2042,7 +2050,7 @@ (macro:' #export (' tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Quotation as a macro." "\n\n" + "## Quotation as a macro." __paragraph "(' YOLO)"))]) ({(#Cons template #Nil) (do Monad @@ -2056,9 +2064,9 @@ (macro:' #export (|> tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Piping macro." "\n\n" - "(|> elems (list/map int/encode) (interpose '' '') (fold text/compose ''''))" "\n\n" - "## =>" "\n\n" + "## Piping macro." __paragraph + "(|> elems (list/map int/encode) (interpose '' '') (fold text/compose ''''))" __paragraph + "## =>" __paragraph "(fold text/compose '''' (interpose '' '' (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) @@ -2082,9 +2090,9 @@ (macro:' #export (<| tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Reverse piping macro." "\n\n" - "(<| (fold text/compose '''') (interpose '' '') (list/map int/encode) elems)" "\n\n" - "## =>" "\n\n" + "## Reverse piping macro." __paragraph + "(<| (fold text/compose '''') (interpose '' '') (list/map int/encode) elems)" __paragraph + "## =>" __paragraph "(fold text/compose '''' (interpose '' '' (list/map int/encode elems)))"))]) ({(#Cons [init apps]) (return (list (list/fold ("lux check" (-> Code Code Code) @@ -2257,10 +2265,10 @@ (macro:' #export (do-template tokens) (list [(tag$ ["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." "\n\n" - "(do-template [ ]" "\n" - " " "[(def: #export (-> Int Int) (i/+ ))]" "\n\n" - " " "[inc +1]" "\n" + "## By specifying a pattern (with holes), and the input data to fill those holes, repeats the pattern as many times as necessary." __paragraph + "(do-template [ ]" ..new-line + " " "[(def: #export (-> Int Int) (i/+ ))]" __paragraph + " " "[inc +1]" ..new-line " " "[dec -1]"))]) ({(#Cons [[_ (#Tuple bindings)] (#Cons [[_ (#Tuple templates)] data])]) ({[(#Some bindings') (#Some data')] @@ -2608,8 +2616,8 @@ (def:''' #export (not x) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Bit negation." "\n\n" - "(not #1) => #0" "\n\n" + "## Bit negation." __paragraph + "(not #1) => #0" __paragraph "(not #0) => #1"))]) (-> Bit Bit) (if x #0 #1)) @@ -2820,7 +2828,7 @@ (macro:' #export (type tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Takes a type expression and returns it's representation as data-structure." "\n\n" + "## Takes a type expression and returns it's representation as data-structure." __paragraph "(type (All [a] (Maybe (List a))))"))]) ({(#Cons type #Nil) (do Monad @@ -2839,7 +2847,7 @@ (macro:' #export (: tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## The type-annotation macro." "\n\n" + "## The type-annotation macro." __paragraph "(: (List Int) (list +1 +2 +3))"))]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux check" (type (~ type)) (~ value))))) @@ -2851,7 +2859,7 @@ (macro:' #export (:coerce tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## The type-coercion macro." "\n\n" + "## The type-coercion macro." __paragraph "(:coerce Dinosaur (list +1 +2 +3))"))]) ({(#Cons type (#Cons value #Nil)) (return (list (` ("lux coerce" (type (~ type)) (~ value))))) @@ -2949,8 +2957,8 @@ (macro:' #export (Rec tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Parameter-less recursive types." "\n\n" - "## A name has to be given to the whole type, to use it within its body." "\n\n" + "## 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)])"))]) ({(#Cons [_ (#Identifier "" name)] (#Cons body #Nil)) (let' [body' (replace-syntax (list [name (` (#.Apply (~ (make-parameter 1)) (~ (make-parameter 0))))]) @@ -2964,11 +2972,11 @@ (macro:' #export (exec tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Sequential execution of expressions (great for side-effects)." "\n\n" - "(exec" "\n" - " " "(log! ''#1'')" "\n" - " " "(log! ''#2'')" "\n" - " " "(log! ''#3'')" "\n" + "## Sequential execution of expressions (great for side-effects)." __paragraph + "(exec" ..new-line + " " "(log! ''#1'')" ..new-line + " " "(log! ''#2'')" ..new-line + " " "(log! ''#3'')" ..new-line "''YOLO'')"))]) ({(#Cons value actions) (let' [dummy (identifier$ ["" ""])] @@ -3122,12 +3130,12 @@ (macro:' #export (case tokens) (list [(tag$ ["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" - " " "(#Cons x (#Cons y (#Cons z #Nil)))" "\n" - " " "(#Some ($_ i/* x y z))" "\n\n" - " " "_" "\n" + "## The pattern-matching macro." ..new-line + "## Allows the usage of macros within the patterns to provide custom syntax." ..new-line + "(case (: (List Int) (list +1 +2 +3))" ..new-line + " " "(#Cons x (#Cons y (#Cons z #Nil)))" ..new-line + " " "(#Some ($_ i/* x y z))" __paragraph + " " "_" ..new-line " " "#None)"))]) ({(#Cons value branches) (do Monad @@ -3141,13 +3149,13 @@ (macro:' #export (^ tokens) (list [(tag$ ["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" + "## Macro-expanding patterns." ..new-line + "## It's a special macro meant to be used with 'case'." ..new-line + "(case (: (List Int) (list +1 +2 +3))" ..new-line + " (^ (list x y z))" ..new-line " (#Some ($_ i/* x y z))" - "\n\n" - " _" "\n" + __paragraph + " _" ..new-line " #None)"))]) (case tokens (#Cons [_ (#Form (#Cons pattern #Nil))] (#Cons body branches)) @@ -3166,17 +3174,17 @@ (macro:' #export (^or tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Or-patterns." "\n" - "## It's a special macro meant to be used with 'case'." "\n" + "## Or-patterns." ..new-line + "## It's a special macro meant to be used with 'case'." ..new-line "(type: Weekday #Monday #Tuesday #Wednesday #Thursday #Friday #Saturday #Sunday)" - "\n\n" - "(def: (weekend? day)" "\n" - " (-> Weekday Bit)" "\n" - " (case day" "\n" - " (^or #Saturday #Sunday)" "\n" + __paragraph + "(def: (weekend? day)" ..new-line + " (-> Weekday Bit)" ..new-line + " (case day" ..new-line + " (^or #Saturday #Sunday)" ..new-line " #1" - "\n\n" - " _" "\n" + __paragraph + " _" ..new-line " #0))"))]) (case tokens (^ (list& [_ (#Form patterns)] body branches)) @@ -3204,10 +3212,10 @@ (macro:' #export (let tokens) (list [(tag$ ["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" + "## Creates local bindings." ..new-line + "## Can (optionally) use pattern-matching macros when binding." ..new-line + "(let [x (foo bar)" ..new-line + " y (baz quux)]" ..new-line " (op x y))"))]) (case tokens (^ (list [_ (#Tuple bindings)] body)) @@ -3230,12 +3238,12 @@ (macro:' #export (function tokens) (list [(tag$ ["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" + "## Syntax for creating functions." ..new-line + "## Allows for giving the function itself a name, for the sake of recursion." ..new-line + "(: (All [a b] (-> a b a))" ..new-line " (function (_ x y) x))" - "\n\n" - "(: (All [a b] (-> a b a))" "\n" + __paragraph + "(: (All [a b] (-> a b a))" ..new-line " (function (const x y) x))"))]) (case (: (Maybe [Text Code (List Code) Code]) (case tokens @@ -3349,14 +3357,14 @@ (macro:' #export (def: tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Defines global constants/functions." "\n" - "(def: (rejoin-pair pair)" "\n" - " (-> [Code Code] (List Code))" "\n" - " (let [[left right] pair]" "\n" + "## Defines global constants/functions." ..new-line + "(def: (rejoin-pair pair)" ..new-line + " (-> [Code Code] (List Code))" ..new-line + " (let [[left right] pair]" ..new-line " (list left right)))" - "\n\n" - "(def: branching-exponent" "\n" - " Int" "\n" + __paragraph + "(def: branching-exponent" ..new-line + " Int" ..new-line " +5)"))]) (let [[export? tokens'] (export^ tokens) parts (: (Maybe [Code (List Code) (Maybe Code) Code (List [Code Code])]) @@ -3434,15 +3442,15 @@ (macro:' #export (macro: tokens) (list [(tag$ ["lux" "doc"]) (text$ ($_ "lux text concat" - "## Macro-definition macro." "\n" - "(macro: #export (name-of tokens)" "\n" - " (case tokens" "\n" - " (^template []" "\n" - " (^ (list [_ ( [prefix name])]))" "\n" - " (return (list (` [(~ (text$ prefix)) (~ (text$ name))]))))" "\n" + "## Macro-definition macro." ..new-line + "(macro: #export (name-of tokens)" ..new-line + " (case tokens" ..new-line + " (^template []" ..new-line + " (^ (list [_ ( [prefix name])]))" ..new-line + " (return (list (` [(~ (text$ prefix)) (~ (text$ name))]))))" ..new-line " ([#Identifier] [#Tag])" - "\n\n" - " _" "\n" + __paragraph + " _" ..new-line " (fail ''Wrong syntax for name-of'')))"))]) (let [[exported? tokens] (export^ tokens) name+args+meta+body?? (: (Maybe [Name (List Code) Code Code]) @@ -3481,17 +3489,17 @@ (macro: #export (signature: tokens) {#.doc (text$ ($_ "lux text concat" - "## Definition of signatures ala ML." "\n" - "(signature: #export (Ord a)" "\n" - " (: (Equivalence a)" "\n" - " eq)" "\n" - " (: (-> a a Bit)" "\n" - " <)" "\n" - " (: (-> a a Bit)" "\n" - " <=)" "\n" - " (: (-> a a Bit)" "\n" - " >)" "\n" - " (: (-> a a Bit)" "\n" + "## Definition of signatures ala ML." ..new-line + "(signature: #export (Ord a)" ..new-line + " (: (Equivalence a)" ..new-line + " eq)" ..new-line + " (: (-> a a Bit)" ..new-line + " <)" ..new-line + " (: (-> a a Bit)" ..new-line + " <=)" ..new-line + " (: (-> a a Bit)" ..new-line + " >)" ..new-line + " (: (-> a a Bit)" ..new-line " >=))"))} (let [[exported? tokens'] (export^ tokens) ?parts (: (Maybe [Name (List Code) Code (List Code)]) @@ -3573,8 +3581,8 @@ _ (fail )))] - [and (if (~ pre) (~ post) #0) "'and' requires >=1 clauses." "Short-circuiting 'and'.\n(and #1 #0 #1) ## => #0"] - [or (if (~ pre) #1 (~ post)) "'or' requires >=1 clauses." "Short-circuiting 'or'.\n(or #1 #0 #1) ## => #1"]) + [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"]) (def: (index-of part text) (-> Text Text (Maybe Nat)) @@ -3608,18 +3616,18 @@ (def: #export (error! message) {#.doc (text$ ($_ "lux text concat" - "## Causes an error, with the given error message." "\n" + "## Causes an error, with the given error message." ..new-line "(error! ''OH NO!'')"))} (-> Text Nothing) ("lux io error" message)) (macro: (default tokens state) {#.doc (text$ ($_ "lux text concat" - "## Allows you to provide a default value that will be used" "\n" + "## Allows you to provide a default value that will be used" ..new-line "## if a (Maybe x) value turns out to be #.None." - "\n\n" + __paragraph "(default +20 (#.Some +10)) ## => +10" - "\n\n" + __paragraph "(default +20 #.None) ## => +20"))} (case tokens (^ (list else maybe)) @@ -3894,18 +3902,18 @@ (macro: #export (structure: tokens) {#.doc (text$ ($_ "lux text concat" - "## Definition of structures ala ML." "\n" - "(structure: #export Ord (Ord Int)" "\n" - " (def: eq Equivalence)" "\n" - " (def: (< test subject)" "\n" - " (lux.i/< test subject))" "\n" - " (def: (<= test subject)" "\n" - " (or (lux.i/< test subject)" "\n" - " (lux.i/= test subject)))" "\n" - " (def: (> test subject)" "\n" - " (lux.i/> test subject))" "\n" - " (def: (>= test subject)" "\n" - " (or (lux.i/> test subject)" "\n" + "## Definition of structures ala ML." ..new-line + "(structure: #export Ord (Ord Int)" ..new-line + " (def: eq Equivalence)" ..new-line + " (def: (< test subject)" ..new-line + " (lux.i/< test subject))" ..new-line + " (def: (<= test subject)" ..new-line + " (or (lux.i/< test subject)" ..new-line + " (lux.i/= test subject)))" ..new-line + " (def: (> test subject)" ..new-line + " (lux.i/> test subject))" ..new-line + " (def: (>= test subject)" ..new-line + " (or (lux.i/> test subject)" ..new-line " (lux.i/= test subject))))"))} (let [[exported? tokens'] (export^ tokens) ?parts (: (Maybe [Code (List Code) Code Code (List Code)]) @@ -3978,7 +3986,7 @@ (macro: #export (type: tokens) {#.doc (text$ ($_ "lux text concat" - "## The type-definition macro." "\n" + "## The type-definition macro." ..new-line "(type: (List a) #Nil (#Cons a (List a)))"))} (let [[exported? tokens'] (export^ tokens) [rec? tokens'] (case tokens' @@ -4211,9 +4219,9 @@ _ ($_ text/compose prefix "/" clean))] (return output)) (fail ($_ "lux text concat" - "Cannot climb the module hierarchy...\n" - "Importing module: " module "\n" - " Relative Root: " relative-root "\n")))))) + "Cannot climb the module hierarchy..." ..new-line + "Importing module: " module ..new-line + " Relative Root: " relative-root ..new-line)))))) (def: (parse-imports nested? relative-root imports) (-> Bit Text (List Code) (Meta (List Importation))) @@ -4497,10 +4505,10 @@ (macro: #export (^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: #export (range (^open ''.'') from to)" "\n" - " (All [a] (-> (Enum a) a a (List a)))" "\n" + "## Same as the 'open' macro, but meant to be used as a pattern-matching macro for generating local bindings." ..new-line + "## Takes an 'alias' text for the generated local bindings." ..new-line + "(def: #export (range (^open ''.'') from to)" ..new-line + " (All [a] (-> (Enum a) a a (List a)))" ..new-line " (range' <= succ from to))"))} (case tokens (^ (list& [_ (#Form (list [_ (#Text alias)]))] body branches)) @@ -4548,11 +4556,11 @@ (macro: #export (cond tokens) {#.doc (text$ ($_ "lux text concat" - "## Branching structures with multiple test conditions." "\n" - "(cond (n/even? num) ''even''" "\n" + "## Branching structures with multiple test conditions." ..new-line + "(cond (n/even? num) ''even''" ..new-line " (n/odd? num) ''odd''" - "\n\n" - " ## else-branch" "\n" + __paragraph + " ## else-branch" ..new-line " ''???'')"))} (if (n/= 0 (n/% 2 (list/size tokens))) (fail "cond requires an uneven number of arguments.") @@ -4583,14 +4591,14 @@ (macro: #export (get@ tokens) {#.doc (text$ ($_ "lux text concat" - "## Accesses the value of a record at a given tag." "\n" + "## Accesses the value of a record at a given tag." ..new-line "(get@ #field my-record)" - "\n\n" - "## Can also work with multiple levels of nesting:" "\n" + __paragraph + "## Can also work with multiple levels of nesting:" ..new-line "(get@ [#foo #bar #baz] my-record)" - "\n\n" - "## And, if only the slot/path is given, generates an accessor function:" "\n" - "(let [getter (get@ [#foo #bar #baz])]" "\n" + __paragraph + "## And, if only the slot/path is given, generates an accessor function:" ..new-line + "(let [getter (get@ [#foo #bar #baz])]" ..new-line " (getter my-record))"))} (case tokens (^ (list [_ (#Tag slot')] record)) @@ -4652,14 +4660,14 @@ (macro: #export (open: tokens) {#.doc (text$ ($_ "lux text concat" "## Opens a structure and generates a definition for each of its members (including nested members)." - "\n\n" - "## For example:" "\n" + __paragraph + "## For example:" ..new-line "(open: ''i:.'' Number)" - "\n\n" - "## Will generate:" "\n" - "(def: i:+ (:: Number +))" "\n" - "(def: i:- (:: Number -))" "\n" - "(def: i:* (:: Number *))" "\n" + __paragraph + "## Will generate:" ..new-line + "(def: i:+ (:: Number +))" ..new-line + "(def: i:- (:: Number -))" ..new-line + "(def: i:* (:: Number *))" ..new-line "..."))} (case tokens (^ (list [_ (#Text alias)] struct)) @@ -4693,9 +4701,9 @@ (macro: #export (|>> 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/map int/encode) (interpose '' '') (fold text/compose ''''))" "\n" - "## =>" "\n" + "## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..new-line + "(|>> (list/map int/encode) (interpose '' '') (fold text/compose ''''))" ..new-line + "## =>" ..new-line "(function (_ ) (fold text/compose '''' (interpose '' '' (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") @@ -4704,9 +4712,9 @@ (macro: #export (<<| 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" - "(<<| (fold text/compose '''') (interpose '' '') (list/map int/encode))" "\n" - "## =>" "\n" + "## Similar to the piping macro, but rather than taking an initial object to work on, creates a function for taking it." ..new-line + "(<<| (fold text/compose '''') (interpose '' '') (list/map int/encode))" ..new-line + "## =>" ..new-line "(function (_ ) (fold text/compose '''' (interpose '' '' (list/map int/encode ))))"))} (do Monad [g!_ (gensym "_") @@ -4744,10 +4752,10 @@ _ (fail ($_ text/compose "Wrong syntax for refer @ " current-module - "\n" (|> options - (list/map code-to-text) - (interpose " ") - (list/fold text/compose ""))))))) + ..new-line (|> options + (list/map code-to-text) + (interpose " ") + (list/fold text/compose ""))))))) (def: (write-refer module-name [r-defs r-opens]) (-> Text Refer (Meta (List Code))) @@ -4833,20 +4841,20 @@ (macro: #export (module: tokens) {#.doc (text$ ($_ "lux text concat" "## Module-definition macro." - "\n\n" + __paragraph "## Can take optional annotations and allows the specification of modules to import." - "\n\n" - "## Example" "\n" - "(.module: {#.doc ''Some documentation...''}" "\n" - " [lux #*" "\n" - " [control" "\n" - " [''M'' monad #*]]" "\n" - " [data" "\n" - " maybe" "\n" - " [''.'' name (''name/.'' Codec)]]" "\n" - " [macro" "\n" - " code]]" "\n" - " [//" "\n" + __paragraph + "## Example" ..new-line + "(.module: {#.doc ''Some documentation...''}" ..new-line + " [lux #*" ..new-line + " [control" ..new-line + " [''M'' monad #*]]" ..new-line + " [data" ..new-line + " maybe" ..new-line + " [''.'' name (''name/.'' Codec)]]" ..new-line + " [macro" ..new-line + " code]]" ..new-line + " [//" ..new-line " [type (''.'' Equivalence)]])"))} (do Monad [#let [[_meta _imports] (: [(List [Code Code]) (List Code)] @@ -4874,10 +4882,10 @@ (macro: #export (:: tokens) {#.doc (text$ ($_ "lux text concat" - "## Allows accessing the value of a structure's member." "\n" + "## Allows accessing the value of a structure's member." ..new-line "(:: Codec encode)" - "\n\n" - "## Also allows using that value as a function." "\n" + __paragraph + "## Also allows using that value as a function." ..new-line "(:: Codec encode +123)"))} (case tokens (^ (list struct [_ (#Identifier member)])) @@ -4891,14 +4899,14 @@ (macro: #export (set@ tokens) {#.doc (text$ ($_ "lux text concat" - "## Sets the value of a record at a given tag." "\n" + "## Sets the value of a record at a given tag." ..new-line "(set@ #name ''Lux'' lang)" - "\n\n" - "## Can also work with multiple levels of nesting:" "\n" + __paragraph + "## Can also work with multiple levels of nesting:" ..new-line "(set@ [#foo #bar #baz] value my-record)" - "\n\n" - "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" "\n" - "(let [setter (set@ [#foo #bar #baz] value)] (setter my-record))" "\n" + __paragraph + "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" ..new-line + "(let [setter (set@ [#foo #bar #baz] value)] (setter my-record))" ..new-line "(let [setter (set@ [#foo #bar #baz])] (setter value my-record))"))} (case tokens (^ (list [_ (#Tag slot')] value record)) @@ -4978,14 +4986,14 @@ (macro: #export (update@ tokens) {#.doc (text$ ($_ "lux text concat" - "## Modifies the value of a record at a given tag, based on some function." "\n" + "## Modifies the value of a record at a given tag, based on some function." ..new-line "(update@ #age inc person)" - "\n\n" - "## Can also work with multiple levels of nesting:" "\n" + __paragraph + "## Can also work with multiple levels of nesting:" ..new-line "(update@ [#foo #bar #baz] func my-record)" - "\n\n" - "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" "\n" - "(let [updater (update@ [#foo #bar #baz] func)] (updater my-record))" "\n" + __paragraph + "## And, if only the slot/path and (optionally) the value are given, generates a mutator function:" ..new-line + "(let [updater (update@ [#foo #bar #baz] func)] (updater my-record))" ..new-line "(let [updater (update@ [#foo #bar #baz])] (updater func my-record))"))} (case tokens (^ (list [_ (#Tag slot')] fun record)) @@ -5051,38 +5059,38 @@ (macro: #export (^template tokens) {#.doc (text$ ($_ "lux text concat" - "## It's similar to do-template, but meant to be used during pattern-matching." "\n" - "(def: (beta-reduce env type)" "\n" - " (-> (List Type) Type Type)" "\n" - " (case type" "\n" - " (#.Primitive name params)" "\n" + "## It's similar to do-template, but meant to be used during pattern-matching." ..new-line + "(def: (beta-reduce env type)" ..new-line + " (-> (List Type) Type Type)" ..new-line + " (case type" ..new-line + " (#.Primitive name params)" ..new-line " (#.Primitive name (list/map (beta-reduce env) params))" - "\n\n" - " (^template []" "\n" - " ( left right)" "\n" - " ( (beta-reduce env left) (beta-reduce env right)))" "\n" + __paragraph + " (^template []" ..new-line + " ( left right)" ..new-line + " ( (beta-reduce env left) (beta-reduce env right)))" ..new-line " ([#.Sum] [#.Product])" - "\n\n" - " (^template []" "\n" - " ( left right)" "\n" - " ( (beta-reduce env left) (beta-reduce env right)))" "\n" + __paragraph + " (^template []" ..new-line + " ( left right)" ..new-line + " ( (beta-reduce env left) (beta-reduce env right)))" ..new-line " ([#.Function] [#.Apply])" - "\n\n" - " (^template []" "\n" - " ( old-env def)" "\n" - " (case old-env" "\n" - " #.Nil" "\n" + __paragraph + " (^template []" ..new-line + " ( old-env def)" ..new-line + " (case old-env" ..new-line + " #.Nil" ..new-line " ( env def)" - "\n\n" - " _" "\n" - " type))" "\n" + __paragraph + " _" ..new-line + " type))" ..new-line " ([#.UnivQ] [#.ExQ])" - "\n\n" - " (#.Parameter idx)" "\n" + __paragraph + " (#.Parameter idx)" ..new-line " (default type (list.nth idx env))" - "\n\n" - " _" "\n" - " type" "\n" + __paragraph + " _" ..new-line + " type" ..new-line " ))"))} (case tokens (^ (list& [_ (#Form (list& [_ (#Tuple bindings)] templates))] @@ -5196,7 +5204,7 @@ (-> Nat Cursor Cursor Text) (if (n/= old-line new-line) (text/join (repeat (.int (n/- old-column new-column)) " ")) - (let [extra-lines (text/join (repeat (.int (n/- old-line new-line)) "\n")) + (let [extra-lines (text/join (repeat (.int (n/- old-line new-line)) ..new-line)) space-padding (text/join (repeat (.int (n/- baseline new-column)) " "))] (text/compose extra-lines space-padding)))) @@ -5262,27 +5270,27 @@ (case fragment (#Doc-Comment comment) (|> comment - (text/split "\n") - (list/map (function (_ line) ($_ text/compose "## " line "\n"))) + (text/split ..new-line) + (list/map (function (_ line) ($_ text/compose "## " line ..new-line))) text/join) (#Doc-Example example) (let [baseline (find-baseline-column example) [cursor _] example [_ text] (doc-example->Text (with-baseline baseline cursor) baseline example)] - (text/compose text "\n\n")))) + (text/compose text __paragraph)))) (macro: #export (doc tokens) {#.doc (text$ ($_ "lux text concat" "## Creates code documentation, embedding text as comments and properly formatting the forms it's being given." - "\n\n" - "## For Example:" "\n" - "(doc ''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 (inc count) (f x))" "\n" + __paragraph + "## For Example:" ..new-line + "(doc ''Allows arbitrary looping, using the \\''recur\\'' form to re-start the loop.''" ..new-line + " ''Can be used in monadic code to create monadic loops.''" ..new-line + " (loop [count +0" ..new-line + " x init]" ..new-line + " (if (< +10 count)" ..new-line + " (recur (inc count) (f x))" ..new-line " x)))"))} (return (list (` [(~ cursor-code) (#.Text (~ (|> tokens @@ -5489,7 +5497,7 @@ [(bit #0) "#0" [_ (#.Bit #0)]] [(int +123) "+123" [_ (#.Int +123)]] [(frac +123.0) "+123.0" [_ (#.Frac +123.0)]] - [(text "\n") "'\\n'" [_ (#.Text "\n")]] + [(text "123") "'123'" [_ (#.Text "123")]] [(tag ["yolo" "lol"]) "#yolo.lol" [_ (#.Tag ["yolo" "lol"])]] [(identifier ["yolo" "lol"]) "yolo.lol" [_ (#.Identifier ["yolo" "lol"])]] [(form (list (bit #1) (int +123))) "(#1 +123)" (^ [_ (#.Form (list [_ (#.Bit #1)] [_ (#.Int +123)]))])] -- cgit v1.2.3 From 7e312258b13c5fc9c80079fede0e41d479a8a327 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 01:24:29 -0400 Subject: No more escaping of back-slash. --- stdlib/source/lux.lux | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 0417c9a4d..bfbfe0678 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5285,7 +5285,7 @@ "## Creates code documentation, embedding text as comments and properly formatting the forms it's being given." __paragraph "## For Example:" ..new-line - "(doc ''Allows arbitrary looping, using the \\''recur\\'' form to re-start the loop.''" ..new-line + "(doc ''Allows arbitrary looping, using the 'recur' form to re-start the loop.''" ..new-line " ''Can be used in monadic code to create monadic loops.''" ..new-line " (loop [count +0" ..new-line " x init]" ..new-line -- cgit v1.2.3 From d9965e587905cd715ecd4c7150236d660321a02c Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 17:18:30 -0400 Subject: Optimized text clipping. --- stdlib/source/lux.lux | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index bfbfe0678..5abcab3dc 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1,23 +1,17 @@ ("lux def" double-quote - ("lux check" (0 "#Text" (0)) - ("lux int char" +34)) + ("lux int char" +34) [["" 0 0] (10 (0))]) ("lux def" new-line - ("lux check" (0 "#Text" (0)) - ("lux int char" +10)) + ("lux int char" +10) [["" 0 0] (10 (0))]) ("lux def" __paragraph - ("lux check" (0 "#Text" (0)) - ("lux text concat" new-line new-line)) + ("lux text concat" new-line new-line) [["" 0 0] (10 (0))]) ("lux def" dummy-cursor - ("lux check" (2 (0 "#Text" (0)) - (2 (0 "#I64" (1 (0 "#Nat" (0)) (0))) - (0 "#I64" (1 (0 "#Nat" (0)) (0))))) - ["" 0 0]) + ["" 0 0] [["" 0 0] (10 (1 [[["" 0 0] (7 ["lux" "export?"])] [["" 0 0] (0 #1)]] @@ -3606,13 +3600,19 @@ #None #None)) -(def: (clip1 from text) +(def: (clip/1 from text) (-> Nat Text (Maybe Text)) - ("lux text clip" text from ("lux text size" text))) + (let [size ("lux text size" text)] + (if (n/<= size from) + (#.Some ("lux text clip" text from size)) + #.None))) -(def: (clip2 from to text) +(def: (clip/2 from to text) (-> Nat Nat Text (Maybe Text)) - ("lux text clip" text from to)) + (if (and (n/<= to from) + (n/<= ("lux text size" text) to)) + (#.Some ("lux text clip" text from to)) + #.None)) (def: #export (error! message) {#.doc (text$ ($_ "lux text concat" @@ -3651,10 +3651,10 @@ (#Some idx) (list& (default (error! "UNDEFINED") - (clip2 0 idx input)) + (clip/2 0 idx input)) (text/split splitter (default (error! "UNDEFINED") - (clip1 (n/+ 1 idx) input)))))) + (clip/1 (n/+ 1 idx) input)))))) (def: (nth idx xs) (All [a] @@ -4146,7 +4146,7 @@ (def: (split at x) (-> Nat Text (Maybe [Text Text])) - (case [(..clip2 0 at x) (..clip1 at x)] + (case [(..clip/2 0 at x) (..clip/1 at x)] [(#.Some pre) (#.Some post)] (#.Some [pre post]) @@ -4213,7 +4213,7 @@ list/reverse (interpose "/") text/join) - clean (|> module (clip1 ups) (default (error! "UNDEFINED"))) + clean ("lux text clip" module ups ("lux text size" module)) output (case ("lux text size" clean) 0 prefix _ ($_ text/compose prefix "/" clean))] -- cgit v1.2.3 From 312cc7dc5f0be0ef0a48ea8470d8ee64b929bc7b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 19:02:47 -0400 Subject: "lux text char" is now unsafe/optimized. --- stdlib/source/lux.lux | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 5abcab3dc..916b77797 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -3650,11 +3650,9 @@ (list input) (#Some idx) - (list& (default (error! "UNDEFINED") - (clip/2 0 idx input)) + (list& ("lux text clip" input 0 idx) (text/split splitter - (default (error! "UNDEFINED") - (clip/1 (n/+ 1 idx) input)))))) + ("lux text clip" input (n/+ 1 idx) ("lux text size" input)))))) (def: (nth idx xs) (All [a] @@ -4144,23 +4142,17 @@ _ (return [#.Nil parts]))) -(def: (split at x) - (-> Nat Text (Maybe [Text Text])) - (case [(..clip/2 0 at x) (..clip/1 at x)] - [(#.Some pre) (#.Some post)] - (#.Some [pre post]) - - _ - #.None)) +(def: (split! at x) + (-> Nat Text [Text Text]) + [("lux text clip" x 0 at) + ("lux text clip" x at ("lux text size" x))]) (def: (split-with token sample) (-> Text Text (Maybe [Text Text])) (do ..Monad [index (..index-of token sample) - pre+post' (split index sample) - #let [[pre post'] pre+post'] - _+post (split ("lux text size" token) post') - #let [[_ post] _+post]] + #let [[pre post'] (split! index sample) + [_ post] (split! ("lux text size" token) post')]] (wrap [pre post]))) (def: (replace-all pattern value template) @@ -5961,7 +5953,6 @@ (^multi (^ (list [_ (#Text input)])) (n/= 1 ("lux text size" input))) (|> ("lux text char" input 0) - (default (undefined)) nat$ list [compiler] #Right) -- cgit v1.2.3