Can anyone explain why I can rebind list but not +?
(binding [list vector]
(list 1 3))
(binding [list +]
(list 1 3))
(binding [+ list]
(+ 1 3))
I’d like to rebind + so I can do partial evaluation.
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.
In Clojure 1.1.0 at least,
+with two arguments is inlined for performance. Your binding happens too late. With more arguments it works differently.One workaround is to make your own namespace and shadow
clojure.core/+with your own function.Note that inlining appears to happen even more aggressively in the current snapshot of Clojure 1.2.0.
It may be wisest to use a function name other than
+, e.g.add, to avoid confusion.