Interpreter Project: Major Functions

Interpreter Project

Summary of Major Functions

Through Part

Items in blue will be (re-)written in Part $part."; } else { echo "Items in blue will be written in Part $part."; } if ($part > 1) { echo "
Items in green were written in previous parts."; } function p($n) { global $part; if ($n < $part) { echo "green"; } else if ($n == $part) { echo "blue"; } else if ($n == 23) { if ($part < 2) { echo "black"; } else if ($part > 3) { echo "green"; } else { echo "blue"; } } else { echo "black"; } } ?>
NOTE: Items to be written in Part 6 will not be included here.

ABSTRACTION: binding
>(make-binding var val) constructor : create a new binding with var bound to val
>(binding-variable binding) selector : returns variable of binding
>(binding-value binding) selector : returns value of binding
>(set‑binding‑value! binding val) mutator : change value in binding to val
ABSTRACTION: frame
>(make-frame vars vals) constructor : create a new frame with vars bound to vals
>(empty-frame? frame) tester : returns #t if frame is empty; #f otherwise
>(first-binding frame) selector : returns the first binding in frame
>(rest-of-bindings frame) selector : returns the rest of the bindings in frame
>(adjoin-binding binding frame) creates a new frame with binding added to frame
>(binding-in-frame var frame) returns binding for var; #f if no binding exists
ABSTRACTION: environment
>empty-env representation of an empty environment
>(empty-env? env) tester : returns #t if env is empty; #f otherwise
>(first-frame env) selector : returns the first frame in env
>(rest-of-frames env) selector : returns the rest of the frames in env
>(set‑first‑frame! env new-frame) mutator : replace first frame of env with new-frame
>(adjoin-frame frame env) creates a new environment with frame added to env
>(extend-env vars vals env) calls adjoin-frame with a new frame (whose vars are bound to vals) and env
>(binding-in-env var env) returns the binding for var in env; #f if no binding exists
>(setup-env) returns a new global environment
>global-env stores the global environment
IMPLEMENTATION: variables
>(lookup-variable var env) returns the value of var in env; error otherwise
>(variable? exp) tester : returns #t if exp is a variable; #f otherwise
HELPER: tagged-list?
>(tagged-list? exp tag) tester : returns #t if exp is a list beginning with tag; #f otherwise
IMPLEMENTATION: quote
>(quoted? exp) tester : returns #t if exp is a quoted expression; #f otherwise
>(text-of-quotation exp) returns the text of a quoted expression
IMPLEMENTATION: define
>(definition? exp) tester : returns #t if exp is a definition; #f otherwise
>(eval-definition exp env) controller : define variable as specified in exp
>(definition-variable exp) selector : returns variable portion of define exp
>(definition-value exp) selector : returns value portion of define exp
>(define-variable! var val env) add a binding for var bound to val
in the first frame of env (or report an error if a binding already exists)
IMPLEMENTATION: set!
>(assignment? exp) tester : returns #t if exp is an assignment; #f otherwise
>(eval-assignment exp env) controller : assign variable as specified in exp
>(assignment-variable exp) selector : returns variable portion of set! exp
>(assignment-value exp) selector : returns value portion of set! exp
>(set‑variable‑value! var val env) mutate the first binding of var found in env;
error if no binding exists
IMPLEMENTATION: evaluation
>(i-eval exp env) controller : evaluates exp in env
>(read-eval-print-loop) controller : read an expression from the user; evaluate; print result; loop
IMPLEMENTATION: application
>(i-apply proc args) controller : evaluates procedures proc with arguments args
>(application? exp) tester : returns #t if exp is a procedure application; #f otherwise
>(operator exp) selector : returns operator (proc) of application
>(operands exp) selector : returns operands (args) of application
>(eval-operands operands env) returns a list of evaluated operands
>(eval-application exp env) evaluates a procedure application
ABSTRACTION: primitive
>(make-primitive name proc) constructor : creates a new primitive
>(primitive-procedure? proc) tester : returns #t if proc is a primitive; #f otherwise
>(primitive-name proc) selector : returns name of primitive procedure
>(primitive-implementation proc) selector : returns implementation of primitive procedure
>(apply‑primitive‑procedure proc vals) controller : apply primitive proc to evaluated arguments vals
IMPLEMENTATION: begin
>(begin? exp) tester : returns #t if exp is a begin expression; #f otherwise
>(begin-expressions exp) selector : returns list of expressions in begin exp
>(eval-begin exp env) controller : evaluate begin expression
IMPLEMENTATION: if
>(if? exp) tester : returns #t if exp is an if expression; #f otherwise
>(test-expression exp) selector : returns test expression of an if expression
>(then-expression exp) selector : returns then expression of an if expression
>(else-expression exp) selector : returns else expression of an if expression
>(eval-if exp env) controller : evaluate if expression
IMPLEMENTATION: cond
>(cond? exp) tester : returns #t if exp is a cond expression; #f otherwise
>(first-cond-exp exp) selector : returns first conditional in cond exp
>(rest-of-cond-exps exp) selector : returns remaining conditionals in cond expression
>(eval-cond exp env) controller : evaluate cond expression
IMPLEMENTATION: lambda
(lambda? exp) tester : returns #t if exp is a lambda expression; #f otherwise
ABSTRACTION: closure
(make-closure lambda-exp env) constructor : creates abstraction storing lambda exp and its env
(closure? exp) tester : returns #t if exp is a closure; #f otherwise
(procedure-parameters closure) selector : returns list of parameters of closure
(procedure-body closure) selector : returns list of expressions in closure
(procedure-env closure) selector : returns environment in which closure was defined
(apply-closure closure vals) controller : apply closure to evaluated arguments vals
IMPLEMENTATION: let
(let? exp) tester : returns #t if exp is a let expression; #f otherwise
(let->lambda exp) returns lambda expression equivalent of let expression
(eval-let exp env) controller : evaluates let expression
IMPLEMENTATION: let*
(let*? exp) tester : returns #t if exp is a let* expression; #f otherwise
(let*->let exp) returns let expression equivalent of let* expression
(eval-let* exp env) controller : evaluates let* expression