All pastes #1669791 Raw Edit

laka laka

public java v1 · immutable
#1669791 ·published 2009-11-13 12:16 UTC
rendered paste body
Suppose we have n steps left to climb; initially n=1. If n=0 then we are done. Otherwise, we try to call step: if it succeeds then we now have n-1 steps to go; if it fails we have n+1 steps to go. You can implement this with an explicit counter.  (define (step-up)    (let loop ((n 1))      (cond ((= n 0) #f)            ((step)  (loop (- n 1)))            (else    (loop (+ n 1))))))You can also implement this without an explicit counter:  (define (step-up)    (unless (step)      (step-up)      (step-up)))The justification is straightforward: if we fall down one step as a result of failure we then have to climb the step we just fell down in addition to the one we originally intended to climb.