From 4808ec4dd27afc06fb949166ce2ba7c52657feff Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 4 Sep 2017 20:10:43 -0400 Subject: - $_ and _$ macros now handle better "operator" code that is a form. e.g. ($_ (::: +) 1 2 3) => (::: + 1 (::: + 2 3)) instead of ((::: +) 1 ((::: +) 2 3)) --- stdlib/source/lux.lux | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/stdlib/source/lux.lux b/stdlib/source/lux.lux index d29e4fca5..641e8693d 100644 --- a/stdlib/source/lux.lux +++ b/stdlib/source/lux.lux @@ -1485,6 +1485,16 @@ #Nil ys)) +(def:''' (_$_joiner op a1 a2) + #;Nil + (-> Code Code Code Code) + (_lux_case op + [_ (#Form parts)] + (form$ (List/append parts (list a1 a2))) + + _ + (form$ (list op a1 a2)))) + (macro:' #export (_$ tokens) (#Cons [["lux" "doc"] (#TextA "## Left-association for the application of binary functions over variadic arguments. (_$ Text/append \"Hello, \" name \".\\nHow are you?\") @@ -1496,9 +1506,7 @@ (#Cons op tokens') (_lux_case tokens' (#Cons first nexts) - (return (list (fold (function' [a1 a2] (form$ (list op a1 a2))) - first - nexts))) + (return (list (fold (_$_joiner op) first nexts))) _ (fail "Wrong syntax for _$")) @@ -1517,9 +1525,7 @@ (#Cons op tokens') (_lux_case (reverse tokens') (#Cons last prevs) - (return (list (fold (function' [a1 a2] (form$ (list op a1 a2))) - last - prevs))) + (return (list (fold (_$_joiner op) last prevs))) _ (fail "Wrong syntax for $_")) -- cgit v1.2.3