I don’t understand this code from the clojure 1.5 release notes. It uses the cond-> macro. For example, how would it translate into pre-1.5 code?
user=> (cond-> 1
true inc
false (* 42)
(= 2 2) (* 3))
6
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Each step changes the result if the test is true, or leaves it alone if the test is false.
You could write this in 1.4 by threading anonymous functions:
Though the
cond->does not introduce new functions, instead it generates a binding form to be more efficient:and uses a
gensymforgincase some of the forms use the symbolgcond->>is very similar, it just places the threaded symbol in a diferent place.which in this example gives the same result because
*and+are commutative.