Skip to content

Instantly share code, notes, and snippets.

@dplyukhin
dplyukhin / Lisph.hs
Created January 9, 2017 05:04
Source code for a blog post
import Data.List
type Program = [SExp]
-- Note that we are using Strings in our compiler to denote Lisp *symbols*;
-- The Lisp we are writing has no string primitives of its own.
data SExp = Literal Integer -- e.g. 5, 42
| Symbol String -- e.g. x, first, lambda, -
| SExp [SExp] -- e.g. (+ (* 3 2) 4), (define fact (lambda n (fact (- n 1))))
@dplyukhin
dplyukhin / inheritance_demo.js
Created November 29, 2013 22:08
A comprehensive demo on Javascript inheritance (untested but it's probably right XD)
// object_1.foo === 'bar'
// object_1['foo'] === 'bar'
var object_1 = {
foo: 'bar'
}
// object_2 uses object_1 as its *prototype* - it inherits the properties but they are not its own
// object_2.hasOwnProperty('foo') === false
// object_2.foo === 'bar'
var object_2 = Object.create(object_1);
@dplyukhin
dplyukhin / ee.py
Created November 25, 2013 22:57
'lil event emitter in python!
class EventEmitter:
"""Create listeners on an object"""
def __init__(self):
self._events = {}
def on(self, event, callback):
"""Execute callback when event is emitted. Returns an id for deletion.
event {String}