Skip to content

Instantly share code, notes, and snippets.

russolsen / for_calls_each.rb
Created Oct 3, 2016
Demo that in Ruby the for expression is just sugar around a call to the each method.
View for_calls_each.rb
# Demo that for calls each
class ThreeOf
def initialize(value)
@value = value
def each(&block)
View gist:56a0750da28216e18042
require 'oj'
require 'stringio'
require 'json'
class Handler
def hash_start
def hash_set(h,k,v)
russolsen / cloforth_repl
Created Sep 3, 2013
The key function in cloforth
View cloforth_repl
(defn repl [env]
(let [dictionary (:dictionary env)]
(if (:quit env)
(let [r (:in env)
compiled (comp/compile-statement r dictionary)]
(if (and (coll? compiled) (empty? compiled))
(let [result (exec/execute-program env compiled) ;; Get the lazy sequence of states
new-env (last result)] ;; ... and then the last one
russolsen / lisp_repl.rb
Created Jan 26, 2012
And to finish the thought, a REPL using Fogus' lithp.rb and my own s-expression parser.
View lisp_repl.rb
require 'lithp'
require 'lisp_parser'
lisp =
print "> "
while not $stdin.eof?
line = readline
s_expression =
p lisp.eval(s_expression)
russolsen / lisp_parser.rb
Created Jan 26, 2012
An S expression (i.e. LISP) parser in 32 lines of Ruby.
View lisp_parser.rb
class SExpressionParser
def initialize(expression)
@tokens = expression.scan /[()]|\w+|".*?"|'.*?'/
def peek
def next_token