开发者

Does "The whole language always available" hold in case of Clojure?

开发者 https://www.devze.com 2023-01-17 04:48 出处:网络
Ninth bullet point in Paul Graham\'s What Made Lisp Different says, 9. The whole language always available.

Ninth bullet point in Paul Graham's What Made Lisp Different says,

9. The whole language always available.

There is no real distinction between read-time, compile-time, and runtime. You can compile or run code while reading, read or run code while compiling, and read or co开发者_开发技巧mpile code at runtime.

Running code at read-time lets users reprogram Lisp's syntax; running code at compile-time is the basis of macros; compiling at runtime is the basis of Lisp's use as an extension language in programs like Emacs; and reading at runtime enables programs to communicate using s-expressions, an idea recently reinvented as XML.

Does this last bullet point hold for Clojure?


You can mix runtime and compile-time freely in Clojure, although Common Lisp is still somewhat more flexible here (due to the presence of compiler macros and symbol macros and a fully supported macrolet; Clojure has an advantage in its cool approach to macro hygiene through automagic symbol resolution in syntax-quote). The reader is currently closed, so the free mixing of runtime, compile-time and read-time is not possible1.


1 Except through unsupported clever hacks.


It does hold,

(eval (read-string "(println \"Hello World!!\")"))
Hello World!!
nil

Just like emacs you can have your program configuration in Clojure, one project that I know Clojure for is static which allows you to have your template as a Clojure vector along with arbitrary code which will be executed at read time.

0

精彩评论

暂无评论...
验证码 换一张
取 消