title: Clojure Running Multiple Threads with Functions with zero or one input
body: <p>I'm experimenting in Clojure with running independent threads and I'm getting different behaviors I don't understand.</p>
  <p>For my code editor I'm using Atom (not emacs), REPL is Chlorine.</p>
  <p>I'm testing a really simple function that just prints numbers.
  This one prints from 100 to 1 and takes no inputs:</p>
  <pre><code>(defn pl100 []
    &quot;pl100 = Print Loop from 100 to 1&quot;
    (loop [counter 100]
      (when (pos? counter)
        (do
          (Thread/sleep 100)
          (println (str &quot;counter: &quot; counter))
          (recur (dec counter))))))
  </code></pre>
  <p>This one does the exact same thing, except it takes an input:</p>
  <pre><code>(defn pl-n [n]
      &quot;pl-n = Print Loop from n to 1&quot;
      (loop [counter n]
        (when (pos? counter)
          (do
            (Thread/sleep 100)
            (println (str &quot;counter: &quot; counter))
            (recur (dec counter))))))
  </code></pre>
  <p>When I use</p>
  <pre><code>(.start (Thread. #(.run pl100)))
  ; --&gt; prints to console REPL
  ; --&gt; runs with no errors
  </code></pre>
  <p>this code</p>
  <ol>
  <li>prints to the console REPL (where I call lein) and</li>
  <li>runs with no errors</li>
  </ol>
  <p>When I use</p>
  <pre><code>(.start (Thread. #(.run (pl-n 100))))
  ; prints to console REPL
  ; --&gt; java.lang.NullPointerException: Cannot invoke &quot;Object.getClass()&quot; because &quot;target&quot; is null
  </code></pre>
  <p>this code</p>
  <ol>
  <li>prints to the console REPL</li>
  <li>ends with the above exception</li>
  </ol>
  <p>When I use</p>
  <pre><code>(.start (Thread. pl100))
  ; --&gt; prints to the console REPL
  ; --&gt; runs with no errors  
  </code></pre>
  <p>this code</p>
  <ol>
  <li>prints to the console REPL</li>
  <li>runs with no errors</li>
  </ol>
  <p>When I use</p>
  <pre><code>(.start (Thread. (pl-n 100)))
  ; --&gt; prints to Atom REPL, not console REPL!
  ; ends with exception 
  ; Execution error (NullPointerException) at java.lang.Thread/&lt;init&gt; (Thread.java:396).
  ; name cannot be null
  ; class java.lang.NullPointerException
  </code></pre>
  <p>this code</p>
  <ol>
  <li>prints to the Atom REPL (I'm using Atom, not emacs)! Not to the console REPL like the others</li>
  <li>ends with exception</li>
  </ol>
  <p>So, can someone please help me understand:</p>
  <ol>
  <li>Why is it when I'm running a function that takes an input, Java gives an error? Why are the function calls not equivalent?</li>
  <li>What is (.run ...) doing?</li>
  <li>Why is it that sometimes the code prints to the console and other times to Atom/Chlorine?</li>
  </ol>