Error of calling functions in Scheme

1k views Asked by At

I am trying to define two functions using Scheme. One is the close_to function which looks like this:

    (define (close_to x y)(if(< (abs (- x y)) 0.0001)(#t)#f))

it should return true if the number x and y has a difference that is smaller than 0.0001 and false otherwise. However, it keeps throwing the error:

function call: expected a function after the open parenthesis, but received true

when I call it

    (close_to 4 3.99999999)

The second function is the improve function which looks like this:

    (define (improve x y)(average y /(x y)))

it should return the average of y and x/y. Similarly, I am getting the error:

function call: expected a function after the open parenthesis, but received 1

when I call it

    (improve 1 2)

What am I doing wrong? Can anyone help me?

1

There are 1 answers

1
Will Hartung On

Your problem is the (#t) and (#f).

#t is not a function. Rather, rewrite the first one like this:

(define (close_to x y)
  (if (< (abs (- x y)) 0.0001)
    #t
    #f))

The other is an exercise for the reader.