Skip to content

Instantly share code, notes, and snippets.

: above ( aa-a ) repeat tuck @ over =if drop ;then swap @ 0; again ;
2 elements tp tib 1024 allot
: tib, tp ++ !@tp ;
: tz tib !tp ; tz
2 elements t trig
: findTrig !t trig repeat @ 0; dup 1+ @ @t = not 0; drop again ;
: doTrig findTrig dup 3 + @ swap 2 + @ with-class ;
: addTrig here @trig , !trig , &.word , here 1+ , 0 , 0 , [ ;
: contig variable 0 , allot ;
: linked variable -1 , ;
: >contig .data ` tuck ` @ ` ! ` ++ ;
: <contig .data ` dup ` -- ` @ ` @ ;
: >linked .data ` here ` over ` @ ` , ` swap ` ! ` , ;
: <linked .data ` dup ` @ ` 1+ ` @ ` swap ` dup ` @ ` @ ` swap ` ! ;
: __> dup 1+ @ if >linked ;then >contig ; immediate
( 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 ! ;
with strings'
with quotes'
{
create str0 512 allot
create str1 512 allot
: NewCompare
[ toLower dup getLength 1+ str0 swap copy ] dip
toLower dup getLength 1+ str1 swap copy
str0 str1 default: compare ;
@lsparrish
lsparrish / gist:575873
Created September 12, 2010 05:26 — forked from foucist/gist:575421
functional
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
@lsparrish
lsparrish / gist:576309
Created September 12, 2010 18:34 — forked from crcx/gist:576204
chain: stringBuffer'
{{
tib variable: buffer
@buffer variable: pointer
: terminate ( - ) 0 @pointer ! ;
---reveal---
: addToBuffer ( c- ) @pointer ! pointer ++ terminate ;
: getFromBuffer ( -c ) pointer -- @pointer @ terminate ;
: endOfBuffer ( -a ) repeat @pointer dup @ 0; 2drop pointer ++ again ;
: sizeOfBuffer ( -n ) @pointer @buffer - ;
@lsparrish
lsparrish / gist:576359
Created September 12, 2010 19:30 — forked from crcx/gist:576343
chain: stringBuffer'
{{
tib variable: buffer
@buffer variable: pointer
: terminate ( - ) 0 @pointer ! ;
: bs? ( c-cf ) dup 8 = ;
: remove ( c- ) drop pointer -- @pointer @buffer <if @buffer !pointer then terminate ;
: add ( c- ) @pointer ! pointer ++ terminate ;
---reveal---
: addToBuffer ( c- ) bs? if remove else add then ;
@lsparrish
lsparrish / test.c
Created September 15, 2010 00:40
playing around with c
#include <stdio.h>
char* listen();
int process();
int strcmp();
int output();
int main() {
char *str;
while (strcmp(str,"bye\n") != 0){
( dict contains link to the most recent char word created. )
( m? is the interrupt detector for the lookup function. )
( l? is the lookup function. returns an xt or 0. )
( : starts a char definition. )
( ; calls a char definition. )
variable dict
: m? dup 0 =if nip -1 ( leave 0 on stack after interrupt ) ;then
2dup 1+ @ =if nip 2 + -1 ( leave xt on stack after interrupt );then ;
: l? dict repeat @ m? if; again ;
chain: stacks'
{{
variable this
: stack ( -n ) this @ ;
---reveal---
: :| ( n- ) this ! ;
: |: ( "- ) create here dup :| , 100 allot ;
: \ ( n- ) stack ++ stack @ ! ;
: / ( -n ) stack @ stack -- @ ;
}}