SICP Ex 1.3错误;语法关键字不能用作表达式:#[keyword-value-item 13]

时间:2018-08-10 13:15:03

标签: functional-programming scheme sicp

嘿,我正在尝试写一些方案,您能帮我吗?

(define (square a b) (+ (* a a) (* b b)))

(define (sumsq x y z)
    (cond (and (< x y) (< x z) (square y z))
          (and (< y x) (< y z) (square x z))
          (else (square y z))))

(sumsq 1 2 3)

它给我一个错误;Syntactic keyword may not be used as an expression: #[keyword-value-item 13]

1 个答案:

答案 0 :(得分:3)

缺少两个括号。这是cond的正确语法:

(define (sumsq x y z)
    (cond ((and (< x y) (< x z)) (square y z))
          ((and (< y x) (< y z)) (square x z))
          (else (square y z))))