Re: [racket] Puzzled with tail-recursion conversion

2012-02-15 Thread namekuseijin
thanks. Very subtle difference... definitely not a good idea to try to double an existing variable as an accumulator too... I reworked it to: (define (pi4 accuracy) (let helper ((k 0) (r 0)) (let ((this (* (/ (expt -1 k) (expt 4 k)) (+ (/ 2 (+ (* 4 k) 1))

Re: [racket] Puzzled with tail-recursion conversion

2012-02-15 Thread Matthias Felleisen
If you systematically apply cps and then accumulator transformations, you get this: (define (pi3 accuracy) (let helper ((k 0)) (let ((this (formula k))) (if (< (abs this) accuracy) this (+ this (helper (+ k 1))) (pi3 .1) (define (pi3-cps accuracy) (let he