Jensen's Device

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]

Jensen.algol
real procedure SIGMA(x, i, n);
   value n;
   real x; integer i, n;
begin
   real s;
   s := 0;
   for i := 1 step 1 until n do
      s := s + x;
   SIGMA := s;
end

*This is the famous example by Jensen that demonstrates the power of call-by-name. It allows to sum up an expression x that depends on a variable i:

10
Sigma
i=1
ai

SIGMA(a(i), i, 10)

10
Sigma
i=1
ai bi

SIGMA(a(i) * b(i), i, 10)


 

 [Previous Chapter]  [Previous Page]  [Contents]  [Next Page]
Copyright © 2002 Andreas Borchert, converted to HTML on May 02, 2002