Some vars protected from binding?

2 views
Skip to first unread message

Jacek Generowicz

unread,
Jan 19, 2010, 7:45:11 AM1/19/10
to Clojure
(def ++ +)
(defn foo-core [a b] (+ a b))
(defn foo-user [a b] (++ a b))
(binding [+ -
++ -]
[(foo-core 1 1) (foo-user 1 1)])

Gives the result:

[2 0]

which suggests that some vars are immune to binding.

Could someone please point me to the chapter and verse describing
this?

Thanks.

Meikel Brandmeyer

unread,
Jan 19, 2010, 11:33:01 AM1/19/10
to Clojure
Hi,

On Jan 19, 1:45 pm, Jacek Generowicz <jacek.generow...@googlemail.com>
wrote:

The two argument version of some functions like + or - are inlined. So
in foo-core the function is inlined and the Var is actually not
referenced. Try with three arguments and you will get the expected
result.

Sincerely
Meikel

Phil Hagelberg

unread,
Jan 19, 2010, 3:40:53 PM1/19/10
to clo...@googlegroups.com
Jacek Generowicz <jacek.ge...@googlemail.com> writes:

This is also affected by direct binding. It's not documented anywhere
outside the IRC logs to my knowledge, but if you look at line 2818 of
Compiler.java you can see the criteria whereby certain vars are made
"direct", improving the call-time performance, but making it impossible
to rebind them.

Currently all vars inside a namespace that begins with clojure with root
bindings that are functions are subject to this feature, though this
criteria will hopefully change in the future.

-Phil

Reply all
Reply to author
Forward
0 new messages