mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 20:49:05 +03:00
pipe macros seem to work now...
This commit is contained in:
parent
5cddb63db7
commit
4fc8cf01fc
@ -19,9 +19,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;; (defn f [] (fold add 0 &[1 2 3]))
|
||||
|
||||
;; (defn f [i]
|
||||
|
@ -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))))
|
||||
|
@ -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)))
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user