Paste: Jensen's Device in Clay

Author: uros643
Mode: text
Date: Tue, 2 Nov 2010 20:43:42
Plain Text |
// Demonstration of Jensen's Device in the Clay Programming Language.
//   * http://en.wikipedia.org/wiki/Jensen%27s_Device
//   * http://tachyon.in/clay/

// Compute the 100th Harmonic number
//     = SIGMA_{i=1..100} 1/i
//    ~= 5.187378

main() {
    var j = 0;
    println(sum(j, 1, foo(100), 1.0/j));
}

foo(n) {
    print(n, "th Harmonic number: ");
    return n;
}

callbyname sum(i, lo, hi, term) ret : Float64 {
    ret = 0.0;
    i = lo;
    var hi = hi;
    
    while (i <= hi) {
        ret += term;
        inc(i);
    }
}

// I do wonder how callbyname is implemented... 

New Annotation

Summary:
Author:
Mode:
Body: