Is this a partial closure function?

I am discussing closure with a friend, and he thinks that (partial + 5)is closure. But I think closure is a function that closes a free variable, like

(let [a 10]
  (defn func1 [x] (+ x a))
)

then it func1is a closure. But in this case is 5not a free variable. So what is the correct answer?

+5
source share
2 answers

partialuses closure for a partial function. Check the code partialusing (source partial)repl and you will see that it uses closure.

(defn partial
  "Takes a function f and fewer than the normal arguments to f, and
  returns a fn that takes a variable number of additional args. When
  called, the returned function calls f with args + additional args."
  {:added "1.0"}
  ([f arg1]
   (fn [& args] (apply f arg1 args)))
  ([f arg1 arg2]
   (fn [& args] (apply f arg1 arg2 args)))
  ([f arg1 arg2 arg3]
   (fn [& args] (apply f arg1 arg2 arg3 args)))
  ([f arg1 arg2 arg3 & more]
   (fn [& args] (apply f arg1 arg2 arg3 (concat more args)))))
+7
source

(partial + 5) - an anonymous function or "lambda".

"", ; . " " "" "?"


[¹] , , , , , .

0

All Articles