1 An env is a dictionary of{'var':val} pairs, with a link to its outer environment in env['\_outer'].   
2 A procedure is a lambda expression, with parms, body, and env which calls eval_exp on the body.   
3 ###\*\#   
4 evaluateProgram(program): Initialize a standard environment. Parse and evaluate a list of expressions, returning the final  $\rightarrow$  result.   
5 ['define square (lambda (r)  $(\ast r))$  , '(square 3)] -> 9   
6 get_env(parms, args, env=None): Return a new env inside env with parms mapped to their corresponding args, and env as the  $\rightarrow$  new env's outer env.   
7 [] ,[] ->{'}\_outer': None}   
8 ['a'], [1] -> {a': 1, '\_outer': None}   
9 standard_env(includes=['math', 'ops', 'simple_method]): An environment with some Scheme standard procedures. Start with an  $\rightarrow$  environment and update it with standard functions.   
10 [] ->{'}\_outer': None}   
11 get(math): Get a dictionary mapping math library function names to their functions.   
12 get ops(): Get a dictionary mapping operator symbols to their functions: +, -, *, /, >, <, >=, <=, =.   
13 getsimple_method(): Get a dictionary mapping 'abs', 'min', 'max', 'not', 'round' to their functions.   
14 apply_fn_dict_key(fn_dict_generation, key, args_list): Return the value of fn_dict_generation() [key](*args_list) in  $\rightarrow$  standard_env.   
15 get(math, '\sqrt{t}', [4] -> 2.0   
16 getOps, ++', [1, 2] -> 3   
17 getsimple_method, abs', [-1] -> 1   
18 get math   
19 get ops   
20 getsimple_method   
21 parse_and_update(expression, env): Parse an expression, return the result.   
22  $" (+ 1 (* 2 3))"$  ,  $\{^{+ + }:(\mathrm{~lambd}\alpha \mathrm{x},\mathrm{y};\mathrm{x} + \mathrm{y})$  , \*\*: (lambda x, y: x * y), '\_outer': None) -> 7   
23 eval_exp(x, env): Evaluate an expression in an environment and return the result. Check if x is a list, a string, or  $\rightarrow$  neither, and call the corresponding function.   
24 1,{'}\_outer': None} -> 1   
25 find(env, var): Find the value of var in the innermost env where var appears.   
26 {a':4,'\_outer':None}, 'a' -> 4   
27 {'}\_outer':{a':4,'\_outer':None}, 'a' -> 4   
28 {a':3,'\_outer':{a':4,'\_outer':None}, 'a' -> 3   
29 string(case(x, env): Return find(env, x).   
30 'a', {a':4,'\_outer':None} -> 4   
31 find   
32 list(case(x, env): Handle the function specified by the first value of x. Handle the first value of x being quote, if,  $\rightarrow$  define,set!, lambda, or otherwise. Return the result.   
33 ['quote', a'], {'}\_outer': None} -> 'a'   
34 ['if', True, 1, 2], {'}\_outer': None} -> 1   
35 ['define', a', 1], {'}\_outer': None} -> None   
36 get_procedure(parms, body, env): Return a procedure which evaluates body in a new environment with parms bound to the  $\rightarrow$  args passed to the procedure (in the same order as parms).   
37 eval_procedure(parms, body, env, args): Gets a procedure and returns the result of evaluating proc(*args) in env.  $\rightarrow$  Should not be called directly.   
38 ['r'], ['*', 'pi', ['*', 'r', 'r)], {'*': (lambda x, y: x * y), 'pi': 3, '\_outer': None}, [1] -> 3   
39 get_procedure   
40 get_env   
41 eval_exp   
42 otherwise(case(x, env): Get the procedure by evaluating the first value of x. Then, evaluate the arguments and apply  $\rightarrow$  the procedure to them. Return the result.   
43 ['+', 1, 2], {'++': (lambda x, y: x + y), '\_outer': None} -> 3   
44 eval_exp   
45 eval_exp   
46 not_list(case(x, env): Return x   
47 1,{}-> 1   
48 parse(program): Read a Scheme expression from a string.   
49  $^{\prime}(1 + (2 * 3))'\rightarrow [1,\dots,[2,\dots,3]]$    
50 tokenize(s): Convert a string into a list of tokens, including parenns.   
51 "1 + 2" -> ['1', ', ', 2']   
52 "1 + (2 * 3)" -> ['1', ', ', ('(,'2', ', ', 3', )')']   
53 read_from_tokens(tokens): Translate tokens to their corresponding atoms, using parentheses for nesting lists.   
54 ['(','1', ', ',(','2', ', ', ', 3'), ', ',)] -> [1,'+', [2,'*, 3]]]   
55 atom(token): Numbers become numbers; every other token is a string.   
56 "1" -> 1   
57 "a" -> "a"   
58 "1.2" -> 1.2   
59 nested_list_to_str(exp): Convert a nested list into a string with nesting represented by parentheses.   
60 1 -> "1"   
61 [1,'+', [2,'*', 3]] -> "(1 + (2 * 3))"