From db697bb636e2341d26bb188cc1b9981a1ab505d7 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 7 May 2017 14:30:48 -0400 Subject: - Changed the name of "let%" to "with-expansions". --- stdlib/source/lux.lux | 51 ++++++++++++------------ stdlib/source/lux/concurrency/promise.lux | 42 ++++++++++---------- stdlib/source/lux/control/pipe.lux | 6 ++- stdlib/source/lux/data/coll/ordered.lux | 39 ++++++++++--------- stdlib/source/lux/data/format/json.lux | 56 ++++++++++++++------------- stdlib/source/lux/host.jvm.lux | 25 ++++++------ stdlib/source/lux/macro/poly.lux | 29 +++++++------- stdlib/source/lux/macro/poly/eq.lux | 27 ++++++------- stdlib/source/lux/macro/poly/text-encoder.lux | 27 ++++++------- 9 files changed, 159 insertions(+), 143 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index f530f9ca5..af5a0d142 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -5273,30 +5273,31 @@ (wrap (list (record$ =pairs)))) )) -(macro: #export (let% tokens) +(macro: #export (with-expansions tokens) {#;doc (doc "Controlled macro-expansion." "Bind an arbitraty number of ASTs resulting from macro-expansion to local bindings." "Wherever a binding appears, the bound ASTs will be spliced in there." (test: "AST operations & structures" - (let% [ (do-template [ ] - [(compare ) - (compare (:: AST/encode show )) - (compare true (:: Eq = ))] - - [(bool true) "true" [_ (#;Bool true)]] - [(bool false) "false" [_ (#;Bool false)]] - [(int 123) "123" [_ (#;Int 123)]] - [(real 123.0) "123.0" [_ (#;Real 123.0)]] - [(char #"\n") "#\"\\n\"" [_ (#;Char #"\n")]] - [(text "\n") "\"\\n\"" [_ (#;Text "\n")]] - [(tag ["yolo" "lol"]) "#yolo;lol" [_ (#;Tag ["yolo" "lol"])]] - [(symbol ["yolo" "lol"]) "yolo;lol" [_ (#;Symbol ["yolo" "lol"])]] - [(form (list (bool true) (int 123))) "(true 123)" (^ [_ (#;Form (list [_ (#;Bool true)] [_ (#;Int 123)]))])] - [(tuple (list (bool true) (int 123))) "[true 123]" (^ [_ (#;Tuple (list [_ (#;Bool true)] [_ (#;Int 123)]))])] - [(record (list [(bool true) (int 123)])) "{true 123}" (^ [_ (#;Record (list [[_ (#;Bool true)] [_ (#;Int 123)]]))])] - [(local-tag "lol") "#lol" [_ (#;Tag ["" "lol"])]] - [(local-symbol "lol") "lol" [_ (#;Symbol ["" "lol"])]] - )] + (with-expansions + [ (do-template [ ] + [(compare ) + (compare (:: AST/encode show )) + (compare true (:: Eq = ))] + + [(bool true) "true" [_ (#;Bool true)]] + [(bool false) "false" [_ (#;Bool false)]] + [(int 123) "123" [_ (#;Int 123)]] + [(real 123.0) "123.0" [_ (#;Real 123.0)]] + [(char #"\n") "#\"\\n\"" [_ (#;Char #"\n")]] + [(text "\n") "\"\\n\"" [_ (#;Text "\n")]] + [(tag ["yolo" "lol"]) "#yolo;lol" [_ (#;Tag ["yolo" "lol"])]] + [(symbol ["yolo" "lol"]) "yolo;lol" [_ (#;Symbol ["yolo" "lol"])]] + [(form (list (bool true) (int 123))) "(true 123)" (^ [_ (#;Form (list [_ (#;Bool true)] [_ (#;Int 123)]))])] + [(tuple (list (bool true) (int 123))) "[true 123]" (^ [_ (#;Tuple (list [_ (#;Bool true)] [_ (#;Int 123)]))])] + [(record (list [(bool true) (int 123)])) "{true 123}" (^ [_ (#;Record (list [[_ (#;Bool true)] [_ (#;Int 123)]]))])] + [(local-tag "lol") "#lol" [_ (#;Tag ["" "lol"])]] + [(local-symbol "lol") "lol" [_ (#;Symbol ["" "lol"])]] + )] (test-all ))))} (case tokens (^ (list& [_ (#Tuple bindings)] bodies)) @@ -5304,21 +5305,23 @@ (^ (list& [_ (#Symbol ["" var-name])] macro-expr bindings')) (do Monad [expansion (macro-expand-once macro-expr)] - (case (place-tokens var-name expansion (` (;let% [(~@ bindings')] (~@ bodies)))) + (case (place-tokens var-name expansion (` (;with-expansions + [(~@ bindings')] + (~@ bodies)))) (#Some output) (wrap output) _ - (fail "[let%] Improper macro expansion."))) + (fail "[with-expansions] Improper macro expansion."))) #Nil (return bodies) _ - (fail "Wrong syntax for let%")) + (fail "Wrong syntax for with-expansions")) _ - (fail "Wrong syntax for let%"))) + (fail "Wrong syntax for with-expansions"))) (def: (flatten-alias type) (-> Type Type) diff --git a/stdlib/source/lux/concurrency/promise.lux b/stdlib/source/lux/concurrency/promise.lux index ef3d28a29..edca7d05a 100644 --- a/stdlib/source/lux/concurrency/promise.lux +++ b/stdlib/source/lux/concurrency/promise.lux @@ -148,16 +148,17 @@ {#;doc "Heterogeneous alternative combinator."} (All [a b] (-> (Promise a) (Promise b) (Promise (| a b)))) (let [a|b (promise (Either ($ +0) ($ +1)))] - (let% [ (do-template [ ] - [(await (function [value] - (do Monad - [_ (resolve ( value) a|b)] - (wrap []))) - )] - - [left #;Left] - [right #;Right] - )] + (with-expansions + [ (do-template [ ] + [(await (function [value] + (do Monad + [_ (resolve ( value) a|b)] + (wrap []))) + )] + + [left #;Left] + [right #;Right] + )] (exec a|b)))) @@ -165,16 +166,17 @@ {#;doc "Homogeneous alternative combinator."} (All [a] (-> (Promise a) (Promise a) (Promise a))) (let [left||right (promise ($ +0))] - (let% [ (do-template [] - [(await [(function [value] - (do Monad - [_ (resolve value left||right)] - (wrap [])))] - )] - - [left] - [right] - )] + (with-expansions + [ (do-template [] + [(await [(function [value] + (do Monad + [_ (resolve value left||right)] + (wrap [])))] + )] + + [left] + [right] + )] (exec left||right)))) diff --git a/stdlib/source/lux/control/pipe.lux b/stdlib/source/lux/control/pipe.lux index 7c68c06f6..fb0273835 100644 --- a/stdlib/source/lux/control/pipe.lux +++ b/stdlib/source/lux/control/pipe.lux @@ -37,7 +37,8 @@ (|> 5 (@> [(i.+ @ @)])))} (wrap (list (fold (function [next prev] - (` (let% [(~ (ast;symbol ["" name])) (~ prev)] + (` (with-expansions + [(~ (ast;symbol ["" name])) (~ prev)] (~ next)))) prev body)))) @@ -53,7 +54,8 @@ [i.odd?] [(i.* 3)] [(_> -1)])))} (with-gensyms [g!temp] - (wrap (list (` (let% [(~ g!temp) (~ prev)] + (wrap (list (` (with-expansions + [(~ g!temp) (~ prev)] (cond (~@ (do Monad [[test then] branches] (list (` (|> (~ g!temp) (~@ test))) diff --git a/stdlib/source/lux/data/coll/ordered.lux b/stdlib/source/lux/data/coll/ordered.lux index 5ecf96781..c6fd5937f 100644 --- a/stdlib/source/lux/data/coll/ordered.lux +++ b/stdlib/source/lux/data/coll/ordered.lux @@ -105,9 +105,10 @@ (def: (balance-left-add parent self) (All [a] (-> (Node a) (Node a) (Node a))) - (let% [ (as-is (black (get@ #value parent) - (#;Some self) - (get@ #right parent)))] + (with-expansions + [ (as-is (black (get@ #value parent) + (#;Some self) + (get@ #right parent)))] (case (get@ #color self) #Red (case (get@ #left self) @@ -140,9 +141,10 @@ (def: (balance-right-add parent self) (All [a] (-> (Node a) (Node a) (Node a))) - (let% [ (as-is (black (get@ #value parent) - (get@ #left parent) - (#;Some self)))] + (with-expansions + [ (as-is (black (get@ #value parent) + (get@ #left parent) + (#;Some self)))] (case (get@ #color self) #Red (case (get@ #right self) @@ -203,18 +205,19 @@ (#;Some root) (let [reference (get@ #value root)] - (let% [ (do-template [ ] - [( reference elem) - (let [side-root (get@ root) - outcome (recur side-root)] - (if (is side-root outcome) - ?root - (#;Some ( (default (undefined) outcome) - root))))] - - [T/< #left add-left] - [T/> #right add-right] - )] + (with-expansions + [ (do-template [ ] + [( reference elem) + (let [side-root (get@ root) + outcome (recur side-root)] + (if (is side-root outcome) + ?root + (#;Some ( (default (undefined) outcome) + root))))] + + [T/< #left add-left] + [T/> #right add-right] + )] (cond ## (T/= reference elem) diff --git a/stdlib/source/lux/data/format/json.lux b/stdlib/source/lux/data/format/json.lux index 41654d93d..535de1b53 100644 --- a/stdlib/source/lux/data/format/json.lux +++ b/stdlib/source/lux/data/format/json.lux @@ -773,15 +773,16 @@ (poly: #hidden (Codec//encode *env* :x:) (let [->Codec//encode (: (-> AST AST) (function [.type.] (` (-> (~ .type.) JSON))))] - (let% [ (do-template [ ] - [(do @ [_ ( :x:)] (wrap (` (: (~ (->Codec//encode (` ))) ))))] - - [Unit poly;unit (function [(~ (ast;symbol ["" "0"]))] #Null)] - [Bool poly;bool ;;gen-boolean] - [Int poly;int (|>. ;int-to-real ;;gen-number)] - [Real poly;real ;;gen-number] - [Char poly;char (|>. char;as-text ;;gen-string)] - [Text poly;text ;;gen-string])] + (with-expansions + [ (do-template [ ] + [(do @ [_ ( :x:)] (wrap (` (: (~ (->Codec//encode (` ))) ))))] + + [Unit poly;unit (function [(~ (ast;symbol ["" "0"]))] #Null)] + [Bool poly;bool ;;gen-boolean] + [Int poly;int (|>. ;int-to-real ;;gen-number)] + [Real poly;real ;;gen-number] + [Char poly;char (|>. char;as-text ;;gen-string)] + [Text poly;text ;;gen-string])] ($_ macro;either (with-gensyms [g!type-fun g!case g!input g!key g!val] @@ -924,24 +925,25 @@ (poly: #hidden (Codec//decode *env* :x:) (let [->Codec//decode (: (-> AST AST) (function [.type.] (` (-> JSON (Error (~ .type.))))))] - (let% [ (do-template [ ] - [(do @ [_ ( :x:)] (wrap (` (: (~ (->Codec//decode (` ))) ))))] - - [Unit poly;unit ;;unit] - [Bool poly;bool ;;bool] - [Int poly;int ;;int] - [Real poly;real ;;real] - [Char poly;char ;;char] - [Text poly;text ;;text]) - (do-template [ ] - [(do @ - [:sub: ( :x:) - .sub. (Codec//decode *env* :sub:)] - (wrap (` (: (~ (->Codec//decode (type;to-ast :x:))) - ( (~ .sub.))))))] - - [Maybe poly;maybe ;;nullable] - [List poly;list ;;array])] + (with-expansions + [ (do-template [ ] + [(do @ [_ ( :x:)] (wrap (` (: (~ (->Codec//decode (` ))) ))))] + + [Unit poly;unit ;;unit] + [Bool poly;bool ;;bool] + [Int poly;int ;;int] + [Real poly;real ;;real] + [Char poly;char ;;char] + [Text poly;text ;;text]) + (do-template [ ] + [(do @ + [:sub: ( :x:) + .sub. (Codec//decode *env* :sub:)] + (wrap (` (: (~ (->Codec//decode (type;to-ast :x:))) + ( (~ .sub.))))))] + + [Maybe poly;maybe ;;nullable] + [List poly;list ;;array])] ($_ macro;either (with-gensyms [g!type-fun g!case g!input g!key g!val] diff --git a/stdlib/source/lux/host.jvm.lux b/stdlib/source/lux/host.jvm.lux index 2aa352cf7..96853e6f5 100644 --- a/stdlib/source/lux/host.jvm.lux +++ b/stdlib/source/lux/host.jvm.lux @@ -683,18 +683,19 @@ (wrap (#GenericWildcard (#;Some [bound-kind bound]))))) (do s;Monad [name (full-class-name^ imports)] - (let% [ (do-template [ ] - [(Text/= name) - (wrap (#GenericClass (list)))] - - ["[Z" "Boolean-Array"] - ["[B" "Byte-Array"] - ["[S" "Short-Array"] - ["[I" "Int-Array"] - ["[J" "Long-Array"] - ["[F" "Float-Array"] - ["[D" "Double-Array"] - ["[C" "Char-Array"])] + (with-expansions + [ (do-template [ ] + [(Text/= name) + (wrap (#GenericClass (list)))] + + ["[Z" "Boolean-Array"] + ["[B" "Byte-Array"] + ["[S" "Short-Array"] + ["[I" "Int-Array"] + ["[J" "Long-Array"] + ["[F" "Float-Array"] + ["[D" "Double-Array"] + ["[C" "Char-Array"])] (cond (member? text;Eq (map product;left type-vars) name) (wrap (#GenericTypeVar name)) diff --git a/stdlib/source/lux/macro/poly.lux b/stdlib/source/lux/macro/poly.lux index 3252cfeeb..decc25b93 100644 --- a/stdlib/source/lux/macro/poly.lux +++ b/stdlib/source/lux/macro/poly.lux @@ -63,20 +63,21 @@ (def: #export primitive (Matcher Type) (;function [:type:] - (let% [ (do-template [ ] - [(do Monad - [_ ( :type:)] - (wrap ))] - - [void Void] - [unit Unit] - [bool Bool] - [nat Nat] - [int Int] - [deg Deg] - [real Real] - [char Char] - [text Text])] + (with-expansions + [ (do-template [ ] + [(do Monad + [_ ( :type:)] + (wrap ))] + + [void Void] + [unit Unit] + [bool Bool] + [nat Nat] + [int Int] + [deg Deg] + [real Real] + [char Char] + [text Text])] ($_ macro;either )))) diff --git a/stdlib/source/lux/macro/poly/eq.lux b/stdlib/source/lux/macro/poly/eq.lux index a26566e79..dc3b84cce 100644 --- a/stdlib/source/lux/macro/poly/eq.lux +++ b/stdlib/source/lux/macro/poly/eq.lux @@ -35,20 +35,21 @@ (poly: #export (Eq env :x:) (let [->Eq (: (-> AST AST) (function [.type.] (` (eq;Eq (~ .type.)))))] - (let% [ (do-template [ ] - [(do @ - [_ ( :x:)] - (wrap (` (: (~ (->Eq (` ))) - ))))] + (with-expansions + [ (do-template [ ] + [(do @ + [_ ( :x:)] + (wrap (` (: (~ (->Eq (` ))) + ))))] - [Unit poly;unit (function [(~' test) (~' input)] true)] - [Bool poly;bool bool;Eq] - [Nat poly;nat number;Eq] - [Int poly;int number;Eq] - [Deg poly;deg number;Eq] - [Real poly;real number;Eq] - [Char poly;char char;Eq] - [Text poly;text text;Eq])] + [Unit poly;unit (function [(~' test) (~' input)] true)] + [Bool poly;bool bool;Eq] + [Nat poly;nat number;Eq] + [Int poly;int number;Eq] + [Deg poly;deg number;Eq] + [Real poly;real number;Eq] + [Char poly;char char;Eq] + [Text poly;text text;Eq])] ($_ macro;either ## Primitive types diff --git a/stdlib/source/lux/macro/poly/text-encoder.lux b/stdlib/source/lux/macro/poly/text-encoder.lux index 21215d851..10fd85ebe 100644 --- a/stdlib/source/lux/macro/poly/text-encoder.lux +++ b/stdlib/source/lux/macro/poly/text-encoder.lux @@ -36,20 +36,21 @@ (poly: #export (Codec::encode env :x:) (let [->Codec::encode (: (-> AST AST) (function [.type.] (` (-> (~ .type.) Text))))] - (let% [ (do-template [ ] - [(do @ - [_ ( :x:)] - (wrap (` (: (~ (->Codec::encode (` ))) - (~' )))))] + (with-expansions + [ (do-template [ ] + [(do @ + [_ ( :x:)] + (wrap (` (: (~ (->Codec::encode (` ))) + (~' )))))] - [Unit poly;unit (function [_0] "[]")] - [Bool poly;bool (:: bool;Codec encode)] - [Nat poly;nat (:: number;Codec encode)] - [Int poly;int (:: number;Codec encode)] - [Deg poly;deg (:: number;Codec encode)] - [Real poly;real (:: number;Codec encode)] - [Char poly;char (:: char;Codec encode)] - [Text poly;text (:: text;Codec encode)])] + [Unit poly;unit (function [_0] "[]")] + [Bool poly;bool (:: bool;Codec encode)] + [Nat poly;nat (:: number;Codec encode)] + [Int poly;int (:: number;Codec encode)] + [Deg poly;deg (:: number;Codec encode)] + [Real poly;real (:: number;Codec encode)] + [Char poly;char (:: char;Codec encode)] + [Text poly;text (:: text;Codec encode)])] ($_ macro;either ## Primitives -- cgit v1.2.3