Passing list of variables individually to clojure function

前端 未结 2 1963
北海茫月
北海茫月 2021-01-13 13:52

I have been playing around with clojure, and decided to make a higher order function that combines mapcat and list to emulate this behavior:

Clojure> (ma         


        
2条回答
  •  死守一世寂寞
    2021-01-13 14:46

    You're right, the arguments are wrapped in a list as a result of the vararg declaration. You need to apply the arguments in order to unwrap the list of arguments:

    (defn mapcatList[& more]
      (apply mapcat list more))
    
    user=> (mapcatList '(1 2 3 4) '(5 6 7 8))               
    (1 5 2 6 3 7 4 8)
    user=> (mapcatList '(1 2 3 4) '(5 6 7 8) '(\a \b \c \d))
    (1 5 \a 2 6 \b 3 7 \c 4 8 \d)
    

提交回复
热议问题