RosettaCodeData/Task/Menu/Factor/menu.factor

14 lines
414 B
Factor
Raw Permalink Normal View History

2020-02-17 23:21:07 -08:00
USING: formatting io kernel math math.parser sequences ;
2013-04-10 21:29:02 -07:00
: print-menu ( seq -- )
[ 1 + swap "%d - %s\n" printf ] each-index
"Your choice? " write flush ;
2020-02-17 23:21:07 -08:00
: (select) ( seq -- result )
dup print-menu readln string>number dup integer? [
drop 1 - swap 2dup bounds-check?
[ nth ] [ nip (select) ] if
] [ drop (select) ] if* ;
: select ( seq -- result ) [ "" ] [ (select) ] if-empty ;