vendredi 22 janvier 2016

If statements in Racket

I am trying to construct a function "number-crop" which takes three arguments x a b. If x is to the left of the closed interval [a, b] on the number line, then return a. If x is to the right of the interval, then return b. Otherwise, just return x. This is what I have:

(define (number-crop x a b)
  (if (max x a b) x b)
  (if (min x a b) x a))

I am returned with the error, "define: expected only one expression for the function body, but found 1 extra part". I am new to Racket so I am still trying to understand how if statements work within the language.

Aucun commentaire:

Enregistrer un commentaire