Task

Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors.

If possible, make the vectors of arbitrary length.



As an example, compute the dot product of the vectors:

     [1,  3, -5]       and 
     [4, -2, -1]   


If implementing the dot product of two vectors directly:

   each vector must be the same length
   multiply corresponding terms from each vector
   sum the products   (to produce the answer)


Related task

   Vector products


To run:
Start up.
Make an example vector and another example vector.
Compute a dot product of the example vector and the other example vector.
Destroy the example vector. Destroy the other example vector.
Convert the dot product to a string.
Write the string on the console.
Wait for the escape key.
Shut down.
 
An element is a thing with a number.
 
A vector is some elements.
 
To add a number to a vector:
Allocate memory for an element.
Put the number into the element's number.
Append the element to the vector.
 
To multiply a vector by another vector:
If the vector's count is not the other vector's count, exit.
Get an element from the vector.
Get another element from the other vector.
Loop.
If the element is nil, exit.
Multiply the element's number by the other element's number.
Put the element's next into the element.
Put the other element's next into the other element.
Repeat.
 
A sum is a number.
 
To find a sum of a vector:
Get an element from the vector.
Loop.
If the element is nil, exit.
Add the element's number to the sum.
Put the element's next into the element.
Repeat.
 
A product is a number.
 
To compute a dot product of a vector and another vector:
If the vector's count is not the other vector's count, exit.
Multiply the vector by the other vector.
Find a sum of the vector.
Put the sum into the dot product.
 
To make an example vector and another example vector:
Add 1 to the example vector.
Add 3 to the example vector.
Add -5 to the example vector.
Add 4 to the other example vector.
Add -2 to the other example vector.
Add -1 to the other example vector.