diff options
author | Eduardo Julian | 2021-08-08 17:56:15 -0400 |
---|---|---|
committer | Eduardo Julian | 2021-08-08 17:56:15 -0400 |
commit | f621a133e6e0a516c0586270fea8eaffb4829d82 (patch) | |
tree | 399396ee2f6a10df10cea9b78c51c76679b70e59 /stdlib/source/library/lux/math | |
parent | 17e7566be51df5e428a6b10e6469201a8a9468da (diff) |
No more #export magic syntax.
Diffstat (limited to '')
18 files changed, 327 insertions, 325 deletions
diff --git a/stdlib/source/library/lux/math.lux b/stdlib/source/library/lux/math.lux index 65c3c01d0..8a7c9feff 100644 --- a/stdlib/source/library/lux/math.lux +++ b/stdlib/source/library/lux/math.lux @@ -8,18 +8,20 @@ ["i" int]]]]]) (template [<name> <value> <doc>] - [(def: #export <name> + [(def: .public <name> {#.doc <doc>} <value>)] [e +2.7182818284590452354 "The base of the natural logarithm."] + ## ["π is wrong!" by Bob Palais](https://www.math.utah.edu/~palais/pi.html) [pi +3.14159265358979323846 "The ratio of a circle's circumference to its diameter."] + ## [The Tau Manifesto](https://tauday.com/tau-manifesto) [tau +6.28318530717958647692 "The ratio of a circle's circumference to its radius."] ) (for {@.old (as_is (template [<name> <method>] - [(def: #export (<name> input) + [(def: .public (<name> input) (-> Frac Frac) (<method> input))] @@ -40,24 +42,24 @@ [root/2 "jvm invokestatic:java.lang.Math:sqrt:double"] [root/3 "jvm invokestatic:java.lang.Math:cbrt:double"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) ("jvm invokestatic:java.lang.Math:pow:double,double" subject param))) @.jvm (as_is (template: (!double value) - (|> value - (:as (primitive "java.lang.Double")) - "jvm object cast")) + [(|> value + (:as (primitive "java.lang.Double")) + "jvm object cast")]) (template: (!frac value) - (|> value - "jvm object cast" - (: (primitive "java.lang.Double")) - (:as Frac))) + [(|> value + "jvm object cast" + (: (primitive "java.lang.Double")) + (:as Frac))]) (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> !double ["D"] @@ -82,7 +84,7 @@ [root/3 "cbrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (|> ("jvm member invoke static" [] "java.lang.Math" "pow" [] ["D" (!double subject)] ["D" (!double param)]) @@ -90,7 +92,7 @@ @.js (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("js apply" ("js constant" <method>)) (:as Frac)))] @@ -113,13 +115,13 @@ [root/3 "Math.cbrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (:as Frac ("js apply" ("js constant" "Math.pow") subject param)))) @.python (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("python object do" <method> ("python import" "math")) (:as Frac)))] @@ -141,17 +143,17 @@ [root/2 "sqrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (:as Frac ("python object do" "pow" ("python import" "math") subject param))) - (def: #export root/3 + (def: .public root/3 (-> Frac Frac) (..pow ("lux f64 /" +3.0 +1.0)))) @.lua (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("lua apply" ("lua constant" <method>)) (:as Frac)))] @@ -173,17 +175,17 @@ [root/2 "math.sqrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) ("lua power" param subject)) - (def: #export root/3 + (def: .public root/3 (-> Frac Frac) (..pow ("lux f64 /" +3.0 +1.0)))) @.ruby (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("ruby apply" ("ruby constant" <method>)) (:as Frac)))] @@ -204,7 +206,7 @@ ) (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("ruby object do" <method>) (:as Int) @@ -214,13 +216,13 @@ [floor "floor"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (:as Frac ("ruby object do" "**" subject param)))) @.php (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("php apply" ("php constant" <method>)) (:as Frac)))] @@ -242,17 +244,17 @@ [root/2 "sqrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (:as Frac ("php apply" ("php constant" "pow") subject param))) - (def: #export root/3 + (def: .public root/3 (-> Frac Frac) (..pow ("lux f64 /" +3.0 +1.0)))) @.scheme (as_is (template [<name> <method>] - [(def: #export <name> + [(def: .public <name> (-> Frac Frac) (|>> ("scheme apply" ("scheme constant" <method>)) (:as Frac)))] @@ -274,16 +276,16 @@ [root/2 "sqrt"] ) - (def: #export (pow param subject) + (def: .public (pow param subject) (-> Frac Frac Frac) (:as Frac ("scheme apply" ("scheme constant" "expt") subject param))) - (def: #export root/3 + (def: .public root/3 (-> Frac Frac) (..pow ("lux f64 /" +3.0 +1.0)))) }) -(def: #export (round input) +(def: .public (round input) (-> Frac Frac) (let [floored (floor input) diff ("lux f64 -" floored input)] @@ -296,7 +298,7 @@ ## else floored))) -(def: #export (atan/2 x y) +(def: .public (atan/2 x y) (-> Frac Frac Frac) (cond ("lux f64 <" x +0.0) (..atan ("lux f64 /" x y)) @@ -317,13 +319,13 @@ ## ("lux f64 =" +0.0 y) ("lux f64 /" +0.0 +0.0)))) -(def: #export (log' base input) +(def: .public (log' base input) (-> Frac Frac Frac) ("lux f64 /" (..log base) (..log input))) -(def: #export (factorial n) +(def: .public (factorial n) (-> Nat Nat) (loop [acc 1 n n] @@ -331,7 +333,7 @@ acc (recur (n.* n acc) (dec n))))) -(def: #export (hypotenuse catA catB) +(def: .public (hypotenuse catA catB) (-> Frac Frac Frac) (..pow +0.5 ("lux f64 +" (..pow +2.0 catA) @@ -340,11 +342,11 @@ ## Hyperbolic functions ## https://en.wikipedia.org/wiki/Hyperbolic_function#Definitions (template [<name> <comp> <inverse>] - [(def: #export (<name> x) + [(def: .public (<name> x) (-> Frac Frac) (|> (..exp x) (<comp> (..exp ("lux f64 *" -1.0 x))) ("lux f64 /" +2.0))) - (def: #export (<inverse> x) + (def: .public (<inverse> x) (-> Frac Frac) (|> +2.0 ("lux f64 /" (|> (..exp x) (<comp> (..exp ("lux f64 *" -1.0 x)))))))] @@ -353,7 +355,7 @@ ) (template [<name> <top> <bottom>] - [(def: #export (<name> x) + [(def: .public (<name> x) (-> Frac Frac) (let [e+ (exp x) e- (exp ("lux f64 *" -1.0 x)) @@ -367,7 +369,7 @@ ## https://en.wikipedia.org/wiki/Inverse_hyperbolic_functions#Definitions_in_terms_of_logarithms (template [<name> <comp>] - [(def: #export (<name> x) + [(def: .public (<name> x) (-> Frac Frac) (|> x (pow +2.0) (<comp> +1.0) (pow +0.5) ("lux f64 +" x) log))] @@ -376,7 +378,7 @@ ) (template [<name> <base> <diff>] - [(def: #export (<name> x) + [(def: .public (<name> x) (-> Frac Frac) (let [x+ (|> <base> ("lux f64 +" <diff>)) x- (|> <base> ("lux f64 -" <diff>))] @@ -387,7 +389,7 @@ ) (template [<name> <op>] - [(def: #export (<name> x) + [(def: .public (<name> x) (-> Frac Frac) (let [x^2 (|> x (pow +2.0))] (|> +1.0 (<op> x^2) (pow +0.5) ("lux f64 +" +1.0) ("lux f64 /" x) log)))] diff --git a/stdlib/source/library/lux/math/infix.lux b/stdlib/source/library/lux/math/infix.lux index 4b1a1ef8b..55653989a 100644 --- a/stdlib/source/library/lux/math/infix.lux +++ b/stdlib/source/library/lux/math/infix.lux @@ -80,7 +80,7 @@ (#Binary left op right) (` ((~ op) (~ (prefix right)) (~ (prefix left)))))) -(syntax: #export (infix {expr infix^}) +(syntax: .public (infix {expr infix^}) {#.doc (doc "Infix math syntax." (infix [x i.* +10]) (infix [[x i.+ y] i.* [x i.- y]]) diff --git a/stdlib/source/library/lux/math/logic/continuous.lux b/stdlib/source/library/lux/math/logic/continuous.lux index e68527938..691890917 100644 --- a/stdlib/source/library/lux/math/logic/continuous.lux +++ b/stdlib/source/library/lux/math/logic/continuous.lux @@ -11,15 +11,15 @@ [number ["/" rev ("#\." interval)]]]]]) -(def: #export false Rev /\bottom) -(def: #export true Rev /\top) +(def: .public false Rev /\bottom) +(def: .public true Rev /\top) (template [<name> <chooser> <monoid> <identity>] - [(def: #export <name> + [(def: .public <name> (-> Rev Rev Rev) <chooser>) - (implementation: #export <monoid> + (implementation: .public <monoid> (Monoid Rev) (def: identity <identity>) @@ -29,16 +29,16 @@ [and /.min conjunction ..true] ) -(def: #export (not input) +(def: .public (not input) (-> Rev Rev) (/.- input ..true)) -(def: #export (implies consequent antecedent) +(def: .public (implies consequent antecedent) (-> Rev Rev Rev) (or (not antecedent) consequent)) -(def: #export (= left right) +(def: .public (= left right) (-> Rev Rev Rev) (and (or (not left) right) (or left (not right)))) diff --git a/stdlib/source/library/lux/math/logic/fuzzy.lux b/stdlib/source/library/lux/math/logic/fuzzy.lux index a449f1ca6..d36b7cfd2 100644 --- a/stdlib/source/library/lux/math/logic/fuzzy.lux +++ b/stdlib/source/library/lux/math/logic/fuzzy.lux @@ -17,18 +17,18 @@ ["." // #_ ["#" continuous]]) -(type: #export (Fuzzy a) +(type: .public (Fuzzy a) {#.doc (doc "A fuzzy set.")} (-> a Rev)) -(implementation: #export functor +(implementation: .public functor (contravariant.Functor Fuzzy) (def: (map f fb) (|>> f fb))) (template [<name> <verdict>] - [(def: #export <name> + [(def: .public <name> Fuzzy (function (_ _) <verdict>))] @@ -37,12 +37,12 @@ [full //.true] ) -(def: #export (membership set elem) +(def: .public (membership set elem) (All [a] (-> (Fuzzy a) a Rev)) (set elem)) (template [<set_composition> <membership_composition>] - [(def: #export (<set_composition> left right) + [(def: .public (<set_composition> left right) (All [a] (-> (Fuzzy a) (Fuzzy a) (Fuzzy a))) (function (_ elem) (<membership_composition> (left elem) @@ -52,27 +52,27 @@ [intersection //.and] ) -(def: #export (complement set) +(def: .public (complement set) (All [a] (-> (Fuzzy a) (Fuzzy a))) (|>> set //.not)) -(def: #export (difference sub base) +(def: .public (difference sub base) (All [a] (-> (Fuzzy a) (Fuzzy a) (Fuzzy a))) (..intersection (..complement sub) base)) -(def: #export (of_predicate predicate) +(def: .public (of_predicate predicate) (All [a] (-> (Predicate a) (Fuzzy a))) (function (_ elem) (if (predicate elem) //.true //.false))) -(def: #export (predicate treshold set) +(def: .public (predicate treshold set) (All [a] (-> Rev (Fuzzy a) (Predicate a))) (function (_ elem) (/.> treshold (set elem)))) -(def: #export of_set +(def: .public of_set (All [a] (-> (Set a) (Fuzzy a))) (|>> set.member? ..of_predicate)) @@ -97,18 +97,18 @@ (-> Rev Rev (Fuzzy Rev)) (..complement (..ascending from to))) -(def: #export (gradient from to) +(def: .public (gradient from to) (-> Rev Rev (Fuzzy Rev)) (if (/.< to from) (..ascending from to) (..descending from to))) (template: (!sort_2 <low> <high>) - (if (/.> <low> <high>) - [<low> <high>] - [<high> <low>])) + [(if (/.> <low> <high>) + [<low> <high>] + [<high> <low>])]) -(def: #export (triangle bottom middle top) +(def: .public (triangle bottom middle top) (-> Rev Rev Rev (Fuzzy Rev)) (let [[low_0 high_0] (!sort_2 bottom middle) [bottom' high_1] (!sort_2 low_0 top) @@ -116,7 +116,7 @@ (..intersection (..ascending bottom' middle') (..descending middle' top')))) -(def: #export (trapezoid bottom middle_bottom middle_top top) +(def: .public (trapezoid bottom middle_bottom middle_top top) (-> Rev Rev Rev Rev (Fuzzy Rev)) (let [[low_0 high_0] (!sort_2 bottom middle_bottom) [low_1 high_1] (!sort_2 middle_top top) @@ -126,7 +126,7 @@ (..intersection (..ascending bottom' middle_bottom') (..descending middle_top' top')))) -(def: #export (cut treshold set) +(def: .public (cut treshold set) (All [a] (-> Rev (Fuzzy a) (Fuzzy a))) (function (_ elem) (let [membership (set elem)] diff --git a/stdlib/source/library/lux/math/modular.lux b/stdlib/source/library/lux/math/modular.lux index bc92467b1..7bfbf34a0 100644 --- a/stdlib/source/library/lux/math/modular.lux +++ b/stdlib/source/library/lux/math/modular.lux @@ -27,19 +27,19 @@ ["." // #_ ["#" modulus (#+ Modulus)]]) -(abstract: #export (Mod m) +(abstract: .public (Mod m) + {#.doc "A number under a modulus."} + {#modulus (Modulus m) #value Int} - {#.doc "A number under a modulus."} - - (def: #export (modular modulus value) + (def: .public (modular modulus value) (All [%] (-> (Modulus %) Int (Mod %))) (:abstraction {#modulus modulus #value (i.mod (//.divisor modulus) value)})) (template [<name> <type> <side>] - [(def: #export <name> + [(def: .public <name> (All [%] (-> (Mod %) <type>)) (|>> :representation <side>))] @@ -47,7 +47,7 @@ [value Int product.right] ) - (exception: #export [%] (incorrect_modulus {modulus (Modulus %)} + (exception: .public [%] (incorrect_modulus {modulus (Modulus %)} {parsed Int}) (exception.report ["Expected" (i\encode (//.divisor modulus))] @@ -61,7 +61,7 @@ (<>.codec i.decimal (<text>.and (<text>.one_of "-+") (<text>.many <text>.decimal)))) - (implementation: #export (codec expected) + (implementation: .public (codec expected) (All [%] (-> (Modulus %) (Codec Text (Mod %)))) (def: (encode modular) @@ -80,7 +80,7 @@ (in (..modular expected value)))))) (template [<name> <op>] - [(def: #export (<name> reference subject) + [(def: .public (<name> reference subject) (All [%] (-> (Mod %) (Mod %) Bit)) (let [[_ reference] (:representation reference) [_ subject] (:representation subject)] @@ -93,19 +93,19 @@ [>= i.>=] ) - (implementation: #export equivalence + (implementation: .public equivalence (All [%] (Equivalence (Mod %))) (def: = ..=)) - (implementation: #export order + (implementation: .public order (All [%] (Order (Mod %))) (def: &equivalence ..equivalence) (def: < ..<)) (template [<name> <op>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) (All [%] (-> (Mod %) (Mod %) (Mod %))) (let [[modulus param] (:representation param) [_ subject] (:representation subject)] @@ -120,7 +120,7 @@ ) (template [<composition> <identity> <monoid>] - [(implementation: #export (<monoid> modulus) + [(implementation: .public (<monoid> modulus) (All [%] (-> (Modulus %) (Monoid (Mod %)))) (def: identity @@ -132,7 +132,7 @@ [..* +1 multiplication] ) - (def: #export (inverse modular) + (def: .public (inverse modular) (All [%] (-> (Mod %) (Maybe (Mod %)))) (let [[modulus value] (:representation modular) [[vk mk] gcd] (i.extended_gcd value (//.divisor modulus))] @@ -141,13 +141,13 @@ _ #.None))) ) -(exception: #export [r% s%] (moduli_are_not_equal {reference (Modulus r%)} +(exception: .public [r% s%] (moduli_are_not_equal {reference (Modulus r%)} {subject (Modulus s%)}) (exception.report ["Reference" (i\encode (//.divisor reference))] ["Subject" (i\encode (//.divisor subject))])) -(def: #export (adapter reference subject) +(def: .public (adapter reference subject) (All [r% s%] (-> (Modulus r%) (Modulus s%) (Try (-> (Mod s%) (Mod r%))))) diff --git a/stdlib/source/library/lux/math/modulus.lux b/stdlib/source/library/lux/math/modulus.lux index 05a0ef26d..72f5d583e 100644 --- a/stdlib/source/library/lux/math/modulus.lux +++ b/stdlib/source/library/lux/math/modulus.lux @@ -18,30 +18,30 @@ [type abstract]]]) -(exception: #export zero_cannot_be_a_modulus) - -(abstract: #export (Modulus %) - Int +(exception: .public zero_cannot_be_a_modulus) +(abstract: .public (Modulus %) {#.doc (doc "A number used as a modulus in modular arithmetic." "It cannot be 0.")} - (def: #export (modulus value) + Int + + (def: .public (modulus value) (Ex [%] (-> Int (Try (Modulus %)))) (if (i.= +0 value) (exception.except ..zero_cannot_be_a_modulus []) (#try.Success (:abstraction value)))) - (def: #export divisor + (def: .public divisor (All [%] (-> (Modulus %) Int)) (|>> :representation)) - (def: #export (= reference subject) + (def: .public (= reference subject) (All [%r %s] (-> (Modulus %r) (Modulus %s) Bit)) (i.= (:representation reference) (:representation subject))) - (def: #export (congruent? modulus reference subject) + (def: .public (congruent? modulus reference subject) (All [%] (-> (Modulus %) Int Int Bit)) (|> subject (i.- reference) @@ -49,7 +49,7 @@ (i.= +0))) ) -(syntax: #export (literal {divisor <code>.int}) +(syntax: .public (literal {divisor <code>.int}) {#.doc (doc "Success!" (literal 123) diff --git a/stdlib/source/library/lux/math/number.lux b/stdlib/source/library/lux/math/number.lux index 288afd703..d1e8144ab 100644 --- a/stdlib/source/library/lux/math/number.lux +++ b/stdlib/source/library/lux/math/number.lux @@ -46,7 +46,7 @@ (text.replace_all ..separator "")) (template [<macro> <nat> <int> <rev> <frac> <error> <doc>] - [(macro: #export (<macro> tokens state) + [(macro: .public (<macro> tokens state) {#.doc <doc>} (case tokens (#.Item [meta (#.Text repr')] #.End) diff --git a/stdlib/source/library/lux/math/number/complex.lux b/stdlib/source/library/lux/math/number/complex.lux index de73592f0..63df9b5ae 100644 --- a/stdlib/source/library/lux/math/number/complex.lux +++ b/stdlib/source/library/lux/math/number/complex.lux @@ -23,12 +23,12 @@ ["f" frac] ["." int]]]]]) -(type: #export Complex +(type: .public Complex {#.doc (doc "A complex number.")} {#real Frac #imaginary Frac}) -(syntax: #export (complex real {?imaginary (<>.maybe <code>.any)}) +(syntax: .public (complex real {?imaginary (<>.maybe <code>.any)}) {#.doc (doc "Complex literals." (complex real imaginary) "The imaginary part can be omitted if it's +0.0." @@ -36,23 +36,23 @@ (in (list (` {#..real (~ real) #..imaginary (~ (maybe.else (' +0.0) ?imaginary))})))) -(def: #export i +(def: .public i (..complex +0.0 +1.0)) -(def: #export +one +(def: .public +one (..complex +1.0 +0.0)) -(def: #export -one +(def: .public -one (..complex -1.0 +0.0)) -(def: #export zero +(def: .public zero (..complex +0.0 +0.0)) -(def: #export (not_a_number? complex) +(def: .public (not_a_number? complex) (or (f.not_a_number? (get@ #real complex)) (f.not_a_number? (get@ #imaginary complex)))) -(def: #export (= param input) +(def: .public (= param input) (-> Complex Complex Bit) (and (f.= (get@ #real param) (get@ #real input)) @@ -60,7 +60,7 @@ (get@ #imaginary input)))) (template [<name> <op>] - [(def: #export (<name> param input) + [(def: .public (<name> param input) (-> Complex Complex Complex) {#real (<op> (get@ #real param) (get@ #real input)) @@ -71,13 +71,13 @@ [- f.-] ) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Complex) (def: = ..=)) (template [<name> <transform>] - [(def: #export <name> + [(def: .public <name> (-> Complex Complex) (|>> (update@ #real <transform>) (update@ #imaginary <transform>)))] @@ -86,18 +86,18 @@ [signum f.signum] ) -(def: #export conjugate +(def: .public conjugate (-> Complex Complex) (update@ #imaginary f.opposite)) -(def: #export (*' param input) +(def: .public (*' param input) (-> Frac Complex Complex) {#real (f.* param (get@ #real input)) #imaginary (f.* param (get@ #imaginary input))}) -(def: #export (* param input) +(def: .public (* param input) (-> Complex Complex Complex) {#real (f.- (f.* (get@ #imaginary param) (get@ #imaginary input)) @@ -108,7 +108,7 @@ (f.* (get@ #imaginary param) (get@ #real input)))}) -(def: #export (/ param input) +(def: .public (/ param input) (-> Complex Complex Complex) (let [(^slots [#real #imaginary]) param] (if (f.< (f.abs imaginary) @@ -122,13 +122,13 @@ {#real (|> (get@ #imaginary input) (f.* quot) (f.+ (get@ #real input)) (f./ denom)) #imaginary (|> (get@ #imaginary input) (f.- (f.* quot (get@ #real input))) (f./ denom))})))) -(def: #export (/' param subject) +(def: .public (/' param subject) (-> Frac Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (f./ param real) #imaginary (f./ param imaginary)})) -(def: #export (% param input) +(def: .public (% param input) (-> Complex Complex Complex) (let [scaled (/ param input) quotient (|> scaled @@ -137,7 +137,7 @@ (- (* quotient param) input))) -(def: #export (cos subject) +(def: .public (cos subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (f.* (math.cosh imaginary) @@ -145,7 +145,7 @@ #imaginary (f.opposite (f.* (math.sinh imaginary) (math.sin real)))})) -(def: #export (cosh subject) +(def: .public (cosh subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (f.* (math.cos imaginary) @@ -153,7 +153,7 @@ #imaginary (f.* (math.sin imaginary) (math.sinh real))})) -(def: #export (sin subject) +(def: .public (sin subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (f.* (math.cosh imaginary) @@ -161,7 +161,7 @@ #imaginary (f.* (math.sinh imaginary) (math.cos real))})) -(def: #export (sinh subject) +(def: .public (sinh subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (f.* (math.cos imaginary) @@ -169,7 +169,7 @@ #imaginary (f.* (math.sin imaginary) (math.cosh real))})) -(def: #export (tan subject) +(def: .public (tan subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject r2 (f.* +2.0 real) @@ -178,7 +178,7 @@ {#real (f./ d (math.sin r2)) #imaginary (f./ d (math.sinh i2))})) -(def: #export (tanh subject) +(def: .public (tanh subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject r2 (f.* +2.0 real) @@ -187,7 +187,7 @@ {#real (f./ d (math.sinh r2)) #imaginary (f./ d (math.sin i2))})) -(def: #export (abs subject) +(def: .public (abs subject) (-> Complex Frac) (let [(^slots [#real #imaginary]) subject] (if (f.< (f.abs imaginary) @@ -203,21 +203,21 @@ (f.* (math.pow +0.5 (f.+ +1.0 (f.* q q))) (f.abs real))))))) -(def: #export (exp subject) +(def: .public (exp subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject r_exp (math.exp real)] {#real (f.* r_exp (math.cos imaginary)) #imaginary (f.* r_exp (math.sin imaginary))})) -(def: #export (log subject) +(def: .public (log subject) (-> Complex Complex) (let [(^slots [#real #imaginary]) subject] {#real (|> subject ..abs math.log) #imaginary (math.atan/2 real imaginary)})) (template [<name> <type> <op>] - [(def: #export (<name> param input) + [(def: .public (<name> param input) (-> <type> Complex Complex) (|> input log (<op> param) exp))] @@ -229,7 +229,7 @@ (-> Frac Frac Frac) (f.* (f.signum sign) magnitude)) -(def: #export (root/2 input) +(def: .public (root/2 input) (-> Complex Complex) (let [(^slots [#real #imaginary]) input t (|> input ..abs (f.+ (f.abs real)) (f./ +2.0) (math.pow +0.5))] @@ -245,7 +245,7 @@ (-> Complex Complex) (|> (complex +1.0) (- (* input input)) ..root/2)) -(def: #export (reciprocal (^slots [#real #imaginary])) +(def: .public (reciprocal (^slots [#real #imaginary])) (-> Complex Complex) (if (f.< (f.abs imaginary) (f.abs real)) @@ -260,14 +260,14 @@ {#real scale #imaginary (|> scale f.opposite (f.* q))}))) -(def: #export (acos input) +(def: .public (acos input) (-> Complex Complex) (|> input (..+ (|> input ..root/2-1z (..* ..i))) ..log (..* (..opposite ..i)))) -(def: #export (asin input) +(def: .public (asin input) (-> Complex Complex) (|> input ..root/2-1z @@ -275,7 +275,7 @@ ..log (..* (..opposite ..i)))) -(def: #export (atan input) +(def: .public (atan input) (-> Complex Complex) (|> input (..+ ..i) @@ -283,11 +283,11 @@ ..log (..* (../ (..complex +2.0) ..i)))) -(def: #export (argument (^slots [#real #imaginary])) +(def: .public (argument (^slots [#real #imaginary])) (-> Complex Frac) (math.atan/2 real imaginary)) -(def: #export (roots nth input) +(def: .public (roots nth input) (-> Nat Complex (List Complex)) (if (n.= 0 nth) (list) @@ -307,7 +307,7 @@ {#real real #imaginary imaginary}))))))) -(def: #export (approximately? margin_of_error standard value) +(def: .public (approximately? margin_of_error standard value) (-> Frac Complex Complex Bit) (and (f.approximately? margin_of_error (get@ #..real standard) diff --git a/stdlib/source/library/lux/math/number/frac.lux b/stdlib/source/library/lux/math/number/frac.lux index c602db1c5..729d9b5b7 100644 --- a/stdlib/source/library/lux/math/number/frac.lux +++ b/stdlib/source/library/lux/math/number/frac.lux @@ -22,35 +22,35 @@ ["#." rev] ["/#" //]]) -(def: #export (= reference sample) +(def: .public (= reference sample) {#.doc "Frac(tion) equivalence."} (-> Frac Frac Bit) ("lux f64 =" reference sample)) -(def: #export (< reference sample) +(def: .public (< reference sample) {#.doc "Frac(tion) less-than."} (-> Frac Frac Bit) ("lux f64 <" reference sample)) -(def: #export (<= reference sample) +(def: .public (<= reference sample) {#.doc "Frac(tion) less-than or equal."} (-> Frac Frac Bit) (or ("lux f64 <" reference sample) ("lux f64 =" reference sample))) -(def: #export (> reference sample) +(def: .public (> reference sample) {#.doc "Frac(tion) greater-than."} (-> Frac Frac Bit) ("lux f64 <" sample reference)) -(def: #export (>= reference sample) +(def: .public (>= reference sample) {#.doc "Frac(tion) greater-than or equal."} (-> Frac Frac Bit) (or ("lux f64 <" sample reference) ("lux f64 =" sample reference))) (template [<comparison> <name>] - [(def: #export <name> + [(def: .public <name> (Predicate Frac) (<comparison> +0.0))] @@ -60,7 +60,7 @@ ) (template [<name> <op> <doc>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) {#.doc <doc>} (-> Frac Frac Frac) (<op> param subject))] @@ -72,22 +72,22 @@ [% "lux f64 %" "Frac(tion) remainder."] ) -(def: #export (/% param subject) +(def: .public (/% param subject) (-> Frac Frac [Frac Frac]) [(../ param subject) (..% param subject)]) -(def: #export opposite +(def: .public opposite (-> Frac Frac) (..* -1.0)) -(def: #export (abs x) +(def: .public (abs x) (-> Frac Frac) (if (..< +0.0 x) (..* -1.0 x) x)) -(def: #export (signum x) +(def: .public (signum x) (-> Frac Frac) (cond (..= +0.0 x) +0.0 (..< +0.0 x) -1.0 @@ -98,7 +98,7 @@ (def: max_exponent (//int.frac +1023)) (template [<name> <test> <doc>] - [(def: #export (<name> left right) + [(def: .public (<name> left right) {#.doc <doc>} (-> Frac Frac Frac) (if (<test> right left) @@ -109,11 +109,11 @@ [max ..> "Frac(tion) minimum."] ) -(def: #export nat +(def: .public nat (-> Frac Nat) (|>> "lux f64 i64" .nat)) -(def: #export int +(def: .public int (-> Frac Int) (|>> "lux f64 i64")) @@ -125,7 +125,7 @@ ("lux i64 right-shift" ..exponent_size) "lux i64 f64")) -(def: #export rev +(def: .public rev (-> Frac Rev) (|>> ..abs (..% +1.0) @@ -133,23 +133,23 @@ "lux f64 i64" ("lux i64 left-shift" ..exponent_size))) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Frac) (def: = ..=)) -(implementation: #export order +(implementation: .public order (Order Frac) (def: &equivalence ..equivalence) (def: < ..<)) -(def: #export smallest +(def: .public smallest Frac (///.pow (//int.frac (//int.- (.int ..mantissa_size) ..min_exponent)) +2.0)) -(def: #export biggest +(def: .public biggest Frac (let [f2^-52 (///.pow (//nat.frac (//nat.- ..mantissa_size 0)) +2.0) f2^+1023 (///.pow ..max_exponent +2.0)] @@ -158,7 +158,7 @@ (..* f2^+1023)))) (template [<name> <compose> <identity>] - [(implementation: #export <name> + [(implementation: .public <name> (Monoid Frac) (def: identity <identity>) @@ -171,7 +171,7 @@ ) (template [<name> <numerator> <doc>] - [(def: #export <name> + [(def: .public <name> {#.doc <doc>} Frac (../ +0.0 <numerator>))] @@ -180,23 +180,23 @@ [positive_infinity +1.0 "Positive infinity."] ) -(def: #export negative_infinity +(def: .public negative_infinity {#.doc "Negative infinity."} Frac (..* -1.0 ..positive_infinity)) -(def: #export (not_a_number? number) +(def: .public (not_a_number? number) {#.doc "Tests whether a frac is actually not-a-number."} (-> Frac Bit) (not (..= number number))) -(def: #export (number? value) +(def: .public (number? value) (-> Frac Bit) (not (or (..not_a_number? value) (..= ..positive_infinity value) (..= ..negative_infinity value)))) -(implementation: #export decimal +(implementation: .public decimal (Codec Text Frac) (def: (encode x) @@ -247,7 +247,7 @@ (def: smallest_exponent (..log/2 ..smallest)) -(def: #export (bits input) +(def: .public (bits input) (-> Frac I64) (.i64 (cond (..not_a_number? input) ..not_a_number_bits @@ -310,7 +310,7 @@ [sign 1 ..sign_offset] ) -(def: #export (of_bits input) +(def: .public (of_bits input) (-> I64 Frac) (case [(: Nat (..exponent input)) (: Nat (..mantissa input)) @@ -374,7 +374,7 @@ (#try.Success [representation +0]))) (template [<struct> <nat> <int> <error>] - [(implementation: #export <struct> + [(implementation: .public <struct> (Codec Text Frac) (def: (encode value) @@ -427,20 +427,20 @@ [hex //nat.hex //int.hex "Invalid hexadecimal syntax: "] ) -(implementation: #export hash +(implementation: .public hash (Hash Frac) (def: &equivalence ..equivalence) (def: hash ..bits)) -(def: #export (approximately? margin_of_error standard value) +(def: .public (approximately? margin_of_error standard value) (-> Frac Frac Frac Bit) (|> value (..- standard) ..abs (..< margin_of_error))) -(def: #export (mod divisor dividend) +(def: .public (mod divisor dividend) (All [m] (-> Frac Frac Frac)) (let [remainder (..% divisor dividend)] (if (or (and (..< +0.0 divisor) diff --git a/stdlib/source/library/lux/math/number/i16.lux b/stdlib/source/library/lux/math/number/i16.lux index 569e228fd..0f273497c 100644 --- a/stdlib/source/library/lux/math/number/i16.lux +++ b/stdlib/source/library/lux/math/number/i16.lux @@ -12,7 +12,7 @@ (def: sub (maybe.assume (i64.sub 16))) -(def: #export I16 +(def: .public I16 {#.doc (doc "A 16-bit integer.")} (:by_example [size] (Sub size) @@ -20,7 +20,7 @@ (I64 size))) -(def: #export equivalence (Equivalence I16) (\ ..sub &equivalence)) -(def: #export width Nat (\ ..sub width)) -(def: #export i16 (-> I64 I16) (\ ..sub narrow)) -(def: #export i64 (-> I16 I64) (\ ..sub widen)) +(def: .public equivalence (Equivalence I16) (\ ..sub &equivalence)) +(def: .public width Nat (\ ..sub width)) +(def: .public i16 (-> I64 I16) (\ ..sub narrow)) +(def: .public i64 (-> I16 I64) (\ ..sub widen)) diff --git a/stdlib/source/library/lux/math/number/i32.lux b/stdlib/source/library/lux/math/number/i32.lux index 33374d19a..61fe87f40 100644 --- a/stdlib/source/library/lux/math/number/i32.lux +++ b/stdlib/source/library/lux/math/number/i32.lux @@ -12,7 +12,7 @@ (def: sub (maybe.assume (i64.sub 32))) -(def: #export I32 +(def: .public I32 {#.doc (doc "A 32-bit integer.")} (:by_example [size] (Sub size) @@ -20,7 +20,7 @@ (I64 size))) -(def: #export equivalence (Equivalence I32) (\ ..sub &equivalence)) -(def: #export width Nat (\ ..sub width)) -(def: #export i32 (-> I64 I32) (\ ..sub narrow)) -(def: #export i64 (-> I32 I64) (\ ..sub widen)) +(def: .public equivalence (Equivalence I32) (\ ..sub &equivalence)) +(def: .public width Nat (\ ..sub width)) +(def: .public i32 (-> I64 I32) (\ ..sub narrow)) +(def: .public i64 (-> I32 I64) (\ ..sub widen)) diff --git a/stdlib/source/library/lux/math/number/i64.lux b/stdlib/source/library/lux/math/number/i64.lux index 02dc98748..c6b8a69d8 100644 --- a/stdlib/source/library/lux/math/number/i64.lux +++ b/stdlib/source/library/lux/math/number/i64.lux @@ -10,19 +10,19 @@ [// ["n" nat]]) -(def: #export bits_per_byte +(def: .public bits_per_byte 8) -(def: #export bytes_per_i64 +(def: .public bytes_per_i64 8) -(def: #export width +(def: .public width Nat (n.* ..bits_per_byte ..bytes_per_i64)) (template [<parameter_type> <name> <op> <doc>] - [(def: #export (<name> parameter subject) + [(def: .public (<name> parameter subject) {#.doc <doc>} (All [s] (-> <parameter_type> (I64 s) (I64 s))) (<op> parameter subject))] @@ -36,34 +36,34 @@ ) ## https://en.wikipedia.org/wiki/Mask_(computing) -(type: #export Mask +(type: .public Mask {#.doc (doc "A pattern of bits that can be imposed on I64 values.")} I64) -(def: #export (bit position) +(def: .public (bit position) {#.doc (doc "A mask with only a specific bit set.")} (-> Nat Mask) (|> 1 .i64 (..left_shifted (n.% ..width position)))) -(def: #export sign +(def: .public sign {#.doc (doc "A mask for the sign bit of ints.")} Mask (..bit (dec ..width))) -(def: #export not +(def: .public not {#.doc "Bitwise negation."} (All [s] (-> (I64 s) (I64 s))) (..xor (.i64 (dec 0)))) -(def: #export false +(def: .public false Mask (.i64 0)) -(def: #export true +(def: .public true Mask (..not ..false)) -(def: #export (mask amount_of_bits) +(def: .public (mask amount_of_bits) {#.doc (doc "Mask a block of bits of the specified size.")} (-> Nat Mask) (case amount_of_bits @@ -76,7 +76,7 @@ (-> Nat Nat Nat) (|> value (right_shifted shift) (n.+ value))) -(def: #export (count subject) +(def: .public (count subject) {#.doc "Count the number of 1s in a bit-map."} (-> (I64 Any) Nat) (let [count' (n.- (|> subject (right_shifted 1) (..and 6148914691236517205) i64) @@ -89,13 +89,13 @@ (add_shift 32) (..and 127)))) -(def: #export (clear index input) +(def: .public (clear index input) {#.doc "Clear bit at the given index."} (All [s] (-> Nat (I64 s) (I64 s))) (|> index ..bit ..not (..and input))) (template [<name> <op> <doc>] - [(def: #export (<name> index input) + [(def: .public (<name> index input) {#.doc <doc>} (All [s] (-> Nat (I64 s) (I64 s))) (|> index ..bit (<op> input)))] @@ -104,16 +104,16 @@ [flip ..xor "Flip bit at given index."] ) -(def: #export (set? index input) +(def: .public (set? index input) (-> Nat (I64 Any) Bit) (|> input (:as I64) (..and (..bit index)) (n.= 0) .not)) -(def: #export (clear? index input) +(def: .public (clear? index input) (-> Nat (I64 Any) Bit) (.not (..set? index input))) (template [<name> <forward> <backward>] - [(def: #export (<name> distance input) + [(def: .public (<name> distance input) (All [s] (-> Nat (I64 s) (I64 s))) (..or (<forward> distance input) (<backward> (n.- (n.% ..width distance) ..width) input)))] @@ -122,18 +122,18 @@ [right_rotated ..right_shifted ..left_shifted] ) -(def: #export (region offset size) +(def: .public (region offset size) {#.doc (doc "A mask for a block of bits of the given size, starting at the given offset.")} (-> Nat Nat Mask) (..left_rotated offset (..mask size))) -(implementation: #export equivalence +(implementation: .public equivalence (All [a] (Equivalence (I64 a))) (def: (= reference sample) ("lux i64 =" reference sample))) -(implementation: #export hash +(implementation: .public hash (All [a] (Hash (I64 a))) (def: &equivalence ..equivalence) @@ -141,7 +141,7 @@ (def: hash .nat)) (template [<monoid> <identity> <compose>] - [(implementation: #export <monoid> + [(implementation: .public <monoid> (All [a] (Monoid (I64 a))) (def: identity <identity>) @@ -151,7 +151,7 @@ [conjunction ..true ..and] ) -(def: #export reversed +(def: .public reversed (All [a] (-> (I64 a) (I64 a))) (let [swapper (: (-> Nat (All [a] (-> (I64 a) (I64 a)))) (function (_ power) @@ -188,7 +188,7 @@ swap/02 swap/01))) -(interface: #export (Sub size) +(interface: .public (Sub size) {#.doc (doc "A sub-space of I64 with a reduce amount of bits.")} (: (Equivalence (I64 size)) @@ -200,7 +200,7 @@ (: (-> (I64 size) I64) widen)) -(def: #export (sub width) +(def: .public (sub width) {#.doc (doc "Given a width in the interval (0,64), yields an implementation for integers of that width.")} (Ex [size] (-> Nat (Maybe (Sub size)))) (if (.and (n.> 0 width) diff --git a/stdlib/source/library/lux/math/number/i8.lux b/stdlib/source/library/lux/math/number/i8.lux index 1f02b508b..1c3bccea6 100644 --- a/stdlib/source/library/lux/math/number/i8.lux +++ b/stdlib/source/library/lux/math/number/i8.lux @@ -12,7 +12,7 @@ (def: sub (maybe.assume (i64.sub 8))) -(def: #export I8 +(def: .public I8 {#.doc (doc "An 8-bit integer.")} (:by_example [size] (Sub size) @@ -20,7 +20,7 @@ (I64 size))) -(def: #export equivalence (Equivalence I8) (\ ..sub &equivalence)) -(def: #export width Nat (\ ..sub width)) -(def: #export i8 (-> I64 I8) (\ ..sub narrow)) -(def: #export i64 (-> I8 I64) (\ ..sub widen)) +(def: .public equivalence (Equivalence I8) (\ ..sub &equivalence)) +(def: .public width Nat (\ ..sub width)) +(def: .public i8 (-> I64 I8) (\ ..sub narrow)) +(def: .public i64 (-> I8 I64) (\ ..sub widen)) diff --git a/stdlib/source/library/lux/math/number/int.lux b/stdlib/source/library/lux/math/number/int.lux index 610ad296e..dbef9c89c 100644 --- a/stdlib/source/library/lux/math/number/int.lux +++ b/stdlib/source/library/lux/math/number/int.lux @@ -19,29 +19,29 @@ ["#." nat] ["#." i64]]) -(def: #export (= reference sample) +(def: .public (= reference sample) {#.doc "Int(eger) equivalence."} (-> Int Int Bit) ("lux i64 =" reference sample)) -(def: #export (< reference sample) +(def: .public (< reference sample) {#.doc "Int(eger) less-than."} (-> Int Int Bit) ("lux i64 <" reference sample)) -(def: #export (<= reference sample) +(def: .public (<= reference sample) {#.doc "Int(eger) less-than or equal."} (-> Int Int Bit) (if ("lux i64 <" reference sample) #1 ("lux i64 =" reference sample))) -(def: #export (> reference sample) +(def: .public (> reference sample) {#.doc "Int(eger) greater-than."} (-> Int Int Bit) ("lux i64 <" sample reference)) -(def: #export (>= reference sample) +(def: .public (>= reference sample) {#.doc "Int(eger) greater-than or equal."} (-> Int Int Bit) (if ("lux i64 <" sample reference) @@ -49,7 +49,7 @@ ("lux i64 =" reference sample))) (template [<comparison> <name>] - [(def: #export <name> + [(def: .public <name> (Predicate Int) (<comparison> +0))] @@ -59,7 +59,7 @@ ) (template [<name> <test> <doc>] - [(def: #export (<name> left right) + [(def: .public (<name> left right) {#.doc <doc>} (-> Int Int Int) (if (<test> right left) @@ -71,7 +71,7 @@ ) (template [<name> <op> <doc>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) {#.doc <doc>} (-> Int Int Int) (<op> param subject))] @@ -83,25 +83,25 @@ [% "lux i64 %" "Int(eger) remainder."] ) -(def: #export (/% param subject) +(def: .public (/% param subject) {#.doc "Int(eger) [division remainder]."} (-> Int Int [Int Int]) [(../ param subject) (..% param subject)]) -(def: #export (opposite value) +(def: .public (opposite value) {#.doc (doc "A value of equal magnitude and opposite sign.")} (-> Int Int) (..- value +0)) -(def: #export (abs x) +(def: .public (abs x) {#.doc (doc "A value of equal magnitude and positive sign.")} (-> Int Int) (if (..< +0 x) (..* -1 x) x)) -(def: #export (signum x) +(def: .public (signum x) {#.doc (doc "A value (either -1, 0 or +0) which represents the sign.")} (-> Int Int) (cond (..= +0 x) +0 @@ -110,7 +110,7 @@ +1)) ## https://rob.conery.io/2018/08/21/mod-and-remainder-are-not-the-same/ -(def: #export (mod divisor dividend) +(def: .public (mod divisor dividend) {#.doc (doc "Integer modulo." "Note: The modulo and the remainder are not the same.")} (All [m] (-> Int Int Int)) @@ -122,28 +122,28 @@ (..+ divisor remainder) remainder))) -(def: #export even? +(def: .public even? (-> Int Bit) (|>> (..% +2) ("lux i64 =" +0))) -(def: #export odd? +(def: .public odd? (-> Int Bit) (|>> ..even? not)) ## https://en.wikipedia.org/wiki/Greatest_common_divisor -(def: #export (gcd a b) +(def: .public (gcd a b) {#.doc "Greatest Common Divisor."} (-> Int Int Int) (case b +0 a _ (gcd b (..% b a)))) -(def: #export (co_prime? a b) +(def: .public (co_prime? a b) (-> Int Int Bit) (..= +1 (..gcd a b))) ## https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm -(def: #export (extended_gcd a b) +(def: .public (extended_gcd a b) {#.doc "Extended euclidean algorithm."} (-> Int Int [[Int Int] Int]) (loop [x +1 x1 +0 @@ -157,7 +157,7 @@ b1 (- (* q b1) a1)))))) ## https://en.wikipedia.org/wiki/Least_common_multiple -(def: #export (lcm a b) +(def: .public (lcm a b) {#.doc "Least Common Multiple."} (-> Int Int Int) (case [a b] @@ -167,22 +167,22 @@ _ (|> a (/ (gcd a b)) (* b)))) -(def: #export frac +(def: .public frac (-> Int Frac) (|>> "lux i64 f64")) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Int) (def: = ..=)) -(implementation: #export order +(implementation: .public order (Order Int) (def: &equivalence ..equivalence) (def: < ..<)) -(implementation: #export enum +(implementation: .public enum (Enum Int) (def: &order ..order) @@ -190,7 +190,7 @@ (def: pred dec)) ## TODO: Find out why the numeric literals fail during JS compilation. -(implementation: #export interval +(implementation: .public interval (Interval Int) (def: &enum ..enum) @@ -204,7 +204,7 @@ (//i64.left_shifted 63 +1))) (template [<name> <compose> <identity>] - [(implementation: #export <name> + [(implementation: .public <name> (Monoid Int) (def: identity <identity>) @@ -220,7 +220,7 @@ (def: +sign "+") (template [<struct> <codec> <error>] - [(implementation: #export <struct> + [(implementation: .public <struct> (Codec Text Int) (def: (encode value) @@ -254,13 +254,13 @@ [hex //nat.hex "Invalid hexadecimal syntax for Int: "] ) -(implementation: #export hash +(implementation: .public hash (Hash Int) (def: &equivalence ..equivalence) (def: hash .nat)) -(def: #export (right_shifted parameter subject) +(def: .public (right_shifted parameter subject) {#.doc "Signed/arithmetic bitwise right-shift."} (-> Nat Int Int) (//i64.or (//i64.and //i64.sign subject) diff --git a/stdlib/source/library/lux/math/number/nat.lux b/stdlib/source/library/lux/math/number/nat.lux index 7599e221f..63c2302c4 100644 --- a/stdlib/source/library/lux/math/number/nat.lux +++ b/stdlib/source/library/lux/math/number/nat.lux @@ -16,7 +16,7 @@ ["." maybe]]]]) (template [<extension> <output> <name> <documentation>] - [(def: #export (<name> parameter subject) + [(def: .public (<name> parameter subject) {#.doc <documentation>} (-> Nat Nat <output>) (<extension> parameter subject))] @@ -35,7 +35,7 @@ (let [mask (|> 1 ("lux i64 left-shift" 32) ("lux i64 -" 1))] (|>> ("lux i64 and" mask)))) -(def: #export (< reference sample) +(def: .public (< reference sample) {#.doc "Nat(ural) less-than."} (-> Nat Nat Bit) (let [referenceH (..high reference) @@ -48,19 +48,19 @@ (..low sample)) #0)))) -(def: #export (<= reference sample) +(def: .public (<= reference sample) {#.doc "Nat(ural) less-than or equal."} (-> Nat Nat Bit) (if (..< reference sample) #1 ("lux i64 =" reference sample))) -(def: #export (> reference sample) +(def: .public (> reference sample) {#.doc "Nat(ural) greater-than."} (-> Nat Nat Bit) (..< sample reference)) -(def: #export (>= reference sample) +(def: .public (>= reference sample) {#.doc "Nat(ural) greater-than or equal."} (-> Nat Nat Bit) (if (..< sample reference) @@ -68,7 +68,7 @@ ("lux i64 =" reference sample))) (template [<name> <test> <doc>] - [(def: #export (<name> left right) + [(def: .public (<name> left right) {#.doc <doc>} (-> Nat Nat Nat) (if (<test> right left) @@ -79,7 +79,7 @@ [max ..> "Nat(ural) maximum."] ) -(def: #export (* parameter subject) +(def: .public (* parameter subject) {#.doc "Nat(ural) multiplication."} (-> Nat Nat Nat) (:as Nat @@ -87,7 +87,7 @@ (:as Int parameter) (:as Int subject)))) -(def: #export (/ parameter subject) +(def: .public (/ parameter subject) {#.doc "Nat(ural) division."} (-> Nat Nat Nat) (if ("lux i64 <" +0 (:as Int parameter)) @@ -106,7 +106,7 @@ quotient ("lux i64 +" 1 quotient))))) -(def: #export (/% parameter subject) +(def: .public (/% parameter subject) {#.doc "Nat(ural) [division remainder]."} (-> Nat Nat [Nat Nat]) (let [quotient (../ parameter subject) @@ -115,7 +115,7 @@ (:as Int quotient))] [quotient ("lux i64 -" flat subject)])) -(def: #export (% parameter subject) +(def: .public (% parameter subject) {#.doc "Nat(ural) remainder."} (-> Nat Nat Nat) (let [flat ("lux i64 *" @@ -123,18 +123,18 @@ (:as Int (../ parameter subject)))] ("lux i64 -" flat subject))) -(def: #export (gcd a b) +(def: .public (gcd a b) {#.doc "Greatest Common Divisor."} (-> Nat Nat Nat) (case b 0 a _ (gcd b (..% b a)))) -(def: #export (co_prime? a b) +(def: .public (co_prime? a b) (-> Nat Nat Bit) (..= 1 (..gcd a b))) -(def: #export (lcm a b) +(def: .public (lcm a b) {#.doc "Least Common Multiple."} (-> Nat Nat Nat) (case [a b] @@ -144,37 +144,37 @@ _ (|> a (../ (..gcd a b)) (..* b)))) -(def: #export even? +(def: .public even? (-> Nat Bit) (|>> (..% 2) ("lux i64 =" 0))) -(def: #export odd? +(def: .public odd? (-> Nat Bit) (|>> ..even? not)) -(def: #export frac +(def: .public frac (-> Nat Frac) (|>> .int "lux i64 f64")) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Nat) (def: = ..=)) -(implementation: #export order +(implementation: .public order (Order Nat) (def: &equivalence ..equivalence) (def: < ..<)) -(implementation: #export enum +(implementation: .public enum (Enum Nat) (def: &order ..order) (def: succ inc) (def: pred dec)) -(implementation: #export interval +(implementation: .public interval (Interval Nat) (def: &enum ..enum) @@ -182,7 +182,7 @@ (def: bottom 0)) (template [<name> <compose> <identity>] - [(implementation: #export <name> + [(implementation: .public <name> (Monoid Nat) (def: identity <identity>) @@ -300,7 +300,7 @@ _ #.None)) (template [<shift> <struct> <to_character> <to_value> <error>] - [(implementation: #export <struct> + [(implementation: .public <struct> (Codec Text Nat) (def: encode @@ -341,7 +341,7 @@ [4 hex hexadecimal_character hexadecimal_value "Invalid hexadecimal syntax for Nat: "] ) -(implementation: #export decimal +(implementation: .public decimal (Codec Text Nat) (def: (encode value) @@ -373,7 +373,7 @@ (#try.Success output))) <failure>))))) -(implementation: #export hash +(implementation: .public hash (Hash Nat) (def: &equivalence ..equivalence) diff --git a/stdlib/source/library/lux/math/number/ratio.lux b/stdlib/source/library/lux/math/number/ratio.lux index a53f87dd9..a9a494208 100644 --- a/stdlib/source/library/lux/math/number/ratio.lux +++ b/stdlib/source/library/lux/math/number/ratio.lux @@ -23,12 +23,12 @@ [// ["n" nat ("#\." decimal)]]) -(type: #export Ratio +(type: .public Ratio {#.doc (doc "An unsigned ratio of numbers.")} {#numerator Nat #denominator Nat}) -(def: #export (nat value) +(def: .public (nat value) (-> Ratio (Maybe Nat)) (case (get@ #denominator value) 1 (#.Some (get@ #numerator value)) @@ -40,7 +40,7 @@ {#numerator (n./ common numerator) #denominator (n./ common denominator)})) -(syntax: #export (ratio numerator {?denominator (<>.maybe <code>.any)}) +(syntax: .public (ratio numerator {?denominator (<>.maybe <code>.any)}) {#.doc (doc "Rational literals." (ratio numerator denominator) "The denominator can be omitted if it is 1." @@ -48,14 +48,14 @@ (in (list (` ((~! ..normal) {#..numerator (~ numerator) #..denominator (~ (maybe.else (' 1) ?denominator))}))))) -(def: #export (= parameter subject) +(def: .public (= parameter subject) (-> Ratio Ratio Bit) (and (n.= (get@ #numerator parameter) (get@ #numerator subject)) (n.= (get@ #denominator parameter) (get@ #denominator subject)))) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Ratio) (def: = ..=)) @@ -67,72 +67,72 @@ (n.* (get@ #denominator parameter) (get@ #numerator subject))]) -(def: #export (< parameter subject) +(def: .public (< parameter subject) (-> Ratio Ratio Bit) (let [[parameter' subject'] (..equalized parameter subject)] (n.< parameter' subject'))) -(def: #export (<= parameter subject) +(def: .public (<= parameter subject) (-> Ratio Ratio Bit) (or (< parameter subject) (= parameter subject))) -(def: #export (> parameter subject) +(def: .public (> parameter subject) (-> Ratio Ratio Bit) (..< subject parameter)) -(def: #export (>= parameter subject) +(def: .public (>= parameter subject) (-> Ratio Ratio Bit) (or (> parameter subject) (= parameter subject))) -(implementation: #export order +(implementation: .public order (Order Ratio) (def: &equivalence ..equivalence) (def: < ..<)) -(def: #export (+ parameter subject) +(def: .public (+ parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalized parameter subject)] (normal [(n.+ parameter' subject') (n.* (get@ #denominator parameter) (get@ #denominator subject))]))) -(def: #export (- parameter subject) +(def: .public (- parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalized parameter subject)] (normal [(n.- parameter' subject') (n.* (get@ #denominator parameter) (get@ #denominator subject))]))) -(def: #export (* parameter subject) +(def: .public (* parameter subject) (-> Ratio Ratio Ratio) (normal [(n.* (get@ #numerator parameter) (get@ #numerator subject)) (n.* (get@ #denominator parameter) (get@ #denominator subject))])) -(def: #export (/ parameter subject) +(def: .public (/ parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalized parameter subject)] (normal [subject' parameter']))) -(def: #export (% parameter subject) +(def: .public (% parameter subject) (-> Ratio Ratio Ratio) (let [[parameter' subject'] (..equalized parameter subject) quot (n./ parameter' subject')] (..- (update@ #numerator (n.* quot) parameter) subject))) -(def: #export (reciprocal (^slots [#numerator #denominator])) +(def: .public (reciprocal (^slots [#numerator #denominator])) (-> Ratio Ratio) {#numerator denominator #denominator numerator}) (def: separator ":") -(implementation: #export codec +(implementation: .public codec (Codec Text Ratio) (def: (encode (^slots [#numerator #denominator])) @@ -151,7 +151,7 @@ (#.Left (text\compose "Invalid syntax for ratio: " input))))) (template [<identity> <compose> <name>] - [(implementation: #export <name> + [(implementation: .public <name> (Monoid Ratio) (def: identity (..ratio <identity>)) diff --git a/stdlib/source/library/lux/math/number/rev.lux b/stdlib/source/library/lux/math/number/rev.lux index 66abd7e12..dadb71641 100644 --- a/stdlib/source/library/lux/math/number/rev.lux +++ b/stdlib/source/library/lux/math/number/rev.lux @@ -21,7 +21,7 @@ ["#." int]]) (template [<power> <name>] - [(def: #export <name> + [(def: .public <name> Rev (.rev (//i64.left_shifted (//nat.- <power> //i64.width) 1)))] @@ -39,29 +39,29 @@ [12 /4096] ) -(def: #export (= reference sample) +(def: .public (= reference sample) {#.doc "Rev(olution) equivalence."} (-> Rev Rev Bit) ("lux i64 =" reference sample)) -(def: #export (< reference sample) +(def: .public (< reference sample) {#.doc "Rev(olution) less-than."} (-> Rev Rev Bit) (//nat.< (.nat reference) (.nat sample))) -(def: #export (<= reference sample) +(def: .public (<= reference sample) {#.doc "Rev(olution) less-than or equal."} (-> Rev Rev Bit) (if (//nat.< (.nat reference) (.nat sample)) true ("lux i64 =" reference sample))) -(def: #export (> reference sample) +(def: .public (> reference sample) {#.doc "Rev(olution) greater-than."} (-> Rev Rev Bit) (..< sample reference)) -(def: #export (>= reference sample) +(def: .public (>= reference sample) {#.doc "Rev(olution) greater-than or equal."} (-> Rev Rev Bit) (if (..< sample reference) @@ -69,7 +69,7 @@ ("lux i64 =" reference sample))) (template [<name> <test> <doc>] - [(def: #export (<name> left right) + [(def: .public (<name> left right) {#.doc <doc>} (-> Rev Rev Rev) (if (<test> right left) @@ -81,7 +81,7 @@ ) (template [<name> <op> <doc>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) {#.doc <doc>} (-> Rev Rev Rev) (<op> param subject))] @@ -99,7 +99,7 @@ (let [mask (|> 1 ("lux i64 left-shift" 32) ("lux i64 -" 1))] (|>> ("lux i64 and" mask)))) -(def: #export (* param subject) +(def: .public (* param subject) {#.doc "Rev(olution) multiplication."} (-> Rev Rev Rev) (let [subjectH (..high subject) @@ -131,14 +131,14 @@ (//nat./ numerator ..odd_one)) (with_expansions [<least_significant_bit> 1] - (def: #export (reciprocal numerator) + (def: .public (reciprocal numerator) {#.doc "Rev(olution) reciprocal of a Nat(ural)."} (-> Nat Rev) (.rev (case (: Nat ("lux i64 and" <least_significant_bit> numerator)) 0 (..even_reciprocal numerator) _ (..odd_reciprocal numerator)))) - (def: #export (/ param subject) + (def: .public (/ param subject) {#.doc "Rev(olution) division."} (-> Rev Rev Rev) (if ("lux i64 =" +0 param) @@ -149,7 +149,7 @@ (.rev (//nat.* reciprocal (.nat subject))))))) (template [<operator> <name> <output> <output_type> <documentation>] - [(def: #export (<name> param subject) + [(def: .public (<name> param subject) {#.doc <documentation>} (-> Rev Rev <output_type>) (<output> (<operator> (.nat param) (.nat subject))))] @@ -159,7 +159,7 @@ ) (template [<operator> <name>] - [(def: #export (<name> scale subject) + [(def: .public (<name> scale subject) (-> Nat Rev Rev) (.rev (<operator> (.nat scale) (.nat subject))))] @@ -167,7 +167,7 @@ [//nat./ down] ) -(def: #export (/% param subject) +(def: .public (/% param subject) (-> Rev Rev [Rev Rev]) [(../ param subject) (..% param subject)]) @@ -180,35 +180,35 @@ (def: frac_denominator (..mantissa -1)) -(def: #export frac +(def: .public frac (-> Rev Frac) (|>> ..mantissa ("lux f64 /" ..frac_denominator))) -(implementation: #export equivalence +(implementation: .public equivalence (Equivalence Rev) (def: = ..=)) -(implementation: #export hash +(implementation: .public hash (Hash Rev) (def: &equivalence ..equivalence) (def: hash .nat)) -(implementation: #export order +(implementation: .public order (Order Rev) (def: &equivalence ..equivalence) (def: < ..<)) -(implementation: #export enum +(implementation: .public enum (Enum Rev) (def: &order ..order) (def: succ inc) (def: pred dec)) -(implementation: #export interval +(implementation: .public interval (Interval Rev) (def: &enum ..enum) @@ -216,7 +216,7 @@ (def: bottom (.rev 0))) (template [<name> <compose> <identity>] - [(implementation: #export <name> + [(implementation: .public <name> (Monoid Rev) (def: identity (\ interval <identity>)) @@ -233,7 +233,7 @@ (template [<struct> <codec> <char_bit_size> <error>] [(with_expansions [<error_output> (as_is (#try.Failure ("lux text concat" <error> repr)))] - (implementation: #export <struct> + (implementation: .public <struct> (Codec Text Rev) (def: (encode value) @@ -408,7 +408,7 @@ (digits\-!' idx (..digit idx param) output)) output))) -(implementation: #export decimal +(implementation: .public decimal (Codec Text Rev) (def: (encode input) diff --git a/stdlib/source/library/lux/math/random.lux b/stdlib/source/library/lux/math/random.lux index 7d80d6f76..a0f8f66a1 100644 --- a/stdlib/source/library/lux/math/random.lux +++ b/stdlib/source/library/lux/math/random.lux @@ -38,15 +38,15 @@ [type [refinement (#+ Refiner Refined)]]]]) -(type: #export #rec PRNG +(type: .public #rec PRNG {#.doc "An abstract way to represent any PRNG."} (-> Any [PRNG I64])) -(type: #export (Random a) +(type: .public (Random a) {#.doc "A producer of random values based on a PRNG."} (-> PRNG [PRNG a])) -(implementation: #export functor +(implementation: .public functor (Functor Random) (def: (map f fa) @@ -54,7 +54,7 @@ (let [[state' a] (fa state)] [state' (f a)])))) -(implementation: #export apply +(implementation: .public apply (Apply Random) (def: &functor ..functor) @@ -65,7 +65,7 @@ [state'' a] (fa state')] [state'' (f a)])))) -(implementation: #export monad +(implementation: .public monad (Monad Random) (def: &functor ..functor) @@ -79,7 +79,7 @@ (let [[state' fa] (ffa state)] (fa state'))))) -(def: #export (only pred gen) +(def: .public (only pred gen) {#.doc "Retries the generator until the output satisfies a predicate."} (All [a] (-> (-> a Bit) (Random a) (Random a))) (do ..monad @@ -88,7 +88,7 @@ (in sample) (only pred gen)))) -(def: #export (one check random) +(def: .public (one check random) (All [a b] (-> (-> a (Maybe b)) (Random a) (Random b))) (do ..monad @@ -100,7 +100,7 @@ #.None (one check random)))) -(def: #export (refined refiner gen) +(def: .public (refined refiner gen) {#.doc "Retries the generator until the output can be refined."} (All [t r] (-> (Refiner t r) (Random t) (Random (Refined t r)))) (do ..monad @@ -112,13 +112,13 @@ #.None (refined refiner gen)))) -(def: #export bit +(def: .public bit (Random Bit) (function (_ prng) (let [[prng output] (prng [])] [prng (|> output (i64.and 1) (n.= 1))]))) -(def: #export i64 +(def: .public i64 (Random I64) (function (_ prng) (let [[prng left] (prng []) @@ -128,7 +128,7 @@ ("lux i64 +" right))]))) (template [<name> <type> <cast>] - [(def: #export <name> + [(def: .public <name> (Random <type>) (\ ..monad map <cast> ..i64))] @@ -137,11 +137,11 @@ [rev Rev .rev] ) -(def: #export frac +(def: .public frac (Random Frac) (\ ..monad map (|>> .i64 f.of_bits) ..nat)) -(def: #export safe_frac +(def: .public safe_frac {#.doc (doc "A number in the interval [0.0,1.0].")} (Random Frac) (let [mantissa_range (.int (i64.left_shifted 53 1)) @@ -152,7 +152,7 @@ (f./ mantissa_max)) ..int))) -(def: #export (char set) +(def: .public (char set) (-> unicode.Set (Random Char)) (let [start (unicode.start set) end (unicode.end set) @@ -163,7 +163,7 @@ (\ ..monad map in_range) (..only (unicode.member? set))))) -(def: #export (text char_gen size) +(def: .public (text char_gen size) (-> (Random Char) Nat (Random Text)) (if (n.= 0 size) (\ ..monad in "") @@ -173,7 +173,7 @@ (in (text\compose (text.of_char x) xs))))) (template [<name> <set>] - [(def: #export <name> + [(def: .public <name> (-> Nat (Random Text)) (..text (..char <set>)))] @@ -187,7 +187,7 @@ ) (template [<name> <type> <ctor> <gen>] - [(def: #export <name> + [(def: .public <name> (Random <type>) (do ..monad [left <gen> @@ -198,7 +198,7 @@ [complex c.Complex c.complex ..safe_frac] ) -(def: #export (and left right) +(def: .public (and left right) {#.doc "Sequencing combinator."} (All [a b] (-> (Random a) (Random b) (Random [a b]))) (do ..monad @@ -206,7 +206,7 @@ =right right] (in [=left =right]))) -(def: #export (or left right) +(def: .public (or left right) {#.doc "Heterogeneous alternative combinator."} (All [a b] (-> (Random a) (Random b) (Random (Or a b)))) (do {! ..monad} @@ -219,7 +219,7 @@ [=right right] (in (0 #1 =right)))))) -(def: #export (either left right) +(def: .public (either left right) {#.doc "Homogeneous alternative combinator."} (All [a] (-> (Random a) (Random a) (Random a))) (do ..monad @@ -228,14 +228,14 @@ left right))) -(def: #export (rec gen) +(def: .public (rec gen) {#.doc "A combinator for producing recursive random generators."} (All [a] (-> (-> (Random a) (Random a)) (Random a))) (function (_ state) (let [gen' (gen (rec gen))] (gen' state)))) -(def: #export (maybe value_gen) +(def: .public (maybe value_gen) (All [a] (-> (Random a) (Random (Maybe a)))) (do {! ..monad} [some? bit] @@ -246,7 +246,7 @@ (in #.None)))) (template [<name> <type> <zero> <plus>] - [(def: #export (<name> size value_gen) + [(def: .public (<name> size value_gen) (All [a] (-> Nat (Random a) (Random (<type> a)))) (if (n.> 0 size) (do ..monad @@ -260,7 +260,7 @@ ) (template [<name> <type> <ctor>] - [(def: #export (<name> size value_gen) + [(def: .public (<name> size value_gen) (All [a] (-> Nat (Random a) (Random (<type> a)))) (do ..monad [values (list size value_gen)] @@ -271,7 +271,7 @@ [stack Stack (list\fold stack.push stack.empty)] ) -(def: #export (set hash size value_gen) +(def: .public (set hash size value_gen) (All [a] (-> (Hash a) Nat (Random a) (Random (Set a)))) (if (n.> 0 size) (do {! ..monad} @@ -285,7 +285,7 @@ (recur []))))) (\ ..monad in (set.empty hash)))) -(def: #export (dictionary hash size key_gen value_gen) +(def: .public (dictionary hash size key_gen value_gen) (All [k v] (-> (Hash k) Nat (Random k) (Random v) (Random (Dictionary k v)))) (if (n.> 0 size) (do {! ..monad} @@ -300,23 +300,23 @@ (recur []))))) (\ ..monad in (dictionary.empty hash)))) -(def: #export instant +(def: .public instant (Random Instant) (\ ..monad map instant.of_millis ..int)) -(def: #export date +(def: .public date (Random Date) (\ ..monad map instant.date ..instant)) -(def: #export time +(def: .public time (Random Time) (\ ..monad map instant.time ..instant)) -(def: #export duration +(def: .public duration (Random Duration) (\ ..monad map duration.of_millis ..int)) -(def: #export month +(def: .public month (Random Month) (let [(^open "\.") ..monad] (..either (..either (..either (\in #month.January) @@ -332,7 +332,7 @@ (..either (\in #month.November) (\in #month.December))))))) -(def: #export day +(def: .public day (Random Day) (let [(^open "\.") ..monad] (..either (..either (\in #day.Sunday) @@ -343,18 +343,18 @@ (..either (\in #day.Friday) (\in #day.Saturday)))))) -(def: #export (run prng calc) +(def: .public (run prng calc) (All [a] (-> PRNG (Random a) [PRNG a])) (calc prng)) -(def: #export (prng update return) +(def: .public (prng update return) (All [a] (-> (-> a a) (-> a I64) (-> a PRNG))) (function (recur state) (function (_ _) [(recur (update state)) (return state)]))) -(def: #export (pcg_32 [increase seed]) +(def: .public (pcg_32 [increase seed]) {#.doc (doc "An implementation of the PCG32 algorithm." "For more information, please see: http://www.pcg-random.org/")} (-> [(I64 Any) (I64 Any)] PRNG) @@ -369,7 +369,7 @@ (i64.right_rotated rot) .i64))]))) -(def: #export (xoroshiro_128+ [s0 s1]) +(def: .public (xoroshiro_128+ [s0 s1]) {#.doc (doc "An implementation of the Xoroshiro128+ algorithm." "For more information, please see: http://xoroshiro.di.unimi.it/")} (-> [(I64 Any) (I64 Any)] PRNG) @@ -384,7 +384,7 @@ ## https://en.wikipedia.org/wiki/Xorshift#Initialization ## http://xorshift.di.unimi.it/splitmix64.c -(def: #export split_mix_64 +(def: .public split_mix_64 {#.doc (doc "An implementation of the SplitMix64 algorithm.")} (-> Nat PRNG) (let [twist (: (-> Nat Nat Nat) |