Artifact fbfedb99e670cbaf47db963d2b0b09fd10a562ab
File hangman/dict.retro part of check-in [25b3671a47] - use ^ in all areas of hangman by crc on 2010-11-16 19:45:38. [annotate]
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Hangman for Retro Console )
( * System dictionary access. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Copyright [c] 2010, Marc Simpson )
( License: ISC )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( --[ Variables ]--------------------------------------------- )
: sys-dict "wordlist.txt" ^files':r ;
variable dict 0 dict !
here 80 allot constant dict-word
variable dict-size
( --[ Access ]------------------------------------------------ )
: open-dict ( -h ) sys-dict ^files'open dup 0 =if
cr "Error: can't open dictionary." puts then ;
: initialise ( - ) dict @ 0 =if open-dict 0; dup
dict ! ^files'size dict-size ! then ;
: rand-off ( -n ) dict-size @ ^math'toRandom ;
: rand-pos ( -n ) rand-off dict @ ^files'seek drop ;
: >line ( - ) repeat dict @ ^files'read 10 =if ;then again ;
: fread! ( ha-f ) swap ^files'read dup rot ! ;
: readline ( - ) dict-word repeat dict @ over fread! drop
dup @ 10 =if 0 swap ! ;else 1+ then again ;
: rand-word ( - ) rand-pos >line readline ;
: close-dict ( - ) dict @ ^files'close 0 =if
"Error: Can't close dictionary." puts then ;
( --[ Retrieval ]--------------------------------------------- )
: get-word ( -$ )
rand-word dict-word ^strings'toLower dict-word ;
( ============================================================ )