Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idiomatic Clojure function alias

What would be the most idiomatic way to alias a function in Clojure ? And is there any difference in terms of execution between those two approaches ?

Example taken from Om (Clojurescript, but the syntax in Clojure would be the same):

(defn query->ast
  "Given a query expression convert it into an AST."
  [query-expr]
  (parser/query->ast query-expr))

(def query->ast
  "Given a query expression convert it into an AST."
  parser/query->ast)
like image 657
nha Avatar asked Dec 11 '15 16:12

nha


1 Answers

I prefer def to defn.

The defn version

  • has an interposed function call, which may or may not be elided;
  • is restricted to arity 1, whereas the def version has all the arities of the original.
like image 77
Thumbnail Avatar answered Nov 12 '22 04:11

Thumbnail