Skip to content

Instantly share code, notes, and snippets.



Created Jul 19, 2012
What would you like to do?
A simple function to add vectors. Zero pads vectors to the length of the longest
(defn vec+
([] nil)
([v1] v1)
([v1 v2]
(let [c1 (count v1)
c2 (count v2)
seq (if (< c1 c2)
(map + (concat v1 (repeat 0)) v2)
(map + (concat v2 (repeat 0)) v1))]
(vec seq)))
([ v1 v2 & vn]
(reduce vec+ (vec+ v1 v2) vn)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment