You're viewing version 1.2.0 of bound-fn. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

bound-fn

clojure.core

  • (bound-fn & fntail)
Returns a function defined by the given fntail, which will install the
same bindings in effect as in the thread at the time bound-fn was called.
This may be used to define a helper function which runs on a different
thread, but needs the same bindings in place.

1 Example top

  • (def ^:dynamic *some-var* nil)
    
    (defn f [] (println *some-var*))
    
    ;; run f without a new binding
    user=> (f)
    nil
    nil
    
    ;; run f with a new binding
    user=> (binding [*some-var* "hello"]
             (f))
    hello
    nil
    
    ;; run f in a thread with a new binding
    user=> (binding [*some-var* "goodbye"]
             (.start (Thread. f)))
    nil
    nil
    
    ;; run a bound f in a thread with a new binding
    user=> (binding [*some-var* "goodbye"]
             (.start (Thread. (bound-fn [] (f)))))
    goodbye
    nil
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:1525 top

(defmacro bound-fn
  "Returns a function defined by the given fntail, which will install the
  same bindings in effect as in the thread at the time bound-fn was called.
  This may be used to define a helper function which runs on a different
  thread, but needs the same bindings in place."
  {:added "1.1"}
  [& fntail]
  `(bound-fn* (fn ~@fntail)))
Vars in clojure.core/bound-fn: defmacro bound-fn* concat fn list seq
Used in 0 other vars

Comments top

No comments for bound-fn. Log in to add a comment.