方案不能定义功能

时间:2021-01-16 14:54:09

标签: scheme lisp

我有这样的代码,我检查了我的大括号,但仍然不知道为什么编译器会给我

<块引用>

#f 不是函数 [sumOfSqaresOfTwoBiggest, (anon)]

错误

(
  define (sumOfSqaresOfTwoBiggest a b c) (
    cond (
      ((and (> a c ) (> b c)) (+ (* a a) (* b b)))
      ((and (> a b) (> c b)) (+ (* a a) (* c c)))
      (else (+ (* a a) (* c c)))
    )
  )
)
(sumOfSqaresOfTwoBiggest 1 2 3)

1 个答案:

答案 0 :(得分:1)

你有一种相当不寻常的方式来格式化 lisp 代码。事实上,使用为这种代码量身定做的编辑器对你避免这种错误有很大帮助,没错,就是括号错误。

这是一个带有通常缩进的正确版本:

(define (sumOfSqaresOfTwoBiggest a b c)
  (cond ((and (> a c ) (> b c)) (+ (* a a) (* b b)))
        ((and (> a b) (> c b)) (+ (* a a) (* c c)))
        (else (+ (* a a) (* c c)))))

(sumOfSqaresOfTwoBiggest 1 2 3)
相关问题