1
(define (square x)
(display (* x x)))
(define (sum-of-squares a b)
(+ (square a) (square b)))
我测试了它,而sum-of-squares
函数不起作用。为什么?这个Scheme的平方和函数为什么不起作用?
(define (square x)
(display (* x x)))
(define (sum-of-squares a b)
(+ (square a) (square b)))
我测试了它,而sum-of-squares
函数不起作用。为什么?这个Scheme的平方和函数为什么不起作用?
(display x)
评估为无效(可能被视为无效)。这是一个打印出参数但不返回它的函数调用。相反,您应该定义平方函数来评估值而不显示,即:
(define (square x)
(* x x))