From 94cd8f89f9d45a338b08ef7b39563d29042d0839 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Mon, 3 Jul 2017 00:13:06 +0200 Subject: [PATCH] number-game: need to flush the output --- extra/numbers-game/numbers-game.factor | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/extra/numbers-game/numbers-game.factor b/extra/numbers-game/numbers-game.factor index e0d00986fc..6fae3d99c5 100644 --- a/extra/numbers-game/numbers-game.factor +++ b/extra/numbers-game/numbers-game.factor @@ -1,14 +1,25 @@ USING: kernel math math.parser random io ; IN: numbers-game -: read-number ( -- n ) readln string>number ; +: printfl ( s -- ) + print flush ; + +: writefl ( s -- ) + write flush ; + +: read-number ( -- n ) + readln string>number ; : guess-banner ( -- ) - "I'm thinking of a number between 0 and 100." print ; -: guess-prompt ( -- ) "Enter your guess: " write ; -: too-high ( -- ) "Too high" print ; -: too-low ( -- ) "Too low" print ; -: correct ( -- ) "Correct - you win!" print ; + "I'm thinking of a number between 0 and 100." printfl ; + +: guess-prompt ( -- ) "Enter your guess: " writefl ; + +: too-high ( -- ) "Too high" printfl ; + +: too-low ( -- ) "Too low" printfl ; + +: correct ( -- ) "Correct - you win!" printfl ; : inexact-guess ( actual guess -- ) < [ too-high ] [ too-low ] if ;