Clojure – why can’t let be used with vector?
•
Java
replace
(let [x 1] (my-expression))
I'm trying to use:
(let (vector x 1) (my-expression))
Don't ask why, I prefer ordinary parentheses But clojure said:
let requires a vector for its binding in ...
What's up?
Solution
Let special form binding form must be a vector literal, not just an expression evaluated as a vector
Why? Roughly speaking, an expression must be compiled before it can be evaluated At compile time (vector x 1) will not be evaluated as a vector, it will just be a list In fact, if you want to evaluate, the parameters of the vector will be evaluated, which means that x must be solved. However, you don't want x to be parsed, you want it to be bound
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码