How does the Clojure optimizer work, and where is it?

I am new to Clojure, but not up to lisp. Several constructive solutions look strange to me - in particular, you need a vector for the function parameters and explicitly request tail calls using recur.

Translating lists to vectors (and vice versa) is a standard operation for the optimizer. The tail can be converted to iteration by overwriting it in an equivalent clojure before compiling to byte code. The syntax [] and recur suggest that none of these optimizations are present in the current implementation.

I need a pointer to where in the implementation I can find any / all conversions from source to source. I don't speak Java very well, so I try to switch to a codebase.

If there is no optimization before functional conversion to JVM bytecode, I would be interested to justify this. Perhaps to speed up compilation?

Thanks.

+4
source share
2 answers

There is no explicit optimizer package in the compiler code. Any optimizations are done inline. Some of them can be turned on or off using compiler flags.


Note that literal vectors for function parameters are a syntactic choice, as functions are represented in the source code. Whether they are represented as vectors or a list or something else will not affect the runtime and cannot be optimized.

recur, Rich Hickey :

, , . JVM Java (.. ..).

( , , ), , , , , , . , recur.

. , .

"" . , recur .

+6

,

lisps . , "" . "" . , , . , .

Clojure lisp . , , , , , , , . , cond, , , . , .

. , , , , - , . defn:

https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L296

, , .

+1

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


All Articles