正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 3. 2.4 A less trivial procedure: factorial First of all, it has a new kind of expression in the interior, the Compute n factorial, defined as n =n(n-1)(n-2)(n-3),1 his is an example of a predicate, a procedure that takes some .Notice that n!=n [(n-1(n-2)=n"(n-1)! ifn>1 arguments and returns either true or false. in this case based on (define fact (lambda (n) the test for numerical equality (f(=n1) *n(fact(-n1))})) numerical equality 4)=>#t (=45)=>#f 6 001 SICP Slide 3.2.5 The more interesting part is the body of the lambda, and it is a A less trivial procedure: factorial new special form called an if. Because this is a special form,it Notice that n!=n [(n-1)(n-2)=n"(n-1) ifn>1 means that evaluation does not follow the normal rules for (define fact combinations. Ifs are used to control the order of evaluation (lambda (n) and contain three pieces (f(=n1) merical (f=44)23)=>2 if(=45)23)=>3 470∞03 A less trivial procedure: factorial Slide 3.2.6 Its first subexpression we call a predicate .Notice that n!=n"[(n-1(n-2).]=n"(n-1) ifn> (define fact (lambda (n) (act(-n1))}))) f(=44)2 (f(45)23 731(003 predic Slide 3.2.7 A less trivial procedure: factorial Its second subexpression we call a consequent .Notice that n!=n(n-1)(n-2),J=n (n-1) ifn>1 tact (=45)>静E (false) (f(=44)236.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 3.2.4 First of all, it has a new kind of expression in the interior, the =. This is an example of a predicate, a procedure that takes some arguments and returns either true or false, in this case based on the test for numerical equality. Slide 3.2.5 The more interesting part is the body of the lambda, and it is a new special form called an if. Because this is a special form, it means that evaluation does not follow the normal rules for combinations. If's are used to control the order of evaluation, and contain three pieces. Slide 3.2.6 Its first subexpression we call a predicate. Slide 3.2.7 Its second subexpression we call a consequent
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有