【发布时间】:2014-05-29 18:14:54
【问题描述】:
有人用过在线ide repli吗? http://repl.it/languages/Scheme
你如何增加它?
我正在尝试封装一个函数来根据 sicp video 2a 进行总结。
(define (square a )
(* a a))
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a ) next b))))
(define (sum-int a b)
(define (identity a) a)
(sum identity a (+ 1 a) b))
(define (sum-square a b)
(sum square a (+1 ) b))
(sum-square 1 2)
替代的平方和(不工作)
(define (sum-square a b)
(sum square a (+ 1 a) b))
(sum-square 1 2) // getting 2 not a function.
工作代码:
(define (sum-int a b)
(define (identity a) a)
(sum identity a (lambda(a)(+ 1 a)) b))
【问题讨论】:
-
我还没有完成学习方案,但是如果你想返回一个函数,你不需要
lambda吗? -
哦,好吧!这行得通!