1
votes

Currently learning Scheme/Racket and have problem running this piece of code.

(if (or (< aftnHour 0) (> aftnHour 6))
  ((display 
      "You entered an invalid input. Please enter an input between 0 and 8 only.")
   (newline)(newline)(askAftnHour))

My goal is to check if a variable is not between 0 and 6. If that condition is satisfied, I want to prompt the user about his mistake and call the same method again. The newline is just for formatting purposes.

The code actually works the first time when the user enters wrongly, i.e. the error message is shown and then the function is called again. But now upon entering the correct input, an error is produced:

"procedure application: expected procedure, given: #; arguments were: # # # "

I suspect I am doing something wrong with my newline, but really can't figure out what. Your help/advise is greatly appreciated.

1

1 Answers

3
votes

You are missing a begin call before display. It's not enough to wrap some expressions in () and treat them as a sequence, they will be actually treated as a function call, in this example it's a void call with three void parameters.

> (if (or(< aftnHour 0)(> aftnHour 6))
>     (begin (display "You entered an invalid input. Please enter an input between 0
> and 8 only.
> ")(newline)(newline)(askAftnHour))