|
From: | Matt Wette |
Subject: | another Q on tail calls |
Date: | Wed, 18 Feb 2015 09:20:27 -0800 |
Here is another one Q on tail recursion. Is this a tail call? The result of (foo) is 10. At each iteration the loop captures the local variable "n" in a lambda and saves in a list. At the end of the iteration "+" is applied to the evaluation of all the lambdas. It looks to me like the capture of the binding has to invalidate tail-recursion. Is that true? (define (foo) (let iter ((proc-list '()) (n 4)) (if (zero? n) (apply + (map (lambda (proc) (proc)) proc-list)) (iter (cons (lambda () n) proc-list) (1- n))))) Motivation: I have been looking into streams programming (from SICP) and thinking about delay/force and future/touch. Thanks, Matt |
[Prev in Thread] | Current Thread | [Next in Thread] |