Multiply an iterated sequences over another iterated sequences

Asked
Active3 hr before
Viewed126 times

2 Answers

sequences
90%

In many cases, we would like to iterate over the elements of a sequence and perform some computation for each element in turn, This pattern is so common that Python has an additional control statement to process sequential data: the for statement

Example_snippet/controller/utility/_sequences.js/ >>> digits = [1, 8, 2, 8] >>> . . .
>>> digits = [1, 8, 2, 8] >>>
   len(digits)
4
   >>>
   digits[3]
8
load more v
88%

The original Pascal version of this function used a for loop, which has a direct equivalent in Dylan, as we see in this version of the function:,The thing to note about this function is that there is no explicit iteration clause, Instead, the iteration is done by the built-in functions

Example_snippet/controller/utility/_sequences.js/ function dotProduct(x: array[x. . .
function dotProduct(x: array[xlo..xhi: integer] of real,
   y: array[ylo..yhi: integer] of real): real;
var
   i: integer;
sum: real;
begin
if (xhi - xlo < > yhi - ylo)
   error("dotProduct: arrays of different lengths");
sum: = 0.0;
for i: = xlo to xhi do
      sum: = sum + x[i] * y[i - xlo + ylo];
   dotProduct: = sum
end;
load more v