View Lisph.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)))) |
View inheritance_demo.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
View ee.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |