Skip to content

Instantly share code, notes, and snippets.

View AlexBaranosky's full-sized avatar

AlexBaranosky AlexBaranosky

  • Cisco Secure Malware Analytics (formerly Threat Grid)
  • Massachusetts
  • 03:36 (UTC -05:00)
View GitHub Profile
@fogus
fogus / psil-test.js
Created January 26, 2012 03:32
*psil, pocket lisp interpreter
var cx = new env;
console.log(leval(['set','a',42],cx));
console.log(leval('a',cx));
console.log(leval(['eq',42,'a'],cx));
console.log(leval(['quote',[1,2]],cx));
console.log(leval(['fst',['quote',[1,2]]],cx));
console.log(leval(['rst',['quote',[1,2]]],cx));
console.log(leval(['cons',1,['quote',[2,3]]],cx));
console.log(leval(['cond',['eq',1,2],42,43],cx));
console.log(leval(['atom',['quote',[1,2]]],cx));
@fogus
fogus / forth.rb
Created January 26, 2012 03:32 — forked from deadprogram/forth.rb
Forth interpreter in 64 lines of Ruby
#!/usr/bin/env ruby
def pop; $stack.pop || raise(StackUnderflow); end
def push(expression); $stack << expression; end
def unary; -> { push(yield pop) }; end
def binary; -> { push(yield pop, pop) }; end
def unary_boolean; -> { push(if yield pop then 1 else 0 end) }; end
def binary_boolean; -> { push(if yield pop, pop then 1 else 0 end) }; end
def swap; $stack[-2,2] = $stack[-2,2].reverse; end
$stack = []