About the source - >>

I was looking at the source of clojure.core:

(defmacro ->> [x & forms] (loop [xx, forms forms] (if forms (let [form (first forms) threaded (if (seq? form) (with-meta `(~(first form) ~@ (next form) ~x) (meta form)) (list form x))] (recur threaded (next forms))) x))) 

In line 7 why not just

 (with-meta `( ~@form ~x) (meta form)) 
+6
source share
1 answer

It is almost equivalent, but not quite. Consider what happens if the form is (incorrectly) () . As written, this error gets at compile time, because it does not allow to evaluate (nil x) . With the proposed simplification, an error will be noticed at runtime, or perhaps never at all, if x is a function with no arguments.

Leaving aside correctness, this is also better for readability, as it emphasizes what the first form will be called and the rest as arguments. It is also a prettier symmetry with the implementation -> .

+7
source

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


All Articles