What is: Inline keyword in Clojure functions?

I found this piece of code in the Clojure source code:

(defn == "Returns non-nil if nums all have the equivalent value (type-independent), otherwise false" {:inline (fn [xy] `(. clojure.lang.Numbers (equiv ~x ~y))) :inline-arities #{2} :added "1.0"} ..... 

What does :inline ?

Update : also found a good example here .

+5
source share
1 answer

The built-in definition of a Clojure function allows the compiler to view the operator as a macro, not as a function. The problem is that you have to provide a separate macro body that should have nothing to do with the function body. You can define the embedded version + that actually did - !

This is very doubtful and completely undocumented. It seems to be used to install faster code for small core functions.


In contrast, in C ++, inline is a hint for the compiler to consider the built-in extension of any function call. Expanding a string requires the same semantics as a regular function call. Functions of accessories and mutators are often built-in.

It is odd to find an aspect of the Clojure language with soggier semantics than the corresponding C ++.


I thought the function was deprecated. Is not. This is a similar definline operator, which is not obsolete, but experimental. To be obsolete, it would have to be created in the first place, and it never reached this stage.


I am grateful to Alan Malo for the corrections above.

+6
source

Source: https://habr.com/ru/post/1268355/


All Articles