Interesting situation in clojure
So I was trying to do something like this:
(defn bad-function [body]
(let [result “hello”]
body))
And then I tried to do something like this:
(bad-function (println result))
And it failed. I didn’t understand why it would failed since I do something very similar in our regular non-lisp languages.
I don’t fully understand what is the problem, but this is my guess: when the reader begins to apply (bad-function (println result)), it wants to apply the body at some point before the result binding happens.
I believe that if I am going to be able to do something like that, I am going to have to use macros.
I would like to know what exactly is going on though.
-
cabbagebot likes this
-
devscratchpad reblogged this from hackedy and added:
Thanks. I was suspecting something like that. Now I know. Ah, and I found a work around without having to use macros....
-
twitterbutlonger likes this
-
hackedy reblogged this from devscratchpad and added:
the problem is that the body is evaluated before being passed to the function. you want macros as an example (defn oh-no...
-
devscratchpad posted this