Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Created September 11, 2010 05:49
Show Gist options
  • Save lsparrish/574886 to your computer and use it in GitHub Desktop.
Save lsparrish/574886 to your computer and use it in GitHub Desktop.
( compare two strings from the beginning and return how many )
( similar characters there are before the strings diverge. )
: ^match ( $$-n ) 0 -rot repeat @+ push swap @+ pop =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 @ ! ;
: fr_list ( -n ) list @ @ list -- ;
: no_list ( - ) list dup ! ;
: sz_list ( -n ) list @ list - ;
create tp here , 100 allot
: @tp tp @ ;
: to_tib tp ++ @tp ! 0 @tp 1+ ! ;
: z_tp tp tp ! 0 @tp 1+ ! ;
: tib tp 1+ ;
: get_list
last repeat @ 0;
tib over d->name
^match tib getLength =if dup to_list then
again ;
: show_list
repeat sz_list 0 =if tib type ;then
fr_list d->name type space again ;
variable delim
: test_delim ( n-n ) dup @delim =if drop 0 then ;
: test_tab ( n-nf ) dup 27 =if drop -1 get_list show_list ;then 0 ;
: accept !delim repeat key test_tab not
if test_delim 0; dup emit to_tib then again ;
32 accept
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment