Skip to content

Instantly share code, notes, and snippets.

@lsparrish
Created December 26, 2009 05:25
Show Gist options
  • Select an option

  • Save lsparrish/263843 to your computer and use it in GitHub Desktop.

Select an option

Save lsparrish/263843 to your computer and use it in GitHub Desktop.
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( For loop with an index that counts from zero, placed on the )
( top of the stack with each iteration. Uses NORS to keep )
( track of the original value, so nexti must be used to clean )
( up when loop is complete. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
: fori ` dup ` push ` for ` pop ` pop ` 2dup
` push ` push ` swap ` - ; compile-only
: nexti ` next ` pop ` drop ; compile-only
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Convert counted and zero-terminated strings. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
{{
create buffer 64 allot
---reveal---
: cs ( $-an ) tempString dup getLength ;
: zt ( an-$ ) tuck buffer swap copy 0 swap buffer + ! buffer tempString ;
: cstype fori over + @ emit nexti ;
}}
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Append/prepend counted strings. )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
{{
: sav ( n-n ) ` dup ` push ;
---reveal---
: csprepend ( anan-an )
here sav swap sav dup allot copy
here swap sav dup allot copy
pop pop + pop swap ;
: csappend ( anan-an ) push -rot pop -rot prepend ;
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment