Skip to content

Instantly share code, notes, and snippets.

@crcx
Forked from lsparrish/gist:574886
Created September 11, 2010 13:16
Show Gist options
  • Save crcx/575177 to your computer and use it in GitHub Desktop.
Save crcx/575177 to your computer and use it in GitHub Desktop.
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
: toList ( n- ) list ++ @list ! ;
: fromList ( -n ) @list @ list -- ;
: sizeOfList ( -n ) @list list - ;
create tp here , 100 allot
: tib tp 1+ ;
: resetBuffer tp !tp 0 !tib ;
: addToBuffer tp ++ @tp ! 0 @tp 1+ ! ;
: getList
last repeat @ 0;
tib over d->name
^match tib getLength =if dup toList then
again ;
: showList repeat sizeOfList 0; drop fromList d->name type space again ;
variable delim
: isDelim? ( n-n ) dup @delim = [ drop 0 ] ifTrue ;
: isTab? ( n-nf ) dup 27 = [ drop -1 getList showList tib type ] [ 0 ] if ;
: accept
resetBuffer !delim
repeat key isTab? 0 =if isDelim? 0; dup emit addToBuffer then again ;
32 accept
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment