Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a Clojure future without it running

Tags:

clojure

future

I have a basic Clojure script containing:

(def test
    (future
        (loop []
            (println "Running")
            (recur))))

However, if I execure the file with:

java -cp clojure-1.3.0.jar clojure.main test.clj

Then the screen fills with "Running". How can I change it so the future runs when I want it?

Note: I realise this will run forever, it's just an example of my problem.

like image 723
Dean Barnes Avatar asked Dec 16 '11 08:12

Dean Barnes


1 Answers

A future that doesn't run immediately is just a function with no arguments.

So:

(defn test []
  (println "Running")
  (recur))

...Later...

(future (test))
like image 174
amalloy Avatar answered Nov 08 '22 12:11

amalloy