apparent bug with binding (or contrib.sql ?) in current master branches

10 views
Skip to first unread message

Joost

unread,
Apr 15, 2010, 9:27:21 AM4/15/10
to Clojure
Hello,

The following works on the 1.1.0 release of both clojure and
clojure.contrib:

$ java -server -Djava.net.preferIPv4Stack=true -Dpid=30893 -
Djava.awt.headless=true -cp clojure-1.1.0/clojure.jar:clojure-
contrib-1.1.0/clojure-contrib.jar clojure.main
Clojure 1.1.0
user=> (use 'clojure.contrib.sql)
nil
user=> (binding [clojure.contrib.sql/do-commands #(prn %)
clojure.contrib.sql/do-prepared #(prn %1 %2)]
(do-commands "bla"))
"bla"
nil


But on the master branches I get:

$ java -server -Djava.net.preferIPv4Stack=true -Dpid=30893 -
Djava.awt.headless=true -cp /home/joost/lib/clojure/clojure-1.2.0-
master-SNAPSHOT.jar:/home/joost/lib/clojure-contrib/clojure-
contrib.jar clojure.main
Clojure 1.2.0-master-SNAPSHOT
user=> (use 'clojure.contrib.sql)
nil
user=> (binding [clojure.contrib.sql/do-commands #(prn %)
clojure.contrib.sql/do-prepared #(prn %1 %2)]
(do-commands "bla"))
java.lang.Exception: no current database connection (NO_SOURCE_FILE:0)

It looks like I can't bind do-commands... But this works:

user=> (defn test-me [] (prn "orig"))
#'user/test-me
user=> (binding [test-me #(prn "bound")] (test-me))
"bound"
nil

I have no idea what's going on.

Phil Hagelberg

unread,
Apr 15, 2010, 11:51:45 PM4/15/10
to clo...@googlegroups.com
On Thu, Apr 15, 2010 at 6:27 AM, Joost <jo...@zeekat.nl> wrote:
> But on the master branches I get:
>
> $ java -server -Djava.net.preferIPv4Stack=true  -Dpid=30893 -
> Djava.awt.headless=true -cp /home/joost/lib/clojure/clojure-1.2.0-
> master-SNAPSHOT.jar:/home/joost/lib/clojure-contrib/clojure-
> contrib.jar clojure.main
> Clojure 1.2.0-master-SNAPSHOT
> user=> (use 'clojure.contrib.sql)
> nil
> user=>  (binding [clojure.contrib.sql/do-commands #(prn %)
>          clojure.contrib.sql/do-prepared #(prn %1 %2)]
>          (do-commands "bla"))
> java.lang.Exception: no current database connection (NO_SOURCE_FILE:0)
>
> It looks like I can't bind do-commands... But this works:

This is due to a little-known feature in the current git master called
direct binding. Basically the value of any var bound to a function
inside any namespace beginning with "clojure" is fixed at compile
time, so there's no way to rebind it.

It's intended to give a performance boost since the step of var lookup
may be skipped, but it also has the side-effect of making you think
you're going a little crazy if you don't know about it. Unfortunately
right now there's no way to opt-out, though we've discussed some
mechanisms that might allow that in the future. It sounds like it
might get turned back off before 1.2 is released:

http://www.assembla.com/spaces/clojure/tickets/271-determine-direct-binding-policy-and-controls

The only workaround right now is to create your own function that
wraps the function you're trying to rebind and rebind your wrapper
instead.

-Phil

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Per Vognsen

unread,
Apr 16, 2010, 1:02:15 AM4/16/10
to clo...@googlegroups.com
Is there any written rationale for direct binding? It sounds like a
poor man's inlining, except we already have perfectly good opt-in
inlining.

If these screwy semantics are to remain, an absolute minimum courtesy
would be for 'binding' to throw an exception at macro expansion time
when one tries to rebind a var that matches the direct binding
criteria.

-Per
Reply all
Reply to author
Forward
0 new messages