# Jensen's Device

### From Seo Wiki - Search Engine Optimization and Programming Languages

**Jensen's Device** is a computer programming technique devised by Danish computer scientist Jørn Jensen, who worked with Peter Naur at Regnecentralen, particularly on the GIER Algol compiler, one of the earliest correct implementations of ALGOL 60.^{[1]}

The following program was proposed to illustrate the technique. It computes the 100th harmonic number by the formula <math> H_{100}=\sum_{i=1}^{100} \frac{1}{i}</math>:

beginintegeri;real proceduresum (i, lo, hi, term);valuelo, hi;integeri, lo, hi;realterm;commentterm is passed by-name, and so is i;beginrealtemp; temp := 0;fori := lostep1untilhidotemp := temp + term; sum := tempend;commentnote the correspondence between the mathematical notation and the call to sum; print (sum (i, 1, 100, 1/i))end

The above exploits call by name to produce the correct answer (5.187...). It depends on the assumption that an expression passed as an actual parameter to a procedure would be re-evaluated every time the corresponding formal parameter's value was required. If the last parameter to `sum<code> had been passed by value, and assuming the initial value of <code>i`

were 1, the result would have been 100 × 1/1 = 100.

Moreover, the *first* parameter to `sum`

,
representing the "bound" variable of the summation,
must also be passed by name, otherwise it would not be possible
to compute the values to be added.
(On the other hand, the global variable does not have to use the same identifier,
in this case `i`

, as the formal parameter.)

Donald Knuth later proposed the Man or Boy Test as a more rigorous exercise.

## References

- ↑ Peter Naur's 2005 Turing Award citation mentions his work with Jensen on GIER Algol