(define (caching f)
(define ht (make-hash))
(lambda (x)
(define y (hash-ref ht x #f))
(let ((y (hash-ref ht x #f)))
(unless y
(hash-set! ht x (or y (f x))))
(set! y (f x))