Skip to content

Instantly share code, notes, and snippets.

View crcx's full-sized avatar

Charles Childers crcx

View GitHub Profile
@crcx
crcx / gist:3811645
Created October 1, 2012 12:54 — forked from lsparrish/gist:3808899
Generator in Retro
( generator )
{{
: xt, ( - ) 1 , @last @d->xt , ;
---reveal---
: yield ( - ) 1 , here 5 + , xt, ` :is 9 , xt, ` :devector ; compile-only
}}
: foo ( - ) "State one" puts yield
"State two" puts yield
"State three" puts ;
@crcx
crcx / request.coffee
Created May 23, 2012 12:53 — forked from wess/request.coffee
My quick Request class for CoffeeScript
# This is my first full blow coffeescript class Im working on
# thoughts?
class Request
constructor: ->
@xhrObjects = [
-> new XMLHttpRequest()
-> new ActiveXObject("Msxml2.XMLHTTP")
-> new ActiveXObject("Microsoft.XMLHTTP")
]
( 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 ;
@crcx
crcx / gist:576343
Created September 12, 2010 19:10 — forked from lsparrish/gist:576309
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 ;
@crcx
crcx / gist:576204
Created September 12, 2010 16:04 — forked from lsparrish/gist:575798
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 - ;
@crcx
crcx / gist:575177
Created September 11, 2010 13:16 — forked from lsparrish/gist:574886
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
@crcx
crcx / gist:569391
Created September 8, 2010 00:32 — forked from lsparrish/gist:556671
chain: parable
{{
create stack here , 10 allot
: push stack dup ++ @ ! ;
: pop stack dup @ @ swap -- ;
: empty? stack dup @ = ;
: nest compiler on here push 0 , 0 , ;
: unnest pop empty? not !compiler ;
---reveal---
: [ nest ; immediate

Original

{{
  : :find ( a-af ) last repeat @ 2dup =if drop @ -1 ;; else dup 0 =if ;then then again ;
  : .vocab ( a- ) dup 1+ @ :find nip if shut else open then ;
---reveal---
  : as-vocab ( a- ) last @ d->class ['] .vocab swap ! ;
@crcx
crcx / do_until.rst
Created January 2, 2010 06:21 — forked from lsparrish/gist:267334
commentary on do/until loops

First, the header describing the library.

( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( do ... until                                                )
( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ )
( Value n is taken from the stack and stored to a virtual     )
( variable. When this number is equal to the TOS at the time  )
( until is executed, the loop terminates.                     )

A Macro for Appending Code Before Evaluation

With this macro loaded, you can append code to a string and evaluate the results easily.

( A macro for appending code blocks. )
{{
  ifNotExists prepend { : prepend ( $$-$ ) here -rot 2 for dup here swap getLength dup allot copy next 0 , ; }