USING: kernel random io math.parser math combinators ; IN: high-low : (guess) ( -- guess ) "Your guess? " write flush readln string>number ; : guess ( -- guess ) (guess) dup [ ] [ drop "Not a number. Try again.\n" write flush guess ] if ; : check-guess ( answer guess -- succeeded? ) { { [ 2dup > ] [ 2drop "Too low" print f ] } { [ 2dup < ] [ 2drop "Too high" print f ] } [ 2drop "You win!" print t ] } cond ; : (game-loop) ( answer -- ) [ guess check-guess not ] curry loop ; : game-loop ( max -- ) random (game-loop) ; : start-game ( -- ) 30 game-loop ; MAIN: start-game