正在加载图片...
Iteration as recursion Scheme uses tail call optimization A tail call is a call with nothing left but to return the answer (define(fact n (letrec((fact-helper (lambda(n answer) f(=n1) answer (fact-helper(n 1)(answer n)) (fact-helper n 1)) sept.8.2003 16.41016.413 Intro to Scheme Outline Scheme syntax · Procedures A mix of scheme- recursion specific details, and Data general programming tutorial lists structure sept.8,2003 16.41016.413 Intro. to scheme 10/ Iteration as Recursion • • (define (fact n) (letrec ((fact-helper (lambda (n answer) answer (fact-helper n 1))) Scheme uses “tail call optimization” A tail call is a call with nothing left but to return the answer. (if (= n 1) Sept. 8, 2003 16.410 16.413 Intro. to Scheme 19 (fact-helper (- n 1) (* answer n)))))) / Outline • • A mix of Scheme￾general programming tutorial Procedures – recursion – lists – structures specific details, and Sept. 8, 2003 16.410 16.413 Intro. to Scheme 20 Scheme syntax • Data 10
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有