Not logged in

Artifact 13cb97a9058f285df450aa26731b8bb2619c05a3

File hangman/dict.retro part of check-in [180b240e3a] - updates to hangman, eval.rx now uses withLength by crc on 2010-11-16 15:30:55. [annotate]


( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Hangman for Retro Console                                    )
(  * System dictionary access.                                 )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Copyright [c] 2010, Marc Simpson                             )
( License: ISC                                                 )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )

with files'
with math'
with strings'

( --[ Variables ]--------------------------------------------- )

: sys-dict "wordlist.txt" :r ;

variable dict                                         0 dict !
here 80 allot                               constant dict-word
                                            variable dict-size

( --[ Access ]------------------------------------------------ )

: open-dict  ( -h ) sys-dict open dup 0 =if
                    cr "Error: can't open dictionary." puts then ;
: initialise ( -  ) dict @ 0 =if open-dict 0; dup
                    dict ! size dict-size ! then ;

: rand-off   ( -n ) dict-size @ toRandom ;
: rand-pos   ( -n ) rand-off dict @ seek drop ;

: >line      ( -  ) repeat dict @ read 10 =if ;then again ;
: fread!     ( ha-f ) swap 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 @ close 0 =if
                    "Error: Can't close dictionary." puts then ;

( --[ Retrieval ]--------------------------------------------- )

: get-word   (  -$  ) rand-word dict-word toLower dict-word ;

( ============================================================ )