scheme tail recursion
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to create a scheme tail recursive function flatten-tl-rec that flattens a nested list of lists. (define flatten-tl-rec (lambda (xs) (letrec ([flatten-tl-rec-acc (lambda (xs acc) (cond ((empty? xs) acc) ((list? (first xs)) (flatten-tl-rec-acc (rest xs) (append (flatten-tl-rec-acc (first xs) '()) acc))) (else (flatten-tl-rec-acc (rest xs) (cons (first xs) acc)))) )]) (flatten-tl-rec-acc xs '())))) (flatten-tl-rec '(1 2 3 (4 5 6) ((7 8 9) 10 (11 (12 13))))) But I am getting (13 12 11 10 9 8 7 6 5 4 3 2 1) instead of (1 2 3 4 5 6 7 8