简体   繁体   中英

clojure: override function application

Is it possible to override the behavior of function application in Clojure?

For instance I'd like to make a namespace where:

(+ 2 2)

Evaluates to the constant 5 via a macro like:

(defmacro app [& args] 5)

+ is just a function so you can, for your namespace, exclude referring to clojure.core/+ and then define your own addition function in that namespace.

Clojure does not offer a general hook for the concept of function application in this namespace. What the development tools do is read the namespace for all the symbols that contain functions, and then hook them with wrapping function that does the tracing. This only affects functions that exist in the namespace at the time this happens, so it's less general than what you are asking for.

see clojure.tools.trace and Robert Hooke for more examples of this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM