Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| (* -*- mode: ocaml; -*- *) | |
| module type FUNCTOR = sig | |
| type 'a t | |
| val map : ('a -> 'b) -> 'a t -> 'b t | |
| end | |
| type 'a monoid = {unit : 'a ; join : 'a -> 'a -> 'a} | |
| type var = string |
| stack = [] | |
| compileStacks = [] | |
| words = {} | |
| builtins = {} | |
| lambdaType = type(lambda x: x) #cannot compare against the function type directly for some reason | |
| def prn(o): | |
| print(o) | |
| def clr(l): |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
A lot of math grad school is reading books and papers and trying to understand what's going on. The difficulty is that reading math is not like reading a mystery thriller, and it's not even like reading a history book or a New York Times article.
The main issue is that, by the time you get to the frontiers of math, the words to describe the concepts don't really exist yet. Communicating these ideas is a bit like trying to explain a vacuum cleaner to someone who has never seen one, except you're only allowed to use words that are four letters long or shorter.
What can you say?
| #!/usr/bin/env python | |
| import sys | |
| import types | |
| import operator | |
| class Runtime: | |
| def __init__(self, env={}, stack=[]): | |
| self.env = { | |
| # Primitive words, not an impressive base but it works |
| <?php | |
| // Define the 'class' class | |
| $class = Obj() | |
| ->fn('new', function ($class) { | |
| $newClass = Obj($class->methods) | |
| ->fn('new', function($class) { | |
| $obj = Obj($class->imethods); | |
| $args = func_get_args(); | |
| array_shift($args); |
| # 30 minutes Lisp in Ruby | |
| # Hong MinHee <http://dahlia.kr/> | |
| # | |
| # This Lisp implementation does not provide a s-expression reader. | |
| # Instead, it uses Ruby syntax like following code: | |
| # | |
| # [:def, :factorial, | |
| # [:lambda, [:n], | |
| # [:if, [:"=", :n, 1], | |
| # 1, |