20 lines
599 B
Text
20 lines
599 B
Text
// Jensen's device in Clipper (or Harbour)
|
|
// A fairly direct translation of the Algol 60
|
|
// John M Skelton 11-Feb-2012
|
|
|
|
function main()
|
|
local i
|
|
? transform(sum(@i, 1, 100, {|| 1 / i}), "##.###############")
|
|
// @ is the quite rarely used pass by ref, {|| ...} is a
|
|
// code block (an anonymous function, here without arguments)
|
|
// The @i makes it clear that something unusual is occurring;
|
|
// a called function which modifies a parameter is commonly
|
|
// poor design!
|
|
return 0
|
|
|
|
function sum(i, lo, hi, bFunc)
|
|
local temp := 0
|
|
for i = lo to hi
|
|
temp += eval(bFunc)
|
|
next i
|
|
return temp
|