Defining a SPI in Clojure

前端 未结 2 1643
轻奢々
轻奢々 2021-01-14 04:09

I\'m looking for an idiomatic way(s) to define an interface in Clojure that can be implemented by an external \"service provider\". My application would locate and instanti

2条回答
  •  我在风中等你
    2021-01-14 04:41

    Clojure is a very dynamic language: almost anything that can be done at compile time can be done at runtime. Your "deployment configuration" could simply be a clojure source file that gets loaded into the application at runtime. Just call (load "my-config.clj"). Note that you can even override functions in a particular dynamic scope if you really want to, so you can wrap any function (including core functions) with another one that say logs their arguments, return value and how long they took to run. Have a look at clojure.contrib.trace for an example of how to do this.

提交回复
热议问题