-
-
Save lsparrish/575873 to your computer and use it in GitHub Desktop.
functional
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with quotes' | |
( compare two strings from the beginning and return how many ) | |
( similar characters there are before the strings diverge. ) | |
: ^match ( $$-n ) | |
0 -rot repeat @+ [ swap @+ ] dip =if rot 1+ -rot else 2drop ;then again ; | |
( test each word in the dictionary for similarity. if similar up ) | |
( to the current point, add to the suggestions queue. ) | |
create list here , 100 allot | |
: to_list ( n- ) list ++ @list ! ; | |
: from_list ( -n ) @list @ list -- ; | |
: list.size ( -n ) @list list - ; | |
create tp tib , | |
: buffer.reset tib !tp 0 !tib ; | |
: buffer.add_to @tp ! tp ++ 0 @tp 1+ ! ; | |
: buffer.to_end repeat @tp @ 0; drop tp ++ again ; | |
: get_list | |
last repeat @ 0; | |
tib over d->name | |
^match tib getLength = [ dup to_list ] ifTrue | |
again ; | |
: guess_word list.size 1 = [ from_list d->name tib over getLength 1+ copy buffer.to_end ] ifTrue ; | |
: show_list guess_word repeat list.size 0; drop from_list d->name type space again ; | |
variable delim | |
: if.delim ( n-n ) dup @delim = [ drop 0 ] ifTrue ; | |
: if.tab ( n-nf ) dup 27 = dup [ nip get_list show_list tib type ] ifTrue ; | |
: new_accept | |
buffer.reset !delim | |
repeat key if.delim 0; if.tab [ dup emit buffer.add_to ] ifFalse again ; | |
' new_accept is accept |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment