12 lines
286 B
Text
12 lines
286 B
Text
(let dotProduct (fun (v1 v2) {
|
|
(assert (= (len v1) (len v2)) "vectors should have the same length")
|
|
|
|
(mut result 0)
|
|
(mut i 0)
|
|
(while (< i (len v1)) {
|
|
(set result (+ result (* (@ v1 i) (@ v2 i))))
|
|
(set i (+ 1 i)) })
|
|
|
|
result }))
|
|
|
|
(print (dotProduct [1 3 -5] [4 -2 -1]))
|