lambda过程作为返回值的例子

课堂上的BUG,是if语法错误。guile> (define (foo x)
(cond ((= x 1) (lambda (y) (+ y 10)))
((= x 2) (lambda (y) (+ y 20)))
(else (lambda (y) (+ y 0)))))
guile> (foo 1)
#<procedure #f (y)>
guile> ((foo 1) 23)
33
guile> ((foo 2) 23)
43
guile> ((foo 3) 23)
23
guile> ((foo 2) 33)
53
guile>

Leave a Reply

Your email address will not be published. Required fields are marked *