1

Currently using racket, can't find much help, was wondering if someone can help me..

I have

(define (reciprocal x) (/ 1 x))

however, having a 0 as an ex shouldn't work. So I tried modifying it to

(define (reciprocal x) (if (= x 0)((#f)(/ 1 x)))

I'm not sure what I'm doing wrong, I was hoping that it would return false if x = 0 but it does not do this. I can still get the reciprocal, just doesn't check for the x. Can someone point out what I'm doing wrong here? Thanks!

user1692517
  • 1,122
  • 4
  • 14
  • 28
  • 1
    Possible duplicate of [My code signals the error "application: not a procedure" or "call to non procedure"](https://stackoverflow.com/questions/48064955/my-code-signals-the-error-application-not-a-procedure-or-call-to-non-procedu) – Sylwester Jan 22 '18 at 22:58

1 Answers1

3

You need to restructure the if-else clause. Typical Scheme syntax for this form is as follows:

(if (predicate expression) then else)

So you would rewrite your code as follows:

(define (reciprocal x) (if (= x 0) #f (/ 1 x)))
crunch
  • 156
  • 8