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

后端 未结 4 1048
野性不改
野性不改 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:35

    Although not a solution to your problem, it should be noted that what you are doing can more easily be achieved with map rather than for e.g.

    user=> (def list1 '("pink" "green"))
    #'user/list1
    user=> (def list2 '("dog" "cat"))
    #'user/list2
    user=> (map #(str %1 "-" %2) list1 list2)
    ("pink-dog" "green-cat")
    user=> 
    

    Another useful technique when learning and experimenting is to use keywords rather than strings. This can reduce typing i.e. no need to put the values in quotes and can sometimes help identify errors more easily. Instead of (def list1 '("pink" "green")) you can just do (def list1 '(:pink :green)). Even better, rather than using lists, try using vectors and then you don't have to quote it (saving another keystroke).

提交回复
热议问题