Passing a function as an argument to a function.
Closed this issue · 2 comments
The following code generates some odd behaving C code.
(run
'(
(defn f1 [x](cljc.core/print x))
(defn f2 f)
(f2 f1)))
value_t *_COLON_fn15779 = make_closure (FN_NAME (main_exit_value15768), env);
VAR_NAME (cljc_DOT_core_SLASH_main_exit_value) = _COLON_fn15779;
value_t *_COLON_fn15788 = make_closure (FN_NAME (open15780), env);
VAR_NAME (cljc_DOT_uv_DOT_fs_SLASH_open) = _COLON_fn15788;
value_t *_COLON_fn15793 = make_closure (FN_NAME (f115789), env);
VAR_NAME (clojurec_DOT_core_test_SLASH_f1) = _COLON_fn15793;
value_t *_COLON_fn15799 = make_closure (FN_NAME (f215794), env);
VAR_NAME (clojurec_DOT_core_test_SLASH_f2) = _COLON_fn15799;
value_t *_COLON_invoke15800 = invoke1 (VAR_NAME (clojurec_DOT_core_test_SLASH_f2), VAR_NAME (clojurec_DOT_core_test_SLASH_f1));
invoke2 (_COLON_fn15793, _COLON_fn15799,_COLON_invoke15800);
return 0;
END_MAIN_CODE;
Looks like it invokes f2 with f1 on the 4th line from the bottom, and then turns around does it again on the 3rd from the bottom. On the 3rd from the bottom I get and exception.
run
requires a Clojure form, not a sequence of Clojure forms, i.e. your example should be
(run '(do
(defn f1 ...)
(defn f2 ...)
(f2 f1)))
Awesome. Thanks for taking the time to set me straight. Works like a champ!