Note that there are some explanatory texts on larger screens.

plurals
  1. POCan clojure be made fully dynamic?
    text
    copied!<p>In clojure 1.1, all calls were dynamic, meaning that you could redefine a function at the REPL and it would be included in the running program automatically. This was also nice for things like dotrace.</p> <p>In clojure 1.2, many calls seem to be statically linked, and if I want to replace a function, Sometimes, I have to find all the places where it's called and put #' in front of them. </p> <p>Worse, I can't predict where I'll need to do this.</p> <p>Is it possible to go back to the old default of dynamic linking? Maybe if you needed the extra iota of speed you could switch it back on for the production app, but for development I much prefer the 1.1 behaviour.</p> <p>I'm hoping for some sort of compiler option like *warn-on-reflection*.</p> <p>Edit:</p> <p>I'm confused about what's going on. More specifically, here are two functions. I prefer the behaviour of the second. How can I make the first one behave like the second, as I believe it used to do in 1.1?</p> <pre><code>user&gt; (clojure-version) "1.2.0" user&gt; (defn factorial[n] (if (&lt; n 2) n (* n (factorial (dec n))))) #'user/factorial user&gt; (require 'clojure.contrib.trace) user&gt; (clojure.contrib.trace/dotrace (factorial) (factorial 10)) TRACE t1670: (factorial 10) TRACE t1670: =&gt; 3628800 user&gt; (defn factorial[n] (if (&lt; n 2) n (* n (#'factorial (dec n))))) #'user/factorial user&gt; (clojure.contrib.trace/dotrace (factorial) (factorial 10)) TRACE t1681: (factorial 10) TRACE t1682: | (factorial 9) TRACE t1683: | | (factorial 8) TRACE t1684: | | | (factorial 7) TRACE t1685: | | | | (factorial 6) TRACE t1686: | | | | | (factorial 5) TRACE t1687: | | | | | | (factorial 4) TRACE t1688: | | | | | | | (factorial 3) TRACE t1689: | | | | | | | | (factorial 2) TRACE t1690: | | | | | | | | | (factorial 1) TRACE t1690: | | | | | | | | | =&gt; 1 TRACE t1689: | | | | | | | | =&gt; 2 TRACE t1688: | | | | | | | =&gt; 6 TRACE t1687: | | | | | | =&gt; 24 TRACE t1686: | | | | | =&gt; 120 TRACE t1685: | | | | =&gt; 720 TRACE t1684: | | | =&gt; 5040 TRACE t1683: | | =&gt; 40320 TRACE t1682: | =&gt; 362880 TRACE t1681: =&gt; 3628800 3628800 </code></pre> <p>Edit (to the whole question, and a change of title):</p> <p>Joost points out below that what's actually going on here is that the self call in factorial is being optimized away. I can't see why that would be done, since you can't do that many recursive self calls without blowing the stack, but it explains the observed behaviour. Perhaps it's something to do with anonymous self-calls.</p> <p>The original reason for my question was that I was trying to write <a href="http://www.learningclojure.com/2011/03/hello-web-dynamic-compojure-web.html" rel="nofollow">http://www.learningclojure.com/2011/03/hello-web-dynamic-compojure-web.html</a>, and I got irritated with the number of places i had to type #' to get the behaviour I expected. That and the dotrace made me think that the general dynamic behaviour had gone and that the on the fly redefining, which works in some places, must be done with some clever hack. </p> <p>In retrospect that seems a strange conclusion to jump to, but now I'm just confused (which is better!). Are there any references for all this? I'd love to have a general theory of when this will work and when it won't. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload