# Paste: first attempt

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 03:27:20 |

Plain Text |

USING: kernel random io math.parser math combinators ;
IN: high-low
: guess "Your guess? " write flush readln string>number ;
: check-guess
{
{ [ 2dup > ] [ 2drop "Too low" print f ] }
{ [ 2dup < ] [ 2drop "Too high" print f ] }
[ 2drop "You win!" print t ]
} cond ;
: game-loop dup guess check-guess [ drop ] [ game-loop ] if ;
: start random game-loop ;

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 03:37:00 |

Plain Text |

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

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 04:42:21 |

Plain Text |

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

Author: | sykopomp |

Mode: | factor |

Date: | Thu, 14 Jan 2010 16:47:34 |

Plain Text |

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

## New Annotation