Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macros 区别于-&燃气轮机&引用;及-&燃气轮机&燃气轮机&引用;在Clojure_Macros_Clojure - Fatal编程技术网

Macros 区别于-&燃气轮机&引用;及-&燃气轮机&燃气轮机&引用;在Clojure

Macros 区别于-&燃气轮机&引用;及-&燃气轮机&燃气轮机&引用;在Clojure,macros,clojure,Macros,Clojure,宏->和->之间有什么区别: user> (macroexpand-1 '(->> 1 a b c)) ;; => (c (b (a 1))) user> (macroexpand-1 '(-> 1 a b c)) ;; => (c (b (a 1))) 让我们看看源代码: user> (clojure.repl/source ->) (defmacro -> "Threads the expr through the forms

->
->
之间有什么区别:

user> (macroexpand-1 '(->> 1 a b c))
;; => (c (b (a 1)))
user> (macroexpand-1 '(-> 1 a b c))
;; => (c (b (a 1)))
让我们看看源代码:

user> (clojure.repl/source ->)
(defmacro ->
  "Threads the expr through the forms. Inserts x as the
  second item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  second item in second form, etc."
  {:added "1.0"}
  [x & forms]
  (loop [x x, forms forms]
    (if forms
      (let [form (first forms)
            threaded (if (seq? form)
                       (with-meta `(~(first form) ~x ~@(next form))
                                   (meta form))
                       (list form x))]
        (recur threaded (next forms)))
      x)))
;; => nil

user> (clojure.repl/source ->>)
(defmacro ->>
  "Threads the expr through the forms. Inserts x as the
  last item in the first form, making a list of it if it is not a
  list already. If there are more forms, inserts the first form as the
  last item in second form, etc."
  {:added "1.1"}
  [x & forms]
  (loop [x x, 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)))
;; => nil
(这是我的。)


所以,
->
比较老,但是看起来很像。。。有没有重复的原因?

这两个宏在处理带有更多参数的线程形式时是不同的。请尝试以下尺寸:

(macroexpand '(->> 1 (a b) (c d e) (f g h i)))
(macroexpand '(-> 1 (a b) (c d e) (f g h i)))

这两个宏在处理带有进一步参数的线程形式时是不同的。请尝试以下尺寸:

(macroexpand '(->> 1 (a b) (c d e) (f g h i)))
(macroexpand '(-> 1 (a b) (c d e) (f g h i)))

这两个宏在处理带有进一步参数的线程形式时是不同的。请尝试以下尺寸:

(macroexpand '(->> 1 (a b) (c d e) (f g h i)))
(macroexpand '(-> 1 (a b) (c d e) (f g h i)))

这两个宏在处理带有进一步参数的线程形式时是不同的。请尝试以下尺寸:

(macroexpand '(->> 1 (a b) (c d e) (f g h i)))
(macroexpand '(-> 1 (a b) (c d e) (f g h i)))

阅读描述
->
将事物作为每个表单中的第二项插入,
->
将事物作为每个表单中的最后一项插入。如果表单一开始只有一个项目,那么它们是等价的。在代码中,
(~(first form)~x~@(next form))
(~(first form)~@(next form)~x)
不同,因为
~x
位于不同的位置(第二位与最后一位)。@Barmar,我的坏朋友,我一直没有注意到。ClojureDocs经常帮助你做例子,解释和代码:看和读描述
->
将事物作为每个表单中的第二项插入,
->
将事物作为每个表单中的最后一项插入。如果表单一开始只有一个项目,那么它们是等价的。在代码中,
(~(first form)~x~@(next form))
(~(first form)~@(next form)~x)
不同,因为
~x
位于不同的位置(第二位与最后一位)。@Barmar,我的坏朋友,我一直没有注意到。ClojureDocs经常帮助你做例子,解释和代码:看和读描述
->
将事物作为每个表单中的第二项插入,
->
将事物作为每个表单中的最后一项插入。如果表单一开始只有一个项目,那么它们是等价的。在代码中,
(~(first form)~x~@(next form))
(~(first form)~@(next form)~x)
不同,因为
~x
位于不同的位置(第二位与最后一位)。@Barmar,我的坏朋友,我一直没有注意到。ClojureDocs经常帮助你做例子,解释和代码:看和读描述
->
将事物作为每个表单中的第二项插入,
->
将事物作为每个表单中的最后一项插入。如果表单一开始只有一个项目,那么它们是等价的。在代码中,
(~(first form)~x~@(next form))
(~(first form)~@(next form)~x)
不同,因为
~x
位于不同的位置(第二位与最后一位)。@Barmar,我的坏朋友,我一直不注意。ClojureDocs通常有助于示例以及解释和代码:查看和。使用
clojure.walk/macroexpand all
可能更好。使用
clojure.walk/macroexpand all
可能更好。使用
clojure.walk/macroexpand all
更好,也许。最好使用
clojure.walk/macroexpand all