This question is based solely on "mental skill" and probably has no practical value.
If I define a value in Clojure using def , can I get the compiler to evaluate it at compile time and not wait for runtime?
(def the-answer 42) (+ the-answer 1)
I suppose I can define a macro, but the call syntax is getting awkward:
(defmacro the-answer [] 42) (+ (the-answer) 1)
This also works, but is still ugly:
(+ `~the-answer 1)
I also understand (or believe) that Clojure evaluates constant expressions at compile time:
(def milliseconds-per-day (* 24 60 60 1000))
I am just learning Common Lisp, but I understand that Common Lisp supports custom reader macros, so you can define a reader macro (something like #$ ) that evaluates the following character at compile time:
(+
By the way, this syntax is not “prettier” than macros.
How to make Clojure evaluate constant var at compile time and replace the reference with the actual value? Is it already done?
Before anyone starts quoting Knuth Law (“premature optimization is the root of all evil”), I ask this question to better understand the internals of Clojure compilation.
Ralph
source share