您可以map
用来实现它。
我在这里使用lambda表达式来定义一个仅接受一个参数的函数。
(defn f [x y ] (...) )
// apply f x y to every element of xs
// in order to do this we need a function which takes only one argument the x_i and takes the second argument from somehere else - the second argument of g
// that's what the lambda \x -> f x y does - in short form.
(defn g [xs y] (map (fn [x] (f x y)) xs))
例如
(def X [1 2 3 4])
(defn f [x y] (* x y))
(g X 3)
;=> (3 6 9 12)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句