1.3.0 permalink Arrow_down_16x16

letfn

clojure.core

  • (letfn fnspecs & body)
fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)

Takes a vector of function specs and a body, and generates a set of
bindings of functions to their names. All of the names are available
in all of the definitions of the functions, as well as the body.

1 Example top

  • user=> (letfn [(twice [x]
                     (* x 2))
                   (six-times [y]
                     (* (twice y) 3))]
             (println "Twice 15 =" (twice 15))
             (println "Six times 15 =" (six-times 15)))
    Twice 15 = 30
    Six times 15 = 90
    nil
    
    ;; Unable to resolve symbol: twice in this context
    user=> (twice 4)
    ; Evaluation aborted.
    
    ;; Unable to resolve symbol: six-times in this context
    user=> (six-times 100)
    ; Evaluation aborted.
    
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/let

    Evaluates the exprs in a lexical context in which the symbols in th

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:5751 top

(defmacro letfn 
  "fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)

  Takes a vector of function specs and a body, and generates a set of
  bindings of functions to their names. All of the names are available
  in all of the definitions of the functions, as well as the body."
  {:added "1.0", :forms '[(letfn [fnspecs*] exprs*)],
   :special-form true, :url nil}
  [fnspecs & body] 
  `(letfn* ~(vec (interleave (map first fnspecs) 
                             (map #(cons `fn %) fnspecs)))
           ~@body))
Vars in clojure.core/letfn:
Used in 0 other vars

Comments top

No comments for letfn. Log in to add a comment.