From f08a9fb208a32ee8f450649095c4f8a0f05931da Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 4 Sep 2017 19:41:59 -0400 Subject: - Re-named "real" numbers to "frac"(tions). --- stdlib/source/lux.lux | 92 +++++----- stdlib/source/lux/control/concatenative.lux | 24 +-- stdlib/source/lux/data/color.lux | 232 +++++++++++++------------- stdlib/source/lux/data/format/css.lux | 2 +- stdlib/source/lux/data/format/json.lux | 8 +- stdlib/source/lux/data/format/json/codec.lux | 38 ++--- stdlib/source/lux/data/format/json/reader.lux | 6 +- stdlib/source/lux/data/number.lux | 156 ++++++++--------- stdlib/source/lux/data/number/complex.lux | 200 +++++++++++----------- stdlib/source/lux/data/text/format.lux | 2 +- stdlib/source/lux/host.js.lux | 6 +- stdlib/source/lux/host.jvm.lux | 4 +- stdlib/source/lux/macro.lux | 2 +- stdlib/source/lux/macro/code.lux | 8 +- stdlib/source/lux/macro/poly.lux | 4 +- stdlib/source/lux/macro/poly/eq.lux | 2 +- stdlib/source/lux/macro/syntax.lux | 2 +- stdlib/source/lux/math.lux | 16 +- stdlib/source/lux/math/logic/fuzzy.lux | 18 +- stdlib/source/lux/math/random.lux | 12 +- stdlib/test/test/lux.lux | 10 +- stdlib/test/test/lux/data/color.lux | 54 +++--- stdlib/test/test/lux/data/format/json.lux | 46 ++--- stdlib/test/test/lux/data/number.lux | 34 ++-- stdlib/test/test/lux/data/number/complex.lux | 58 +++---- stdlib/test/test/lux/data/number/ratio.lux | 1 - stdlib/test/test/lux/host.js.lux | 4 +- stdlib/test/test/lux/macro/code.lux | 2 +- stdlib/test/test/lux/macro/poly/eq.lux | 20 +-- stdlib/test/test/lux/macro/syntax.lux | 4 +- stdlib/test/test/lux/math.lux | 40 ++--- stdlib/test/test/lux/math/logic/fuzzy.lux | 22 +-- 32 files changed, 564 insertions(+), 565 deletions(-) (limited to 'stdlib') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index 7a49fb2ec..d29e4fca5 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -25,9 +25,9 @@ (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill integer numbers.")] (+0))))) -(_lux_def Real - (+12 ["lux" "Real"] - (+0 "#Real" (+0))) +(_lux_def Frac + (+12 ["lux" "Frac"] + (+0 "#Frac" (+0))) (+1 [["lux" "type?"] (+0 true)] (+1 [["lux" "export?"] (+0 true)] (+1 [["lux" "doc"] (+5 "Your standard, run-of-the-mill floating-point numbers.")] @@ -212,7 +212,7 @@ ## (#NatA Nat) ## (#IntA Int) ## (#DegA Deg) -## (#RealA Real) +## (#FracA Frac) ## (#TextA Text) ## (#IdentA Ident) ## (#ListA (List Ann-Value)) @@ -231,8 +231,8 @@ Int (#Sum ## #DegA Deg - (#Sum ## #RealA - Real + (#Sum ## #FracA + Frac (#Sum ## #TextA Text (#Sum ## #IdentA @@ -249,7 +249,7 @@ (#Cons (+5 "NatA") (#Cons (+5 "IntA") (#Cons (+5 "DegA") - (#Cons (+5 "RealA") + (#Cons (+5 "FracA") (#Cons (+5 "TextA") (#Cons (+5 "IdentA") (#Cons (+5 "ListA") @@ -380,7 +380,7 @@ ## (#Nat Nat) ## (#Int Int) ## (#Deg Deg) -## (#Real Real) +## (#Frac Frac) ## (#Text Text) ## (#Symbol Text Text) ## (#Tag Text Text) @@ -404,8 +404,8 @@ Int (#Sum ## "lux;Deg" Deg - (#Sum ## "lux;Real" - Real + (#Sum ## "lux;Frac" + Frac (#Sum ## "lux;Text" Text (#Sum ## "lux;Symbol" @@ -424,7 +424,7 @@ (#Cons (#TextA "Nat") (#Cons (#TextA "Int") (#Cons (#TextA "Deg") - (#Cons (#TextA "Real") + (#Cons (#TextA "Frac") (#Cons (#TextA "Text") (#Cons (#TextA "Symbol") (#Cons (#TextA "Tag") @@ -732,9 +732,9 @@ (_lux_function _ value (_meta (#Deg value)))) #Nil) -(_lux_def real$ - (_lux_: (#Function Real Code) - (_lux_function _ value (_meta (#Real value)))) +(_lux_def frac$ + (_lux_: (#Function Frac Code) + (_lux_function _ value (_meta (#Frac value)))) #Nil) (_lux_def text$ @@ -1778,8 +1778,8 @@ [_ [_ (#Deg value)]] (return (wrap-meta (form$ (list (tag$ ["lux" "Deg"]) (deg$ value))))) - [_ [_ (#Real value)]] - (return (wrap-meta (form$ (list (tag$ ["lux" "Real"]) (real$ value))))) + [_ [_ (#Frac value)]] + (return (wrap-meta (form$ (list (tag$ ["lux" "Frac"]) (frac$ value))))) [_ [_ (#Text value)]] (return (wrap-meta (form$ (list (tag$ ["lux" "Text"]) (text$ value))))) @@ -2121,16 +2121,16 @@ (_lux_proc [ "="] [subject test])))] [ Nat "nat" n.= n.< n.<= n.> n.>= - "Natural equality." "Natural less-than." "Natural less-than-equal." "Natural greater-than." "Natural greater-than-equal."] + "Nat(ural) equality." "Nat(ural) less-than." "Nat(ural) less-than-equal." "Nat(ural) greater-than." "Nat(ural) greater-than-equal."] [ Int "int" i.= i.< i.<= i.> i.>= - "Integer equality." "Integer less-than." "Integer less-than-equal." "Integer greater-than." "Integer greater-than-equal."] + "Int(eger) equality." "Int(eger) less-than." "Int(eger) less-than-equal." "Int(eger) greater-than." "Int(eger) greater-than-equal."] [ Deg "deg" d.= d.< d.<= d.> d.>= - "Degree equality." "Degree less-than." "Degree less-than-equal." "Degree greater-than." "Degree greater-than-equal."] + "Deg(ree) equality." "Deg(ree) less-than." "Deg(ree) less-than-equal." "Deg(ree) greater-than." "Deg(ree) greater-than-equal."] - [Real "real" r.= r.< r.<= r.> r.>= - "Real equality." "Real less-than." "Real less-than-equal." "Real greater-than." "Real greater-than-equal."] + [Frac "frac" f.= f.< f.<= f.> f.>= + "Frac(tion) equality." "Frac(tion) less-than." "Frac(tion) less-than-equal." "Frac(tion) greater-than." "Frac(tion) greater-than-equal."] ) (do-template [ ] @@ -2157,11 +2157,11 @@ [ Deg d./ [ "deg" "/"] "Deg(ree) division."] [ Deg d.% [ "deg" "%"] "Deg(ree) remainder."] - [Real r.+ ["real" "+"] "Real addition."] - [Real r.- ["real" "-"] "Real substraction."] - [Real r.* ["real" "*"] "Real multiplication."] - [Real r./ ["real" "/"] "Real division."] - [Real r.% ["real" "%"] "Real remainder."] + [Frac f.+ ["frac" "+"] "Frac(tion) addition."] + [Frac f.- ["frac" "-"] "Frac(tion) substraction."] + [Frac f.* ["frac" "*"] "Frac(tion) multiplication."] + [Frac f./ ["frac" "/"] "Frac(tion) division."] + [Frac f.% ["frac" "%"] "Frac(tion) remainder."] ) (do-template [ ] @@ -2191,8 +2191,8 @@ [d.min Deg d.< "Deg(ree) minimum."] [d.max Deg d.> "Deg(ree) maximum."] - [r.min Real r.< "Real minimum."] - [r.max Real r.> "Real minimum."] + [f.min Frac f.< "Frac minimum."] + [f.max Frac f.> "Frac minimum."] ) (def:''' (Bool/encode x) @@ -2252,10 +2252,10 @@ (|> value (i./ 10) Int/abs) (|> value (i.% 10) Int/abs (_lux_:! Nat) digit-to-text))))) -(def:''' (Real/encode x) +(def:''' (Frac/encode x) #Nil - (-> Real Text) - (_lux_proc ["real" "encode"] [x])) + (-> Frac Text) + (_lux_proc ["frac" "encode"] [x])) (def:''' (multiple? div n) #Nil @@ -2686,8 +2686,8 @@ [_ (#Deg value)] (_lux_proc ["io" "error"] ["Undefined behavior."]) - [_ (#Real value)] - (Real/encode value) + [_ (#Frac value)] + (Frac/encode value) [_ (#Text value)] ($_ Text/append "\"" value "\"") @@ -2916,8 +2916,8 @@ [_ (#Deg value)] (return (form$ (list (tag$ ["lux" "DegA"]) (deg$ value)))) - [_ (#Real value)] - (return (form$ (list (tag$ ["lux" "RealA"]) (real$ value)))) + [_ (#Frac value)] + (return (form$ (list (tag$ ["lux" "FracA"]) (frac$ value)))) [_ (#Text value)] (return (form$ (list (tag$ ["lux" "TextA"]) (text$ value)))) @@ -4877,8 +4877,8 @@ (-> ) (_lux_proc [n]))] - [real-to-int Real Int ["real" "to-int"]] - [int-to-real Int Real ["int" "to-real"]] + [frac-to-int Frac Int ["frac" "to-int"]] + [int-to-frac Int Frac ["int" "to-frac"]] ) (def: (find-baseline-column ast) @@ -4891,7 +4891,7 @@ [#Nat] [#Int] [#Deg] - [#Real] + [#Frac] [#Text] [#Symbol] [#Tag]) @@ -4958,8 +4958,8 @@ [int-to-nat ["int" "to-nat"] Int Nat] [nat-to-int ["nat" "to-int"] Nat Int] - [real-to-deg ["real" "to-deg"] Real Deg] - [deg-to-real ["deg" "to-real"] Deg Real] + [frac-to-deg ["frac" "to-deg"] Frac Deg] + [deg-to-frac ["deg" "to-frac"] Deg Frac] ) (def: (repeat n x) @@ -5008,7 +5008,7 @@ ([#Bool Bool/encode] [#Nat Nat/encode] [#Int Int/encode] - [#Real Real/encode] + [#Frac Frac/encode] [#Text Text/encode] [#Symbol Ident/encode] [#Tag Tag/encode]) @@ -5208,7 +5208,7 @@ (def: (place-tokens label tokens target) (-> Text (List Code) Code (Maybe (List Code))) (case target - (^or [_ (#Bool _)] [_ (#Nat _)] [_ (#Int _)] [_ (#Deg _)] [_ (#Real _)] [_ (#Text _)] [_ (#Tag _)]) + (^or [_ (#Bool _)] [_ (#Nat _)] [_ (#Int _)] [_ (#Deg _)] [_ (#Frac _)] [_ (#Text _)] [_ (#Tag _)]) (#Some (list target)) [_ (#Symbol [prefix name])] @@ -5257,7 +5257,7 @@ [(bool true) "true" [_ (#;Bool true)]] [(bool false) "false" [_ (#;Bool false)]] [(int 123) "123" [_ (#;Int 123)]] - [(real 123.0) "123.0" [_ (#;Real 123.0)]] + [(frac 123.0) "123.0" [_ (#;Frac 123.0)]] [(text "\n") "\"\\n\"" [_ (#;Text "\n")]] [(tag ["yolo" "lol"]) "#yolo;lol" [_ (#;Tag ["yolo" "lol"])]] [(symbol ["yolo" "lol"]) "yolo;lol" [_ (#;Symbol ["yolo" "lol"])]] @@ -5302,7 +5302,7 @@ ["Nat"] ["Int"] ["Deg"] - ["Real"] + ["Frac"] ["Text"]) (#Named _ type') @@ -5324,7 +5324,7 @@ ["Nat" Nat nat$] ["Int" Int int$] ["Deg" Deg deg$] - ["Real" Real real$] + ["Frac" Frac frac$] ["Text" Text text$]) _ @@ -5362,7 +5362,7 @@ )) (macro: #export (^~ tokens) - {#;doc (doc "Use global defs with simple values, such as text, int, real and bool in place of literals in patterns." + {#;doc (doc "Use global defs with simple values, such as text, int, frac 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)) diff --git a/stdlib/source/lux/control/concatenative.lux b/stdlib/source/lux/control/concatenative.lux index a0854ffcf..61a6ddbd0 100644 --- a/stdlib/source/lux/control/concatenative.lux +++ b/stdlib/source/lux/control/concatenative.lux @@ -2,7 +2,7 @@ n.+ n.- n.* n./ n.% n.= n.< n.<= n.> n.>= i.+ i.- i.* i./ i.% i.= i.< i.<= i.> i.>= d.+ d.- d.* d./ d.% d.= d.< d.<= d.> d.>= - r.+ r.- r.* r./ r.% r.= r.< r.<= r.> r.>=] + f.+ f.- f.* f./ f.% f.= f.< f.<= f.> f.>=] (lux (control ["p" parser "p/" Monad] [monad]) (data [text] @@ -98,7 +98,7 @@ (case command (^or [_ (#;Bool _)] [_ (#;Nat _)] [_ (#;Int _)] - [_ (#;Deg _)] [_ (#;Real _)] + [_ (#;Deg _)] [_ (#;Frac _)] [_ (#;Text _)] [_ (#;Tag _)] (^ [_ (#;Form (list [_ (#;Tag _)]))])) (` (;;push (~ command))) @@ -231,16 +231,16 @@ [Deg Bool d.> ;d.>] [Deg Bool d.>= ;d.>=] - [Real Real r.+ ;r.+] - [Real Real r.- ;r.-] - [Real Real r.* ;r.*] - [Real Real r./ ;r./] - [Real Real r.% ;r.%] - [Real Bool r.= ;r.=] - [Real Bool r.< ;r.<] - [Real Bool r.<= ;r.<=] - [Real Bool r.> ;r.>] - [Real Bool r.>= ;r.>=] + [Frac Frac f.+ ;f.+] + [Frac Frac f.- ;f.-] + [Frac Frac f.* ;f.*] + [Frac Frac f./ ;f./] + [Frac Frac f.% ;f.%] + [Frac Bool f.= ;f.=] + [Frac Bool f.< ;f.<] + [Frac Bool f.<= ;f.<=] + [Frac Bool f.> ;f.>] + [Frac Bool f.>= ;f.>=] ) (def: #export if diff --git a/stdlib/source/lux/data/color.lux b/stdlib/source/lux/data/color.lux index f4799726f..61ee1249a 100644 --- a/stdlib/source/lux/data/color.lux +++ b/stdlib/source/lux/data/color.lux @@ -8,18 +8,18 @@ (def: rgb Nat +256) (def: top Nat (n.dec rgb)) -(def: nat-to-real (-> Nat Real) (|>. nat-to-int int-to-real)) -(def: real-to-nat (-> Real Nat) (|>. real-to-int int-to-nat)) +(def: nat-to-frac (-> Nat Frac) (|>. nat-to-int int-to-frac)) +(def: frac-to-nat (-> Frac Nat) (|>. frac-to-int int-to-nat)) -(def: rgb-factor Real (nat-to-real top)) +(def: rgb-factor Frac (nat-to-frac top)) (def: scale-down - (-> Nat Real) - (|>. nat-to-real (r./ rgb-factor))) + (-> Nat Frac) + (|>. nat-to-frac (f./ rgb-factor))) (def: scale-up - (-> Real Nat) - (|>. (r.* rgb-factor) real-to-nat)) + (-> Frac Nat) + (|>. (f.* rgb-factor) frac-to-nat)) (opaque: #export Color {} {#red Nat @@ -46,115 +46,115 @@ ) (def: #export (to-hsl color) - (-> Color [Real Real Real]) + (-> Color [Frac Frac Frac]) (let [[red green blue] (unpack color) red (scale-down red) green (scale-down green) blue (scale-down blue) - max ($_ r.max red green blue) - min ($_ r.min red green blue) - luminance (|> (r.+ max min) (r./ 2.0))] - (if (r.= max min) + max ($_ f.max red green blue) + min ($_ f.min red green blue) + luminance (|> (f.+ max min) (f./ 2.0))] + (if (f.= max min) ## Achromatic [0.0 0.0 luminance] ## Chromatic - (let [diff (|> max (r.- min)) + (let [diff (|> max (f.- min)) saturation (|> diff - (r./ (if (r.> 0.5 luminance) - (|> 2.0 (r.- max) (r.- min)) - (|> max (r.+ min))))) - hue' (cond (r.= red max) - (|> green (r.- blue) (r./ diff) - (r.+ (if (r.< blue green) 6.0 0.0))) + (f./ (if (f.> 0.5 luminance) + (|> 2.0 (f.- max) (f.- min)) + (|> max (f.+ min))))) + hue' (cond (f.= red max) + (|> green (f.- blue) (f./ diff) + (f.+ (if (f.< blue green) 6.0 0.0))) - (r.= green max) - (|> blue (r.- red) (r./ diff) - (r.+ 2.0)) + (f.= green max) + (|> blue (f.- red) (f./ diff) + (f.+ 2.0)) - ## (r.= blue max) - (|> red (r.- green) (r./ diff) - (r.+ 4.0)))] - [(|> hue' (r./ 6.0)) + ## (f.= blue max) + (|> red (f.- green) (f./ diff) + (f.+ 4.0)))] + [(|> hue' (f./ 6.0)) saturation luminance])))) (def: (hue-to-rgb p q t) - (-> Real Real Real Real) - (let [t (cond (r.< 0.0 t) (r.+ 1.0 t) - (r.> 1.0 t) (r.- 1.0 t) + (-> Frac Frac Frac Frac) + (let [t (cond (f.< 0.0 t) (f.+ 1.0 t) + (f.> 1.0 t) (f.- 1.0 t) ## else t) - f2/3 (r./ 3.0 2.0)] - (cond (r.< (r./ 6.0 1.0) t) - (|> q (r.- p) (r.* 6.0) (r.* t) (r.+ p)) + f2/3 (f./ 3.0 2.0)] + (cond (f.< (f./ 6.0 1.0) t) + (|> q (f.- p) (f.* 6.0) (f.* t) (f.+ p)) - (r.< (r./ 2.0 1.0) t) + (f.< (f./ 2.0 1.0) t) q - (r.< f2/3 t) - (|> q (r.- p) (r.* (|> f2/3 (r.- t))) (r.* 6.0) (r.+ p)) + (f.< f2/3 t) + (|> q (f.- p) (f.* (|> f2/3 (f.- t))) (f.* 6.0) (f.+ p)) ## else p))) (def: #export (from-hsl [hue saturation luminance]) - (-> [Real Real Real] Color) - (if (r.= 0.0 saturation) + (-> [Frac Frac Frac] Color) + (if (f.= 0.0 saturation) ## Achromatic (let [intensity (scale-up luminance)] (color [intensity intensity intensity])) ## Chromatic - (let [q (if (r.< 0.5 luminance) - (|> saturation (r.+ 1.0) (r.* luminance)) - (|> luminance (r.+ saturation) (r.- (r.* saturation luminance)))) - p (|> luminance (r.* 2.0) (r.- q)) - third (|> 1.0 (r./ 3.0))] - (color [(scale-up (|> hue (r.+ third) (hue-to-rgb p q))) + (let [q (if (f.< 0.5 luminance) + (|> saturation (f.+ 1.0) (f.* luminance)) + (|> luminance (f.+ saturation) (f.- (f.* saturation luminance)))) + p (|> luminance (f.* 2.0) (f.- q)) + third (|> 1.0 (f./ 3.0))] + (color [(scale-up (|> hue (f.+ third) (hue-to-rgb p q))) (scale-up (|> hue (hue-to-rgb p q))) - (scale-up (|> hue (r.- third) (hue-to-rgb p q)))])))) + (scale-up (|> hue (f.- third) (hue-to-rgb p q)))])))) (def: #export (to-hsb color) - (-> Color [Real Real Real]) + (-> Color [Frac Frac Frac]) (let [[red green blue] (unpack color) red (scale-down red) green (scale-down green) blue (scale-down blue) - max ($_ r.max red green blue) - min ($_ r.min red green blue) + max ($_ f.max red green blue) + min ($_ f.min red green blue) brightness max - diff (|> max (r.- min)) - saturation (if (r.= 0.0 max) + diff (|> max (f.- min)) + saturation (if (f.= 0.0 max) 0.0 - (|> diff (r./ max)))] - (if (r.= max min) + (|> diff (f./ max)))] + (if (f.= max min) ## Achromatic [0.0 saturation brightness] ## Chromatic - (let [hue (cond (r.= red max) - (|> green (r.- blue) (r./ diff) - (r.+ (if (r.< blue green) 6.0 0.0))) - - (r.= green max) - (|> blue (r.- red) (r./ diff) - (r.+ 2.0)) - - ## (r.= blue max) - (|> red (r.- green) (r./ diff) - (r.+ 4.0)))] - [(|> hue (r./ 6.0)) + (let [hue (cond (f.= red max) + (|> green (f.- blue) (f./ diff) + (f.+ (if (f.< blue green) 6.0 0.0))) + + (f.= green max) + (|> blue (f.- red) (f./ diff) + (f.+ 2.0)) + + ## (f.= blue max) + (|> red (f.- green) (f./ diff) + (f.+ 4.0)))] + [(|> hue (f./ 6.0)) saturation brightness])))) (def: #export (from-hsb [hue saturation brightness]) - (-> [Real Real Real] Color) - (let [hue (|> hue (r.* 6.0)) + (-> [Frac Frac Frac] Color) + (let [hue (|> hue (f.* 6.0)) i (math;floor hue) - f (|> hue (r.- i)) - p (|> 1.0 (r.- saturation) (r.* brightness)) - q (|> 1.0 (r.- (r.* f saturation)) (r.* brightness)) - t (|> 1.0 (r.- (|> 1.0 (r.- f) (r.* saturation))) (r.* brightness)) + f (|> hue (f.- i)) + p (|> 1.0 (f.- saturation) (f.* brightness)) + q (|> 1.0 (f.- (f.* f saturation)) (f.* brightness)) + t (|> 1.0 (f.- (|> 1.0 (f.- f) (f.* saturation))) (f.* brightness)) v brightness - mod (|> i (r.% 6.0) real-to-nat) + mod (|> i (f.% 6.0) frac-to-nat) red (case mod +0 v +1 q +2 p +3 p +4 t +5 v _ (undefined)) green (case mod +0 t +1 v +2 v +3 q +4 p +5 p _ (undefined)) blue (case mod +0 p +1 p +2 t +3 v +4 v +5 q _ (undefined))] @@ -163,51 +163,51 @@ (scale-up blue)]))) (def: #export (to-cmyk color) - (-> Color [Real Real Real Real]) + (-> Color [Frac Frac Frac Frac]) (let [[red green blue] (unpack color) red (scale-down red) green (scale-down green) blue (scale-down blue) - key (|> 1.0 (r.- ($_ r.max red green blue))) - f (if (r.< 1.0 key) - (|> 1.0 (r./ (|> 1.0 (r.- key)))) + key (|> 1.0 (f.- ($_ f.max red green blue))) + f (if (f.< 1.0 key) + (|> 1.0 (f./ (|> 1.0 (f.- key)))) 0.0) - cyan (|> 1.0 (r.- red) (r.- key) (r.* f)) - magenta (|> 1.0 (r.- green) (r.- key) (r.* f)) - yellow (|> 1.0 (r.- blue) (r.- key) (r.* f))] + cyan (|> 1.0 (f.- red) (f.- key) (f.* f)) + magenta (|> 1.0 (f.- green) (f.- key) (f.* f)) + yellow (|> 1.0 (f.- blue) (f.- key) (f.* f))] [cyan magenta yellow key])) (def: #export (from-cmyk [cyan magenta yellow key]) - (-> [Real Real Real Real] Color) - (if (r.= 1.0 key) + (-> [Frac Frac Frac Frac] Color) + (if (f.= 1.0 key) (color [+0 +0 +0]) - (let [red (|> (|> 1.0 (r.- cyan)) - (r.* (|> 1.0 (r.- key)))) - green (|> (|> 1.0 (r.- magenta)) - (r.* (|> 1.0 (r.- key)))) - blue (|> (|> 1.0 (r.- yellow)) - (r.* (|> 1.0 (r.- key))))] + (let [red (|> (|> 1.0 (f.- cyan)) + (f.* (|> 1.0 (f.- key)))) + green (|> (|> 1.0 (f.- magenta)) + (f.* (|> 1.0 (f.- key)))) + blue (|> (|> 1.0 (f.- yellow)) + (f.* (|> 1.0 (f.- key))))] (color [(scale-up red) (scale-up green) (scale-up blue)])))) (def: (normalize ratio) - (-> Real Real) - (cond (r.> 1.0 ratio) - (r.% 1.0 ratio) + (-> Frac Frac) + (cond (f.> 1.0 ratio) + (f.% 1.0 ratio) - (r.< 0.0 ratio) - (|> 1.0 (r.+ (r.% 1.0 ratio))) + (f.< 0.0 ratio) + (|> 1.0 (f.+ (f.% 1.0 ratio))) ## else ratio)) (def: #export (interpolate ratio end start) - (-> Real Color Color Color) + (-> Frac Color Color Color) (let [dS (normalize ratio) - dE (|> 1.0 (r.- dS)) + dE (|> 1.0 (f.- dS)) interpolate' (: (-> Nat Nat Nat) (function [end start] - (real-to-nat (r.+ (r.* dE (nat-to-real end)) - (r.* dS (nat-to-real start)))))) + (frac-to-nat (f.+ (f.* dE (nat-to-frac end)) + (f.* dS (nat-to-frac start)))))) [redS greenS blueS] (unpack start) [redE greenE blueE] (unpack end)] (color [(interpolate' redE redS) @@ -219,7 +219,7 @@ (do-template [ ] [(def: #export ( ratio color) - (-> Real Color Color) + (-> Frac Color Color) (interpolate ratio color))] [darker black] @@ -236,16 +236,16 @@ (do-template [ ] [(def: #export ( ratio color) - (-> Real Color Color) + (-> Frac Color Color) (let [[hue saturation luminance] (to-hsl color)] (from-hsl [hue (|> saturation - (r.* (|> 1.0 ( (normalize ratio)))) - (r.min 1.0)) + (f.* (|> 1.0 ( (normalize ratio)))) + (f.min 1.0)) luminance])))] - [saturate r.+] - [de-saturate r.-] + [saturate f.+] + [de-saturate f.-] ) (def: #export (gray-scale color) @@ -258,12 +258,12 @@ (-> Color [Color Color Color]) (let [[hue saturation luminance] (to-hsl color)] [color - (from-hsl [(|> hue (r.+ <1>) normalize) saturation luminance]) - (from-hsl [(|> hue (r.+ <2>) normalize) saturation luminance])]))] + (from-hsl [(|> hue (f.+ <1>) normalize) saturation luminance]) + (from-hsl [(|> hue (f.+ <2>) normalize) saturation luminance])]))] - [triad (|> 1.0 (r./ 3.0)) (|> 2.0 (r./ 3.0))] - [clash (|> 1.0 (r./ 4.0)) (|> 3.0 (r./ 4.0))] - [split-complement (|> 1.0 (r./ 5.0)) (|> 3.0 (r./ 5.0))] + [triad (|> 1.0 (f./ 3.0)) (|> 2.0 (f./ 3.0))] + [clash (|> 1.0 (f./ 4.0)) (|> 3.0 (f./ 4.0))] + [split-complement (|> 1.0 (f./ 5.0)) (|> 3.0 (f./ 5.0))] ) (do-template [ <1> <2> <3>] @@ -271,22 +271,22 @@ (-> Color [Color Color Color Color]) (let [[hue saturation luminance] (to-hsl color)] [color - (from-hsl [(|> hue (r.+ <1>) normalize) saturation luminance]) - (from-hsl [(|> hue (r.+ <2>) normalize) saturation luminance]) - (from-hsl [(|> hue (r.+ <3>) normalize) saturation luminance])]))] + (from-hsl [(|> hue (f.+ <1>) normalize) saturation luminance]) + (from-hsl [(|> hue (f.+ <2>) normalize) saturation luminance]) + (from-hsl [(|> hue (f.+ <3>) normalize) saturation luminance])]))] - [square (|> 1.0 (r./ 4.0)) (|> 2.0 (r./ 4.0)) (|> 3.0 (r./ 4.0))] - [tetradic (|> 2.0 (r./ 12.0)) (|> 6.0 (r./ 12.0)) (|> 8.0 (r./ 12.0))] + [square (|> 1.0 (f./ 4.0)) (|> 2.0 (f./ 4.0)) (|> 3.0 (f./ 4.0))] + [tetradic (|> 2.0 (f./ 12.0)) (|> 6.0 (f./ 12.0)) (|> 8.0 (f./ 12.0))] ) (def: #export (analogous results slice color) - (-> Nat Real Color (List Color)) + (-> Nat Frac Color (List Color)) (if (n.= +0 results) (list) (let [[hue saturation luminance] (to-hsl color) slice (normalize slice)] (L/map (function [idx] - (from-hsl [(|> idx nat-to-real (r.* slice) (r.+ hue) normalize) + (from-hsl [(|> idx nat-to-frac (f.* slice) (f.+ hue) normalize) saturation luminance])) (list;n.range +0 (n.dec results)))))) @@ -296,11 +296,11 @@ (if (n.= +0 results) (list) (let [[hue saturation brightness] (to-hsb color) - slice (|> 1.0 (r./ (nat-to-real results)))] + slice (|> 1.0 (f./ (nat-to-frac results)))] (|> (list;n.range +0 (n.dec results)) - (L/map (|>. nat-to-real - (r.* slice) - (r.+ brightness) + (L/map (|>. nat-to-frac + (f.* slice) + (f.+ brightness) normalize [hue saturation] from-hsb)))))) diff --git a/stdlib/source/lux/data/format/css.lux b/stdlib/source/lux/data/format/css.lux index a5adfb928..e4ca7e3cd 100644 --- a/stdlib/source/lux/data/format/css.lux +++ b/stdlib/source/lux/data/format/css.lux @@ -74,7 +74,7 @@ (do-template [ ] [(def: #export ( value) - (-> Real Value) + (-> Frac Value) (format (%r value) ))] [em "em"] diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 379e3b23b..847b5fa0f 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -11,7 +11,7 @@ (data [bool] [text "text/" Eq Monoid] (text ["l" lexer]) - [number "real/" Codec "nat/" Codec] + [number "frac/" Codec "nat/" Codec] maybe ["R" result] [sum] @@ -32,7 +32,7 @@ [Null Unit] [Boolean Bool] - [Number Real] + [Number Frac] [String Text] ) @@ -72,7 +72,7 @@ [_ ( value)] (wrap (list (` (: JSON ( (~ ( value)))))))) ([#;Bool code;bool #Boolean] - [#;Real code;real #Number] + [#;Frac code;frac #Number] [#;Text code;text #String]) [_ (#;Tag ["" "null"])] @@ -190,7 +190,7 @@ [( x') ( y')] (:: = x' y')) ([#Boolean bool;Eq] - [#Number number;Eq] + [#Number number;Eq] [#String text;Eq]) [(#Array xs) (#Array ys)] diff --git a/stdlib/source/lux/data/format/json/codec.lux b/stdlib/source/lux/data/format/json/codec.lux index 8a50757bf..d6d888c0e 100644 --- a/stdlib/source/lux/data/format/json/codec.lux +++ b/stdlib/source/lux/data/format/json/codec.lux @@ -12,7 +12,7 @@ [bit] [text "text/" Eq Monoid] (text ["l" lexer]) - [number "real/" Codec "nat/" Codec] + [number "frac/" Codec "nat/" Codec] maybe ["R" result] [sum] @@ -38,7 +38,7 @@ [(def: (-> Text) )] [show-boolean ..;Boolean (:: bool;Codec encode)] - [show-number ..;Number (:: number;Codec encode)] + [show-number ..;Number (:: number;Codec encode)] [show-string ..;String text;encode]) (def: (show-array show-json elems) @@ -114,7 +114,7 @@ signed?' (l;this? "-") offset (l;many l;decimal)] (wrap ($_ text/append mark (if signed?' "-" "") offset))))] - (case (real/decode ($_ text/append (if signed? "-" "") digits "." decimals exp)) + (case (frac/decode ($_ text/append (if signed? "-" "") digits "." decimals exp)) (#R;Error message) (p;fail message) @@ -185,8 +185,8 @@ L/map) (def: tag - (-> Nat Real) - (|>. nat-to-int int-to-real)) + (-> Nat Frac) + (|>. nat-to-int int-to-frac)) (def: #hidden (rec-encode non-rec) (All [a] (-> (-> (-> a JSON) @@ -202,15 +202,15 @@ (def: (encode input) (let [high (|> input (bit;and high-mask) (bit;unsigned-shift-right +32)) low (bit;and low-mask input)] - (..;array (vector (|> high nat-to-int int-to-real #..;Number) - (|> low nat-to-int int-to-real #..;Number))))) + (..;array (vector (|> high nat-to-int int-to-frac #..;Number) + (|> low nat-to-int int-to-frac #..;Number))))) (def: (decode input) (<| (../reader;run input) (do p;Monad [high ../reader;number low ../reader;number]) - (wrap (n.+ (|> high real-to-int int-to-nat (bit;shift-left +32)) - (|> low real-to-int int-to-nat)))))) + (wrap (n.+ (|> high frac-to-int int-to-nat (bit;shift-left +32)) + (|> low frac-to-int int-to-nat)))))) (struct: #hidden _ (Codec JSON Int) (def: encode (|>. int-to-nat (:: Codec encode))) @@ -229,7 +229,7 @@ [Bool poly;bool ..;boolean] [Nat poly;nat (:: ;;Codec (~' encode))] [Int poly;int (:: ;;Codec (~' encode))] - [Real poly;real ..;number] + [Frac poly;frac ..;number] [Text poly;text ..;string])