From 4fc8cf01fc81906f448b2a610e624f9de48cfb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sved=C3=A4ng?= Date: Tue, 29 Mar 2016 13:05:00 +0200 Subject: [PATCH] pipe macros seem to work now... --- examples/project.carp | 3 --- lisp/baking_tests.carp | 21 +++++++++++++++++++++ lisp/core.carp | 4 ++-- lisp/core_tests.carp | 14 ++++++++++++++ src/eval.c | 3 ++- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/examples/project.carp b/examples/project.carp index c4175e3f..7b27eaf7 100644 --- a/examples/project.carp +++ b/examples/project.carp @@ -19,9 +19,6 @@ - - - ;; (defn f [] (fold add 0 &[1 2 3])) ;; (defn f [i] diff --git a/lisp/baking_tests.carp b/lisp/baking_tests.carp index c9de2f77..3f9c7101 100644 --- a/lisp/baking_tests.carp +++ b/lisp/baking_tests.carp @@ -242,3 +242,24 @@ (defn gimme-char () \e) + + +;; PIPE MACROS + +(defn baking-of-pipe-last-macro [] + (->> [10 20 30] + (map inc))) + +(defn test-baking-of-pipe-last-macro [] + (do (bake baking-of-pipe-last-macro) + (assert-eq "[11, 21, 31]" (str (baking-of-pipe-last-macro))))) + + +(defn baking-of-pipe-first-macro [] + (-> 10 + (- 2) + (* 2))) + +(defn test-baking-of-pipe-first-macro [] + (do (bake baking-of-pipe-first-macro) + (assert-eq 16 (baking-of-pipe-first-macro)))) diff --git a/lisp/core.carp b/lisp/core.carp index 9a1ccb52..92462ee2 100644 --- a/lisp/core.carp +++ b/lisp/core.carp @@ -302,8 +302,8 @@ (defn thread-last-internal [start-value forms] (match forms () start-value - ((f ... args) ... xs) (concat (list f) args (list (thread-first-internal start-value xs))) - (x ... xs) (list x (thread-first-internal start-value xs)))) + ((f ... args) ... xs) (concat (list f) args (list (thread-last-internal start-value xs))) + (x ... xs) (list x (thread-last-internal start-value xs)))) (defmacro ->> [start-value ... forms] (thread-last-internal start-value (reverse forms))) diff --git a/lisp/core_tests.carp b/lisp/core_tests.carp index 7aa696b0..a1a8f677 100644 --- a/lisp/core_tests.carp +++ b/lisp/core_tests.carp @@ -1,4 +1,16 @@ +(defn test-pipe-first [] + (assert-eq (list 7 8 9 10 11 12) + (-> 10 + (- 3) + (range 13)))) + +(defn test-pipe-last [] + (assert-eq 20 + (->> [3 4 5 6] + (reduce (fn [a b] (+ a b)) 0) + (- 38)))) + (defn test-sort [] (let [nums '(4 5 6 2 3 7 1)] (do @@ -413,6 +425,8 @@ (test-bind-to-function-in-let) (test-doubles) (test-sort) + (test-pipe-first) + (test-pipe-last) )) (run-core-tests) diff --git a/src/eval.c b/src/eval.c index 10abc06b..8699d847 100644 --- a/src/eval.c +++ b/src/eval.c @@ -415,7 +415,8 @@ void apply(Obj *function, Obj **args, int arg_count) { //printf("Calling function "); obj_print_cout(function); printf(" with params: "); obj_print_cout(function->params); printf("\n"); Obj *calling_env = obj_new_environment(function->env); - env_extend_with_args(calling_env, function, arg_count, args, false); + bool allow_rest_args = true; + env_extend_with_args(calling_env, function, arg_count, args, allow_rest_args); //printf("Lambda env: %s\n", obj_to_string(calling_env)->s); shadow_stack_push(function);