ClojureDocs

Nav

Namespaces

definline

clojure.core

Available since 1.0 (source)
  • (definline name & decl)
Experimental - like defmacro, except defines a named function whose
body is the expansion, calls to which may be expanded inline as if
it were a macro. Cannot be used with variadic (&) args.
0 Examples
No examples for clojure.core/definline.
See Also

Like defn, but the resulting function name is declared as a macro and will be used as a macro by t...

Added by KingMob
2 Notes
    By , created 12.4 years ago

    Note that, as for macros, the arguments to definline are potentially subject to double evaluation if they are used more than once in the body. For example:

    user=> (definline bad-sqr [x] `(* ~x ~x))
    #'user/bad-sqr
    user=> (bad-sqr (do (println "x") 5))
    x
    x
    25
    
    By , created 11.4 years ago

    Any non-like-a-function behaviour should be avoided, because otherwise function will behave differently depending on whether it's inlined or not:

    user=> (definline bad-if [cond then] `(if ~cond ~then))
    #'user/bad-if
    user=> (bad-if nil (do (prn :side-effect) :not-returned))
    nil
    user=> (let [bad-if bad-if] (bad-if nil (do (prn :side-effect)     :not-returned)))
    :side-effect
    nil