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:3895813
Created October 15, 2012 21:54
prefix-based keybindings in retro
needs struct'
with struct'
chain: binding'
{
1 field .link
1 field .label
1 field .xt
} bind
variables| prefix lastbinding |
: getc:internal ( -c ) &getc 2 + @ do ;
: header' here @last' , !last' &.word , here 2 + , , ;
: :' getc dup putc header' 0 , 0 , ]] ;
variable c
: find' ( c-af ) !c last' repeat @ dup 0; 3 + @ @c = dup if; drop again ;
: d'' ( "-a) getc dup putc find' drop ;
: pair ( h-aa ) dup @d->xt swap @d->class ;
: start -1 repeat getc dup putc find' [ pair do ] ifTrue 0; again ;
:' a 1 putn ;
:' b 2 putn ;
:' c drop 0 ;
needs struct'
with struct'
: clone' ( a-a ) here 2dup swap size dup push allot pop copy ;
{ 2 fields .name .personal-dict } user
: ;parse ( "-$ ) '; accept tib keepString ;
: name: ( a"- ) ;parse swap .name ! ;
user luke
luke name: Luke Parrish;
needs decimal'
with decimal'
: sqr ( n-n ) dup * ;
3 elements i j sum
1 !i 1 !j 0 !sum
8 !scale
: // ( nn-n ) push 100000000 * pop / ;
: pi_series ( -) repeat @j @i // @sum + !sum 4 @sum * yield @i 2 + !i @j -1 * !j again ;
3 elements s0 s1 s2
@lsparrish
lsparrish / gist:3808899
Created October 1, 2012 01:03
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 ;
@lsparrish
lsparrish / iotest.hs
Created September 27, 2012 00:53
IO Test
import IO
-- IO playground
intro :: String
intro = "Hello, welcome to the playground."
prompt = "\n->"
--
quit :: IO ()
quit = do putStr "\nGoodbye."
loop :: IO ()
Idea: Digital commodity that acts as a source of credit and currency exchange.
Bitcoin already provides a good way of creating a chain of digital transactions that can't easily be faked. This kind of transaction could be tied to something more elaborate. Among the possibilities, a distributed system for generating currency in a manner that is similar to a loan against collateral.
1. Alice generates a hard hashes against genesis block containing her public key.
2. Bob (and everyone) verifies that they are indeed hard and against the genesis block.
3. Alice sends Claire a transaction signed with her public key.
4. Bob verifies that the transaction is signed by someone with Alice's (i.e. the hard hash solver's) public key.
So far, I'm describing bitcoin. However additional rules can be added to enable conversions like this:
@lsparrish
lsparrish / gist:2934446
Created June 15, 2012 02:52
Convert retro-language bzr repo to git repo and push to github
mkdir ~/bzr
cd ~/bzr
bzr branch lp:retro-language
mkdir ~/github
mkdir ~/github/retro-language
cd ~/github/retro-language
git init
bzr fast-export --plain ~/bzr/retro-language/ | git fast-import
git checkout master
git remote add origin https://github.com/lsparrish/retro-language.git