Dot product: Difference between revisions

Content added Content deleted
(Add Zig)
Line 2,253: Line 2,253:
echo dot_product(array(1, 3, -5), array(4, -2, -1)), "\n";
echo dot_product(array(1, 3, -5), array(4, -2, -1)), "\n";
?></lang>
?></lang>

=={{header|Picat}}==
<lang Picat>go =>
L1 = [1, 3, -5],
L2 = [4, -2, -1],

println(dot_product=dot_product(L1,L2)),
catch(println(dot_product([1,2,3,4],[1,2,3])),E, println(E)),
nl.

dot_product(L1,L2) = _, L1.length != L2.length =>
throw($dot_product_not_same_length(L1,L2)).
dot_product(L1,L2) = sum([L1[I]*L2[I] : I in 1..L1.length]).
</lang>

Output:
<pre>dot_product = 3
dot_product_not_same_length([1,2,3,4],[1,2,3])
</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==