Bohdan Kinash
Bohdan Kinash

Reputation: 23

Scheme cannot define function

I have such a code, I've checked my braces, but still have no clue why the compiler gives me

#f is not a function [sumOfSqaresOfTwoBiggest, (anon)]

error

(
  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)

Upvotes: 0

Views: 61

Answers (1)

Renzo
Renzo

Reputation: 27424

You have a rather unusual way of formatting lisp code. In fact, using an editor tailored for this kind of code will help you a lot to avoid this kind of errors, which is, yes, a wrong parenthesis.

Here is a correct version with the usual indentation:

(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)

Upvotes: 1

Related Questions