Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Forked from crcx/private vocabulary chains
Created July 22, 2010 02:22
Show Gist options
  • Save lsparrish/485480 to your computer and use it in GitHub Desktop.
Save lsparrish/485480 to your computer and use it in GitHub Desktop.
variable this
variable that
: chain create here !that 0 , here !this 2 allot ;
: +link here push @this , @last , pop !this @@last !last ;
: seal @this @that ! ;
variable flag
variable xt
variable str
: zdrop ( n-n | nz-z ) dup 0 =if 2drop 0 then ;
: (search) ( a-fa )
repeat
@ 0; dup 1+ @ zdrop 0;
d->name @str compare if flag on dup 1+ @ zdrop 0; d->xt @ !xt drop ;then
again ;
: search-chain ( a$- )
!str 0 !xt 0 !flag
(search) @xt @flag ;
( ~~~~~~~~~~~~~~~~~~~~~~ TEST STUFF ~~~~~~~~~~~~~~~~~~~~~~~~ )
: walk ( a- ) repeat @ 0; dup 1+ @ zdrop 0; d->name type space again ;
chain oo
: foo 1 . ; +link
: bar 1 . ; +link
: biz 1 . ; +link
: bag 1 . ; +link
seal
oo walk
oo " bar" search-chain .s reset
oo " zdabar" search-chain .s reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment