From c12eeb2b91cc6944363476307ede89b3a6b0524a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 12 Jan 2017 20:07:56 -0400 Subject: - lux/math/simple macros can now work with more than 2 args at a time. --- stdlib/source/lux/math/simple.lux | 139 +++++++------------------------------- 1 file changed, 24 insertions(+), 115 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/math/simple.lux b/stdlib/source/lux/math/simple.lux index 9de6a54b0..111e5cc8c 100644 --- a/stdlib/source/lux/math/simple.lux +++ b/stdlib/source/lux/math/simple.lux @@ -48,10 +48,8 @@ (do-template [ ] [(syntax: #export ( [args ($_ s;alt - (s;seq s;symbol s;symbol) - (s;seq s;any s;any) - s;symbol - s;any + (s;seq (s;alt s;symbol s;any) + (s;some s;any)) s;end)]) ## {#;doc (doc (= ( +1 +2) ## ( +1 +2)) @@ -62,38 +60,7 @@ ## (= ( .1 .2) ## ( .1 .2)))} (case args - (+0 [x y]) - (do @ - [=x (resolve-type x) - =y (resolve-type y) - op (cond (and (check;checks? Nat =x) - (check;checks? Nat =y)) - (wrap (` )) - - (and (check;checks? Int =x) - (check;checks? Int =y)) - (wrap (` )) - - (and (check;checks? Real =x) - (check;checks? Real =y)) - (wrap (` )) - - (and (check;checks? Frac =x) - (check;checks? Frac =y)) - (wrap (` )) - - (compiler;fail (format "No operation for types: " (%type =x) " and " (%type =y))))] - (wrap (list (` ((~ op) (~ (ast;symbol x)) (~ (ast;symbol y))))))) - - (+1 [x y]) - (do @ - [g!x (compiler;gensym "g!x") - g!y (compiler;gensym "g!y")] - (wrap (list (` (let [(~ g!x) (~ x) - (~ g!y) (~ y)] - ( (~ g!x) (~ g!y))))))) - - (+2 x) + (+0 [(#;Left x) ys]) (do @ [=x (resolve-type x) op (cond (check;checks? Nat =x) @@ -108,16 +75,16 @@ (check;checks? Frac =x) (wrap (` )) - (compiler;fail (format "No operation for type: " (%type =x))))] - (wrap (list (` ((~ op) (~ (ast;symbol x))))))) + (compiler;fail (format "No operation for types: " (%type =x))))] + (wrap (list (` ($_ (~ op) (~ (ast;symbol x)) (~@ ys)))))) - (+3 x) + (+0 [(#;Right x) ys]) (do @ [g!x (compiler;gensym "g!x")] (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x))))))) + ( (~ g!x) (~@ ys))))))) - (+4 []) + (+1 []) (do @ [=e compiler;expected-type op (cond (check;checks? (-> Nat Nat Nat) =e) @@ -145,10 +112,8 @@ (do-template [ ] [(syntax: #export ( [args ($_ s;alt - (s;seq s;symbol s;symbol) - (s;seq s;any s;any) - s;symbol - s;any + (s;seq (s;alt s;symbol s;any) + (s;some s;any)) s;end)]) ## {#;doc (doc (= ( +1 +2) ## ( +1 +2)) @@ -159,38 +124,7 @@ ## (= ( .1 .2) ## ( .1 .2)))} (case args - (+0 [x y]) - (do @ - [=x (resolve-type x) - =y (resolve-type y) - op (cond (and (check;checks? Nat =x) - (check;checks? Nat =y)) - (wrap (` )) - - (and (check;checks? Int =x) - (check;checks? Int =y)) - (wrap (` )) - - (and (check;checks? Real =x) - (check;checks? Real =y)) - (wrap (` )) - - (and (check;checks? Frac =x) - (check;checks? Frac =y)) - (wrap (` )) - - (compiler;fail (format "No operation for types: " (%type =x) " and " (%type =y))))] - (wrap (list (` ((~ op) (~ (ast;symbol x)) (~ (ast;symbol y))))))) - - (+1 [x y]) - (do @ - [g!x (compiler;gensym "g!x") - g!y (compiler;gensym "g!y")] - (wrap (list (` (let [(~ g!x) (~ x) - (~ g!y) (~ y)] - ( (~ g!x) (~ g!y))))))) - - (+2 x) + (+0 [(#;Left x) ys]) (do @ [=x (resolve-type x) op (cond (check;checks? Nat =x) @@ -205,16 +139,16 @@ (check;checks? Frac =x) (wrap (` )) - (compiler;fail (format "No operation for type: " (%type =x))))] - (wrap (list (` ((~ op) (~ (ast;symbol x))))))) + (compiler;fail (format "No operation for types: " (%type =x))))] + (wrap (list (` ($_ (~ op) (~ (ast;symbol x)) (~@ ys)))))) - (+3 x) + (+0 [(#;Right x) ys]) (do @ [g!x (compiler;gensym "g!x")] (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x))))))) + ( (~ g!x) (~@ ys))))))) - (+4 []) + (+1 []) (do @ [=e compiler;expected-type op (cond (check;checks? (-> Nat Nat Bool) =e) @@ -242,40 +176,15 @@ (do-template [ ] [(syntax: #export ( [args ($_ s;alt - (s;seq s;symbol s;symbol) - (s;seq s;any s;any) - s;symbol - s;any + (s;seq (s;alt s;symbol s;any) + (s;some s;any)) s;end)]) ## {#;doc (doc (= ( +1 +2) ## ( +1 +2)) ## (= ( 1 2) ## ( 1 2)))} (case args - (+0 [x y]) - (do @ - [=x (resolve-type x) - =y (resolve-type y) - op (cond (and (check;checks? Nat =x) - (check;checks? Nat =y)) - (wrap (` )) - - (and (check;checks? Int =x) - (check;checks? Int =y)) - (wrap (` )) - - (compiler;fail (format "No operation for types: " (%type =x) " and " (%type =y))))] - (wrap (list (` ((~ op) (~ (ast;symbol x)) (~ (ast;symbol y))))))) - - (+1 [x y]) - (do @ - [g!x (compiler;gensym "g!x") - g!y (compiler;gensym "g!y")] - (wrap (list (` (let [(~ g!x) (~ x) - (~ g!y) (~ y)] - ( (~ g!x) (~ g!y))))))) - - (+2 x) + (+0 [(#;Left x) ys]) (do @ [=x (resolve-type x) op (cond (check;checks? Nat =x) @@ -284,16 +193,16 @@ (check;checks? Int =x) (wrap (` )) - (compiler;fail (format "No operation for type: " (%type =x))))] - (wrap (list (` ((~ op) (~ (ast;symbol x))))))) + (compiler;fail (format "No operation for types: " (%type =x))))] + (wrap (list (` ($_ (~ op) (~ (ast;symbol x)) (~@ ys)))))) - (+3 x) + (+0 [(#;Right x) ys]) (do @ [g!x (compiler;gensym "g!x")] (wrap (list (` (let [(~ g!x) (~ x)] - ( (~ g!x))))))) + ( (~ g!x) (~@ ys))))))) - (+4 []) + (+1 []) (do @ [=e compiler;expected-type op (cond (check;checks? (-> Nat Nat Nat) =e) -- cgit v1.2.3