From 38d5f05977c54770195129df5ede2c91be4a32af Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 2 Jul 2017 12:29:36 -0400 Subject: - Lux no longer has a Char primitive data-type. --- stdlib/source/lux.lux | 206 ++++++++++++++++++++------------------------------ 1 file changed, 84 insertions(+), 122 deletions(-) (limited to 'stdlib/source/lux.lux') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index c108428d8..76db92f2f 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -4,7 +4,7 @@ (+0 "#Bool" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Your standard, run-of-the-mill boolean values.")] + (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill boolean values.")] (+0))))) (_lux_def Nat @@ -12,7 +12,7 @@ (+0 "#Nat" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Natural numbers (unsigned integers). + (+1 [["lux" "doc"] (+5 "Natural numbers (unsigned integers). They start at zero (+0) and extend in the positive direction.")] (+0))))) @@ -22,7 +22,7 @@ (+0 "#Int" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Your standard, run-of-the-mill integer numbers.")] + (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill integer numbers.")] (+0))))) (_lux_def Real @@ -30,7 +30,7 @@ (+0 "#Real" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Your standard, run-of-the-mill floating-point numbers.")] + (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill floating-point numbers.")] (+0))))) (_lux_def Deg @@ -38,25 +38,17 @@ (+0 "#Deg" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Fractional numbers that live in the interval [0,1). + (+1 [["lux" "doc"] (+5 "Fractional numbers that live in the interval [0,1). Useful for probability, and other domains that work within that interval.")] (+0))))) -(_lux_def Char - (+12 ["lux" "Char"] - (+0 "#Char" (+0))) - (+1 [["lux" "type?"] (+0 true)] - (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Your standard, run-of-the-mill character values.")] - (+0))))) - (_lux_def Text (+12 ["lux" "Text"] (+0 "#Text" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "Your standard, run-of-the-mill string values.")] + (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill string values.")] (+0))))) (_lux_def Void @@ -64,7 +56,7 @@ (+1)) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "An unusual type that possesses no value, and thus cannot be instantiated.")] + (+1 [["lux" "doc"] (+5 "An unusual type that possesses no value, and thus cannot be instantiated.")] (+0))))) (_lux_def Unit @@ -72,7 +64,7 @@ (+2)) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "An unusual type that only possesses a single value: []")] + (+1 [["lux" "doc"] (+5 "An unusual type that only possesses a single value: []")] (+0))))) (_lux_def Ident @@ -80,7 +72,7 @@ (+4 Text Text)) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "doc"] (+6 "An identifier. + (+1 [["lux" "doc"] (+5 "An identifier. It is used as part of Lux syntax to represent symbols and tags.")] (+0))))) @@ -98,9 +90,9 @@ (+11 (+6 +1) (+6 +0)))))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] - (+1 [["lux" "tags"] (+8 (+1 (+6 "Nil") (+1 (+6 "Cons") (+0))))] - (+1 [["lux" "type-args"] (+8 (+1 (+6 "a") (+0)))] - (+1 [["lux" "doc"] (+6 "A potentially empty list of values.")] + (+1 [["lux" "tags"] (+7 (+1 (+5 "Nil") (+1 (+5 "Cons") (+0))))] + (+1 [["lux" "type-args"] (+7 (+1 (+5 "a") (+0)))] + (+1 [["lux" "doc"] (+5 "A potentially empty list of values.")] (+0))))))) ## (type: (Maybe a) @@ -115,9 +107,9 @@ (+6 +1)))) (#Cons [["lux" "type?"] (+0 true)] (#Cons [["lux" "export?"] (+0 true)] - (#Cons [["lux" "tags"] (+8 (#Cons (+6 "None") (#Cons (+6 "Some") #Nil)))] - (#Cons [["lux" "type-args"] (+8 (#Cons (+6 "a") #Nil))] - (#Cons [["lux" "doc"] (+6 "A potentially missing value.")] + (#Cons [["lux" "tags"] (+7 (#Cons (+5 "None") (#Cons (+5 "Some") #Nil)))] + (#Cons [["lux" "type-args"] (+7 (#Cons (+5 "a") #Nil))] + (#Cons [["lux" "doc"] (+5 "A potentially missing value.")] #Nil)))))) ## (type: #rec Type @@ -173,21 +165,21 @@ (+4 Ident Type))))))))))))))))))) (#Cons [["lux" "type?"] (+0 true)] (#Cons [["lux" "export?"] (+0 true)] - (#Cons [["lux" "tags"] (+8 (#Cons (+6 "Host") - (#Cons (+6 "Void") - (#Cons (+6 "Unit") - (#Cons (+6 "Sum") - (#Cons (+6 "Product") - (#Cons (+6 "Function") - (#Cons (+6 "Bound") - (#Cons (+6 "Var") - (#Cons (+6 "Ex") - (#Cons (+6 "UnivQ") - (#Cons (+6 "ExQ") - (#Cons (+6 "Apply") - (#Cons (+6 "Named") + (#Cons [["lux" "tags"] (+7 (#Cons (+5 "Host") + (#Cons (+5 "Void") + (#Cons (+5 "Unit") + (#Cons (+5 "Sum") + (#Cons (+5 "Product") + (#Cons (+5 "Function") + (#Cons (+5 "Bound") + (#Cons (+5 "Var") + (#Cons (+5 "Ex") + (#Cons (+5 "UnivQ") + (#Cons (+5 "ExQ") + (#Cons (+5 "Apply") + (#Cons (+5 "Named") #Nil))))))))))))))] - (#Cons [["lux" "doc"] (+6 "This type represents the data-structures that are used to specify types themselves.")] + (#Cons [["lux" "doc"] (+5 "This type represents the data-structures that are used to specify types themselves.")] (#Cons [["lux" "type-rec?"] (+0 true)] #Nil)))))) @@ -198,7 +190,7 @@ (#ExQ #Nil (#Bound +1))) (#Cons [["lux" "type?"] (+0 true)] (#Cons [["lux" "export?"] (+0 true)] - (#Cons [["lux" "doc"] (+6 "The type of things whose type does not matter. + (#Cons [["lux" "doc"] (+5 "The type of things whose type does not matter. It can be used to write functions or data-structures that can take, or return, anything.")] #Nil)))) @@ -210,7 +202,7 @@ (#UnivQ #Nil (#Bound +1))) (#Cons [["lux" "type?"] (+0 true)] (#Cons [["lux" "export?"] (+0 true)] - (#Cons [["lux" "doc"] (+6 "The type of things whose type is unknown or undefined. + (#Cons [["lux" "doc"] (+5 "The type of things whose type is unknown or undefined. Useful for expressions that cause errors or other \"extraordinary\" conditions.")] #Nil)))) @@ -221,7 +213,6 @@ ## (#IntA Int) ## (#DegA Deg) ## (#RealA Real) -## (#CharA Char) ## (#TextA Text) ## (#IdentA Ident) ## (#ListA (List Ann-Value)) @@ -242,33 +233,30 @@ Deg (#Sum ## #RealA Real - (#Sum ## #CharA - Char - (#Sum ## #TextA - Text - (#Sum ## #IdentA - Ident - (#Sum ## #ListA - (#Apply Ann-Value List) - ## #DictA - (#Apply (#Product Text Ann-Value) List)))))))))) + (#Sum ## #TextA + Text + (#Sum ## #IdentA + Ident + (#Sum ## #ListA + (#Apply Ann-Value List) + ## #DictA + (#Apply (#Product Text Ann-Value) List))))))))) )) )) (#Cons [["lux" "type?"] (+0 true)] (#Cons [["lux" "export?"] (+0 true)] - (#Cons [["lux" "tags"] (+8 (#Cons (+6 "BoolA") - (#Cons (+6 "NatA") - (#Cons (+6 "IntA") - (#Cons (+6 "DegA") - (#Cons (+6 "RealA") - (#Cons (+6 "CharA") - (#Cons (+6 "TextA") - (#Cons (+6 "IdentA") - (#Cons (+6 "ListA") - (#Cons (+6 "DictA") - #Nil)))))))))))] + (#Cons [["lux" "tags"] (+7 (#Cons (+5 "BoolA") + (#Cons (+5 "NatA") + (#Cons (+5 "IntA") + (#Cons (+5 "DegA") + (#Cons (+5 "RealA") + (#Cons (+5 "TextA") + (#Cons (+5 "IdentA") + (#Cons (+5 "ListA") + (#Cons (+5 "DictA") + #Nil))))))))))] (#Cons [["lux" "type-rec?"] (+0 true)] - (#Cons [["lux" "doc"] (+6 "The value of an individual annotation.")] + (#Cons [["lux" "doc"] (+5 "The value of an individual annotation.")] #Nil)))))) ## (type: Anns @@ -393,7 +381,6 @@ ## (#Int Int) ## (#Deg Deg) ## (#Real Real) -## (#Char Char) ## (#Text Text) ## (#Symbol Text Text) ## (#Tag Text Text) @@ -419,35 +406,32 @@ Deg (#Sum ## "lux;Real" Real - (#Sum ## "lux;Char" - Char - (#Sum ## "lux;Text" - Text - (#Sum ## "lux;Symbol" + (#Sum ## "lux;Text" + Text + (#Sum ## "lux;Symbol" + Ident + (#Sum ## "lux;Tag" Ident - (#Sum ## "lux;Tag" - Ident - (#Sum ## "lux;Form" + (#Sum ## "lux;Form" + Code-List + (#Sum ## "lux;Tuple" Code-List - (#Sum ## "lux;Tuple" - Code-List - ## "lux;Record" - (#Apply (#Product Code Code) List) - ))))))))))) + ## "lux;Record" + (#Apply (#Product Code Code) List) + )))))))))) )))) (#Cons [["lux" "tags"] (#ListA (#Cons (#TextA "Bool") (#Cons (#TextA "Nat") (#Cons (#TextA "Int") (#Cons (#TextA "Deg") (#Cons (#TextA "Real") - (#Cons (#TextA "Char") - (#Cons (#TextA "Text") - (#Cons (#TextA "Symbol") - (#Cons (#TextA "Tag") - (#Cons (#TextA "Form") - (#Cons (#TextA "Tuple") - (#Cons (#TextA "Record") - #Nil)))))))))))))] + (#Cons (#TextA "Text") + (#Cons (#TextA "Symbol") + (#Cons (#TextA "Tag") + (#Cons (#TextA "Form") + (#Cons (#TextA "Tuple") + (#Cons (#TextA "Record") + #Nil))))))))))))] (#Cons [["lux" "type-args"] (#ListA (#Cons (#TextA "w") #;Nil))] default-def-meta-exported))) @@ -753,11 +737,6 @@ (_lux_function _ value (_meta (#Real value)))) #Nil) -(_lux_def char$ - (_lux_: (#Function Char Code) - (_lux_function _ value (_meta (#Char value)))) - #Nil) - (_lux_def text$ (_lux_: (#Function Text Code) (_lux_function _ text (_meta (#Text text)))) @@ -1802,9 +1781,6 @@ [_ [_ (#Real value)]] (return (wrap-meta (form$ (list (tag$ ["lux" "Real"]) (real$ value))))) - [_ [_ (#Char value)]] - (return (wrap-meta (form$ (list (tag$ ["lux" "Char"]) (char$ value))))) - [_ [_ (#Text value)]] (return (wrap-meta (form$ (list (tag$ ["lux" "Text"]) (text$ value))))) @@ -2281,21 +2257,6 @@ (-> Real Text) (_lux_proc ["real" "encode"] [x])) -(def:''' (Char/encode x) - #Nil - (-> Char Text) - (let' [as-text (_lux_case x - #"\t" "\\t" - #"\v" "\\v" - #"\b" "\\b" - #"\n" "\\n" - #"\r" "\\r" - #"\f" "\\f" - #"\"" "\\\"" - #"\\" "\\\\" - _ (_lux_proc ["char" "to-text"] [x]))] - ($_ Text/append "#\"" as-text "\""))) - (def:''' (multiple? div n) #Nil (-> Int Int Bool) @@ -2728,9 +2689,6 @@ [_ (#Real value)] (Real/encode value) - [_ (#Char value)] - ($_ Text/append "#" "\"" (Char/encode value) "\"") - [_ (#Text value)] ($_ Text/append "\"" value "\"") @@ -2961,9 +2919,6 @@ [_ (#Real value)] (return (form$ (list (tag$ ["lux" "RealA"]) (real$ value)))) - [_ (#Char value)] - (return (form$ (list (tag$ ["lux" "CharA"]) (char$ value)))) - [_ (#Text value)] (return (form$ (list (tag$ ["lux" "TextA"]) (text$ value)))) @@ -4937,7 +4892,6 @@ [#Int] [#Deg] [#Real] - [#Char] [#Text] [#Symbol] [#Tag]) @@ -5055,7 +5009,6 @@ [#Nat Nat/encode] [#Int Int/encode] [#Real Real/encode] - [#Char Char/encode] [#Text Text/encode] [#Symbol Ident/encode] [#Tag Tag/encode]) @@ -5255,7 +5208,7 @@ (def: (place-tokens label tokens target) (-> Text (List Code) Code (Maybe (List Code))) (case target - (^or [_ (#Bool _)] [_ (#Nat _)] [_ (#Int _)] [_ (#Deg _)] [_ (#Real _)] [_ (#Char _)] [_ (#Text _)] [_ (#Tag _)]) + (^or [_ (#Bool _)] [_ (#Nat _)] [_ (#Int _)] [_ (#Deg _)] [_ (#Real _)] [_ (#Text _)] [_ (#Tag _)]) (#Some (list target)) [_ (#Symbol [prefix name])] @@ -5305,7 +5258,6 @@ [(bool false) "false" [_ (#;Bool false)]] [(int 123) "123" [_ (#;Int 123)]] [(real 123.0) "123.0" [_ (#;Real 123.0)]] - [(char #"\n") "#\"\\n\"" [_ (#;Char #"\n")]] [(text "\n") "\"\\n\"" [_ (#;Text "\n")]] [(tag ["yolo" "lol"]) "#yolo;lol" [_ (#;Tag ["yolo" "lol"])]] [(symbol ["yolo" "lol"]) "yolo;lol" [_ (#;Symbol ["yolo" "lol"])]] @@ -5351,7 +5303,6 @@ ["Int"] ["Deg"] ["Real"] - ["Char"] ["Text"]) (#Named _ type') @@ -5374,7 +5325,6 @@ ["Int" Int int$] ["Deg" Deg deg$] ["Real" Real real$] - ["Char" Char char$] ["Text" Text text$]) _ @@ -5412,7 +5362,7 @@ )) (macro: #export (^~ tokens) - {#;doc (doc "Use global defs with simple values, such as text, int, real, bool and char, in place of literals in patterns." + {#;doc (doc "Use global defs with simple values, such as text, int, real and bool in place of literals in patterns." "The definitions must be properly-qualified (though you may use one of the short-cuts Lux provides)." (def: (empty?' node) (All [K V] (-> (Node K V) Bool)) @@ -5791,5 +5741,17 @@ (All [a] (-> (Maybe a) a)) (|>. (default (undefined)))) -(macro: #export (as-is tokens state) - (#;Right [state tokens])) +(macro: #export (as-is tokens compiler) + (#;Right [compiler tokens])) + +(macro: #export (char tokens compiler) + (case tokens + (^multi (^ (list [_ (#Text input)])) + (n.= +1 (_lux_proc ["text" "size"] [input]))) + (|> (_lux_proc ["text" "char"] [input +0]) + assume + nat$ list + [compiler] #;Right) + + _ + (#;Left "Wrong syntax for char"))) -- cgit v1.2.3