Skip to content

Instantly share code, notes, and snippets.

@lsparrish
lsparrish / more.rx
Created October 19, 2012 05:19 — forked from crcx/more.rx
yet another approach
( useful things )
: dictionary.find/xt ( string:name - xt ) find [ @d->xt ] [ drop #0 ] if ;
: getc:internal ( -c ) &getc 2 + @ do ;
: __$ keepString 1 , , &dictionary.find/xt , ; parsing
( keymap )
9 variable: prefix:CHAR
create prefix:TABLE 256 allot
( We will lookup the keymap by name, to allow for per-application maps )
@lsparrish
lsparrish / more.rx
Created October 18, 2012 17:32 — forked from crcx/more.rx
yet another approach
9 variable: prefix:CHAR
create prefix:TABLE
256 allot
: getc:internal ( -c ) &getc 2 + @ do ;
[ dup @prefix:CHAR ==
[ drop getc:internal
"prefix:TABLE" find drop @d->xt + @ dup 0 <>
@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 / 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: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
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 ;
@lsparrish
lsparrish / blocker.rst
Created December 22, 2009 08:11 — forked from crcx/blocker.rst

Block Conversion

Author: Charles Childers
Version: 2009.12.21

Blocker User's Guide

@lsparrish
lsparrish / REM.rst
Created December 20, 2009 19:08 — forked from crcx/REM.rst

Retro Editor for Mortals

Author: Charles Childers
Version: 2009.12.20

REM User's Guide

: append ( $$-$ )
swap
here push
here over getLength dup allot copy
here over getLength dup allot copy
0 , pop ;
: paren-wrap s" (" swap append s" )" append ;
Compiler macros are often used to lay down code in the calling word. You'll see something like:
: foo ['] + compile ['] . compile ; immediate
This is fine, but sometimes you need to deal with other macros:
: bar 1 literal, 2 literal, ['] foo execute ; immediate
This approach has one problem: keeping track of what words need to be compiled and which need to be called. Plus, with Retro's use of word classes, you may have other words that are handled in other ways.