出于教育目的,我正在尝试以实用的方式在球拍中实现猜我的号码游戏。我的问题是我必须停止函数并出现错误,如(error "YOU GUESSED!")
. 错误函数是我可以在球拍文档中找到的。有没有一种无错误的方法来阻止这个条件?
注意:我读到了stop-when,但我还不想进入 big-bang。
(define guess-my-number (lambda ()
(letrec ([my-number (random 100)]
[choices-left 7]
[game (lambda (choices-left)
(if (> choices-left 0)
(let ([user-guess (read)])
(cond [(> user-guess my-number) (display "That was too high!")]
[(< user-guess my-number) (display "That was too small!")]
[(= user-guess my-number) (error "YOU GUESSED!")])
(game (- choices-left 1)))
(display "Here ends the game!!")))])
(game choices-left))))