Paste: friends.factor
Author: | Twey |
Mode: | factor |
Date: | Tue, 26 Oct 2010 18:25:30 |
Plain Text |
USING: kernel math prettyprint combinators arrays io sequences unicode.case ;
IN: friends
: get-friend ( n arr -- n arr more )
"Enter the name of a friend, or XXX to stop: " write
readln dup
"XXX" =
[ drop
f ]
[ -rot [ set-nth ] 2keep
[ 1 + ] dip
t ]
if ;
: get-friends ( n arr -- n arr )
t [ ] [ get-friend ] while ;
: prompt ( n arr -- n arr )
"[C]ount, [P]rint, or [A]dd friends? " write
readln >lower
{ { "p" [ 2dup swap head [ print ] each ] }
{ "c" [ [ dup . ] dip ] }
{ "a" [ get-friends prompt ] }
[ drop
"Please enter one of C, P, or A." print
prompt ] }
case ;
: main ( -- )
0 30 null <array> get-friends prompt 2drop ;
MAIN: main
New Annotation