Consider the following implementation of the function for calculating the factorial: [1]
(define fac-tail
(lambda (n)
(define fac-tail-helper
(lambda (n ac)
(if (= 0 n)
ac
(fac-tail-helper (- n 1) (* n ac)))))
(fac-tail-helper n 1)))
I tried to rewrite using letfor internal definition:
(define fac-tail-2
(lambda (n)
(let ((fac-tail-helper-2
(lambda (n ac)
(if (= 0 n)
ac
(fac-tail-helper-2 (- n 1) (* n ac))))))
(fac-tail-helper-2 n 1))))
There is defineno error, but execution results in:
Error: undefined variable 'fac-tail-helper-2'.
{warning: printing of stack trace not supported}
How can I make a version let?
Schema Version - SISC v 1.16.6
[1] Based on the iterative version factorialin SICP section 1.2.1 http://mitpress.mit.edu/sicp/full-text/book/book-ZH-11.html#%_sec_1.2.1
source
share