Problem with passing a vector as a binding to the for macro

后端 未结 4 1069
野性不改
野性不改 2021-02-20 06:13

I have an arbitrary number of lists which I would like to process using the for macro. I want to create a function that passes a vector as the binding since the number of lists

4条回答
  •  时光取名叫无心
    2021-02-20 06:27

    The key is that for is a macro. At macro-expansion time, testvector is a symbol. It will evaluate to a vector at evaluation time, but it's not a vector from the perspective of the for macro.

    user=> (defmacro tst [v] (vector? v))
    #'user/tst
    user=> (tst testvector)
    false
    user=> (vector? testvector)
    true
    user=> (defmacro tst2 [v] `(vector? ~v))
    #'user/tst2
    user=> (tst2 testvector)
    true
    

    If you check the source for the for macro (in core.clj), you'll see that for uses an unquoted vector? call, just like tst in the example above.

提交回复
热议问题