From de728c05f0c7fbc47b0d0d9db02d141d734eb755 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sat, 15 Dec 2018 19:05:19 -0400 Subject: No longer relying on "signature:"'s and "structure:"'s internal macro-expansion to handle the "do-template"s inside. --- stdlib/source/lux/control/functor.lux | 1 + stdlib/source/lux/control/number.lux | 19 ++--- stdlib/source/lux/control/order.lux | 22 ++--- stdlib/source/lux/data/collection/array.lux | 3 +- stdlib/source/lux/data/collection/row.lux | 12 +-- stdlib/source/lux/data/number.lux | 1 - stdlib/source/lux/macro/poly/json.lux | 1 + stdlib/source/lux/time/date.lux | 45 +++++----- stdlib/source/lux/time/duration.lux | 22 ++--- stdlib/source/lux/time/instant.lux | 34 ++++---- stdlib/source/lux/type/unit.lux | 22 ++--- stdlib/source/lux/world/file.lux | 122 ++++++++++++++-------------- 12 files changed, 150 insertions(+), 154 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/control/functor.lux b/stdlib/source/lux/control/functor.lux index 8fcb40c55..b8ad0b159 100644 --- a/stdlib/source/lux/control/functor.lux +++ b/stdlib/source/lux/control/functor.lux @@ -21,5 +21,6 @@ (structure: #export (compose Functor Functor) {#.doc "Functor composition."} (All [F G] (-> (Functor F) (Functor G) (Functor (All [a] (F (G a)))))) + (def: (map f fga) (:: Functor map (:: Functor map f) fga))) diff --git a/stdlib/source/lux/control/number.lux b/stdlib/source/lux/control/number.lux index bf8e41194..3fc8faabf 100644 --- a/stdlib/source/lux/control/number.lux +++ b/stdlib/source/lux/control/number.lux @@ -1,15 +1,14 @@ (.module: lux) -## [Signatures] -(signature: #export (Number n) - {#.doc "Everything that should be expected of a number type."} +(`` (signature: #export (Number n) + {#.doc "Everything that should be expected of a number type."} - (do-template [] - [(: (-> n n n) )] - [+] [-] [*] [/] [%]) + (~~ (do-template [] + [(: (-> n n n) )] + [+] [-] [*] [/] [%])) - (do-template [] - [(: (-> n n) )] - [negate] [signum] [abs]) - ) + (~~ (do-template [] + [(: (-> n n) )] + [negate] [signum] [abs])) + )) diff --git a/stdlib/source/lux/control/order.lux b/stdlib/source/lux/control/order.lux index ef9030c2d..30618b317 100644 --- a/stdlib/source/lux/control/order.lux +++ b/stdlib/source/lux/control/order.lux @@ -4,18 +4,18 @@ [// [equivalence (#+ Equivalence)]]) ## [Signatures] -(signature: #export (Order a) - {#.doc "A signature for types that possess some sense of ordering among their elements."} - - (: (Equivalence a) - eq) - - (do-template [] - [(: (-> a a Bit) )] +(`` (signature: #export (Order a) + {#.doc "A signature for types that possess some sense of ordering among their elements."} + + (: (Equivalence a) + eq) + + (~~ (do-template [] + [(: (-> a a Bit) )] - [<] [<=] [>] [>=] - ) - ) + [<] [<=] [>] [>=] + )) + )) ## [Values] (def: #export (order eq <) diff --git a/stdlib/source/lux/data/collection/array.lux b/stdlib/source/lux/data/collection/array.lux index c38ae1371..6bd59d7b5 100644 --- a/stdlib/source/lux/data/collection/array.lux +++ b/stdlib/source/lux/data/collection/array.lux @@ -229,8 +229,7 @@ _ #0))) #1 - (list.indices sxs)))) - )) + (list.indices sxs)))))) (structure: #export Monoid (All [a] (Monoid (Array a))) (def: identity (new 0)) diff --git a/stdlib/source/lux/data/collection/row.lux b/stdlib/source/lux/data/collection/row.lux index 668e49b6c..d388d6ede 100644 --- a/stdlib/source/lux/data/collection/row.lux +++ b/stdlib/source/lux/data/collection/row.lux @@ -377,8 +377,7 @@ (#Hierarchy hierarchy) (array/fold (function (_ node init') (fold f init' node)) init - hierarchy)) - )) + hierarchy)))) (structure: #export _ (Fold Row) (def: (fold f init xs) @@ -387,8 +386,7 @@ (fold f init (#Hierarchy (get@ #root xs))) - (#Base (get@ #tail xs)))) - )) + (#Base (get@ #tail xs)))))) (structure: #export Monoid (All [a] (Monoid (Row a))) (def: identity empty) @@ -402,16 +400,14 @@ (#Base (array/map f base)) (#Hierarchy hierarchy) - (#Hierarchy (array/map (map f) hierarchy))) - )) + (#Hierarchy (array/map (map f) hierarchy))))) (structure: #export _ (Functor Row) (def: (map f xs) {#level (get@ #level xs) #size (get@ #size xs) #root (|> xs (get@ #root) (array/map (:: Functor map f))) - #tail (|> xs (get@ #tail) (array/map f)) - })) + #tail (|> xs (get@ #tail) (array/map f))})) (structure: #export _ (Apply Row) (def: functor Functor) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index b133e905f..e745d542a 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -1022,7 +1022,6 @@ (structure: #export _ (Hash Frac) (def: eq Equivalence) - (def: hash frac-to-bits)) (structure: #export _ (Hash Rev) diff --git a/stdlib/source/lux/macro/poly/json.lux b/stdlib/source/lux/macro/poly/json.lux index 96c647c6b..6ef9b249e 100644 --- a/stdlib/source/lux/macro/poly/json.lux +++ b/stdlib/source/lux/macro/poly/json.lux @@ -77,6 +77,7 @@ (structure: Codec (All [unit] (Codec JSON (unit.Qty unit))) + (def: encode (|>> unit.out (:: Codec encode))) (def: decode diff --git a/stdlib/source/lux/time/date.lux b/stdlib/source/lux/time/date.lux index 71dd1003d..59bfc5c0e 100644 --- a/stdlib/source/lux/time/date.lux +++ b/stdlib/source/lux/time/date.lux @@ -70,17 +70,17 @@ #November 10 #December 11)) -(structure: #export _ (Order Month) - (def: eq Equivalence) - (do-template [ ] - [(def: ( reference sample) - ( (month-to-nat reference) (month-to-nat sample)))] +(`` (structure: #export _ (Order Month) + (def: eq Equivalence) + (~~ (do-template [ ] + [(def: ( reference sample) + ( (month-to-nat reference) (month-to-nat sample)))] - [< n/<] - [<= n/<=] - [> n/>] - [>= n/>=] - )) + [< n/<] + [<= n/<=] + [> n/>] + [>= n/>=] + )))) (structure: #export _ (Enum Month) (def: order Order) @@ -150,17 +150,17 @@ #Friday 5 #Saturday 6)) -(structure: #export _ (Order Day) - (def: eq Equivalence) - (do-template [ ] - [(def: ( reference sample) - ( (day-to-nat reference) (day-to-nat sample)))] +(`` (structure: #export _ (Order Day) + (def: eq Equivalence) + (~~ (do-template [ ] + [(def: ( reference sample) + ( (day-to-nat reference) (day-to-nat sample)))] - [< n/<] - [<= n/<=] - [> n/>] - [>= n/>=] - )) + [< n/<] + [<= n/<=] + [> n/>] + [>= n/>=] + )))) (structure: #export _ (Enum Day) (def: order Order) @@ -321,5 +321,6 @@ {#.doc (doc "Based on ISO 8601." "For example: 2017-01-15")} (Codec Text Date) - (def: encode encode) - (def: decode decode)) + + (def: encode ..encode) + (def: decode ..decode)) diff --git a/stdlib/source/lux/time/duration.lux b/stdlib/source/lux/time/duration.lux index 699abe31d..9821bc33d 100644 --- a/stdlib/source/lux/time/duration.lux +++ b/stdlib/source/lux/time/duration.lux @@ -61,17 +61,17 @@ (def: (= param subject) (i/= (:representation param) (:representation subject)))) - (structure: #export _ (Order Duration) - (def: eq Equivalence) - (do-template [ ] - [(def: ( param subject) - ( (:representation param) (:representation subject)))] - - [< i/<] - [<= i/<=] - [> i/>] - [>= i/>=] - )) + (`` (structure: #export _ (Order Duration) + (def: eq Equivalence) + (~~ (do-template [ ] + [(def: ( param subject) + ( (:representation param) (:representation subject)))] + + [< i/<] + [<= i/<=] + [> i/>] + [>= i/>=] + )))) (open: "duration/." Order) diff --git a/stdlib/source/lux/time/instant.lux b/stdlib/source/lux/time/instant.lux index 8c61abe5c..d8fb0fe98 100644 --- a/stdlib/source/lux/time/instant.lux +++ b/stdlib/source/lux/time/instant.lux @@ -55,23 +55,23 @@ (def: (= param subject) (:: number.Equivalence = (:representation param) (:representation subject)))) - (structure: #export _ (Order Instant) - (def: eq Equivalence) - (do-template [] - [(def: ( param subject) - (:: number.Order (:representation param) (:representation subject)))] - - [<] [<=] [>] [>=] - )) - - (structure: #export _ (Enum Instant) - (def: order Order) - (do-template [] - [(def: - (|>> :representation (:: number.Enum ) :abstraction))] - - [succ] [pred] - )) + (`` (structure: #export _ (Order Instant) + (def: eq Equivalence) + (~~ (do-template [] + [(def: ( param subject) + (:: number.Order (:representation param) (:representation subject)))] + + [<] [<=] [>] [>=] + )))) + + (`` (structure: #export _ (Enum Instant) + (def: order Order) + (~~ (do-template [] + [(def: + (|>> :representation (:: number.Enum ) :abstraction))] + + [succ] [pred] + )))) ) (def: #export epoch diff --git a/stdlib/source/lux/type/unit.lux b/stdlib/source/lux/type/unit.lux index 96584a989..6f38a02d0 100644 --- a/stdlib/source/lux/type/unit.lux +++ b/stdlib/source/lux/type/unit.lux @@ -167,17 +167,17 @@ (def: (= reference sample) (i/= (out reference) (out sample)))) -(structure: #export Order (All [unit] (Order (Qty unit))) - (def: eq Equivalence) - - (do-template [ ] - [(def: ( reference sample) - ( (out reference) (out sample)))] - - [< i/<] - [<= i/<=] - [> i/>] - [>= i/>=])) +(`` (structure: #export Order (All [unit] (Order (Qty unit))) + (def: eq Equivalence) + + (~~ (do-template [ ] + [(def: ( reference sample) + ( (out reference) (out sample)))] + + [< i/<] + [<= i/<=] + [> i/>] + [>= i/>=])))) (structure: #export Enum (All [unit] (Enum (Qty unit))) (def: order Order) diff --git a/stdlib/source/lux/world/file.lux b/stdlib/source/lux/world/file.lux index 343d2f7aa..df90ba842 100644 --- a/stdlib/source/lux/world/file.lux +++ b/stdlib/source/lux/world/file.lux @@ -47,15 +47,15 @@ (Capability [i] (! (Error Any)))) (signature: #export (File !) - (do-template [ ] - [(: (Can-Query ! ) - )] + (~~ (do-template [ ] + [(: (Can-Query ! ) + )] - [size Nat] - [last-modified Instant] - [can-execute? Bit] - [content (Dirty Binary)] - ) + [size Nat] + [last-modified Instant] + [can-execute? Bit] + [content (Dirty Binary)] + )) (: (Can-Open ! File) move) @@ -86,15 +86,15 @@ discard)) (signature: #export (System !) - (do-template [ ] - [(: (Can-Open ! ) - )] + (~~ (do-template [ ] + [(: (Can-Open ! ) + )] - [file File] - [create-file File] - [directory Directory] - [create-directory Directory] - ) + [file File] + [create-file File] + [directory Directory] + [create-directory Directory] + )) (: Text separator) @@ -225,17 +225,17 @@ (structure: (File path) (-> Path (File IO)) - (do-template [ ] - [(def: ( data) - (do io.Monad - [stream (FileOutputStream::new (java/io/File::new path) ) - _ (OutputStream::write data stream) - _ (OutputStream::flush stream)] - (AutoCloseable::close stream)))] + (~~ (do-template [ ] + [(def: ( data) + (do io.Monad + [stream (FileOutputStream::new (java/io/File::new path) ) + _ (OutputStream::write data stream) + _ (OutputStream::flush stream)] + (AutoCloseable::close stream)))] - [over-write #0] - [append #1] - ) + [over-write #0] + [append #1] + )) (def: (content _) (do io.Monad @@ -294,46 +294,46 @@ (structure: (Directory path) (-> Path (Directory IO)) - (do-template [ ] - [(def: ( _) - (do io.Monad - [?children (java/io/File::listFiles (java/io/File::new path))] - (case ?children - (#.Some children) - (|> children - array.to-list - (monad.filter @ (|>> )) - (:: @ map (monad.map @ (|>> java/io/File::getAbsolutePath (:: @ map )))) - (:: @ join)) - - #.None - (io.throw not-a-directory [path]))))] - - [files java/io/File::isFile File] - [directories java/io/File::isDirectory Directory] - ) + (~~ (do-template [ ] + [(def: ( _) + (do io.Monad + [?children (java/io/File::listFiles (java/io/File::new path))] + (case ?children + (#.Some children) + (|> children + array.to-list + (monad.filter @ (|>> )) + (:: @ map (monad.map @ (|>> java/io/File::getAbsolutePath (:: @ map )))) + (:: @ join)) + + #.None + (io.throw not-a-directory [path]))))] + + [files java/io/File::isFile File] + [directories java/io/File::isDirectory Directory] + )) (def: (discard _) (!delete path cannot-discard-directory))) (structure: #export _ (System IO) - (do-template [ ] - [(def: ( path) - (do io.Monad - [#let [file (java/io/File::new path)] - outcome ( file)] - (case outcome - (#error.Success #1) - (wrap (#error.Success ( path))) - - _ - (wrap (ex.throw [path])))))] - - [file java/io/File::isFile ..File cannot-find-file] - [create-file java/io/File::createNewFile ..File cannot-create-file] - [directory java/io/File::isDirectory ..Directory cannot-find-directory] - [create-directory java/io/File::mkdir ..Directory cannot-create-directory] - ) + (~~ (do-template [ ] + [(def: ( path) + (do io.Monad + [#let [file (java/io/File::new path)] + outcome ( file)] + (case outcome + (#error.Success #1) + (wrap (#error.Success ( path))) + + _ + (wrap (ex.throw [path])))))] + + [file java/io/File::isFile ..File cannot-find-file] + [create-file java/io/File::createNewFile ..File cannot-create-file] + [directory java/io/File::isDirectory ..Directory cannot-find-directory] + [create-directory java/io/File::mkdir ..Directory cannot-create-directory] + )) (def: separator (java/io/File::separator)) )) -- cgit v1.2.3