Why should I use 'apply' in Clojure?

后端 未结 6 1733
执念已碎
执念已碎 2021-01-30 08:34

This is what Rich Hickey said in one of the blog posts but I don\'t understand the motivation in using apply. Please help.

A big difference between Clojur

6条回答
  •  失恋的感觉
    2021-01-30 09:20

    The terms Lisp-1 and Lisp-2 refer to whether functions are in the same namespace as variables.

    In a Lisp-2 (that is, 2 namespaces), the first item in a form will be evaluated as a function name — even if it's actually the name of a variable with a function value. So if you want to call a variable function, you have to pass the variable to another function.

    In a Lisp-1, like Scheme and Clojure, variables that evaluate to functions can go in the initial position, so you don't need to use apply in order to evaluate it as a function.

提交回复
热议问题