Miranda homework
Excerpt from the writeup:
Write and test a Miranda function evaluate that evaluates a Scheme expression (for a very restricted subset of Scheme). For this assignment, consider expressions consisting of:
Major simplification: for the basic assignment you don't need to write a parser to parse Scheme syntax. Instead, you can define some appropriate Miranda types, and write your expressions using those. For example, here are some Scheme expressions and a possible definition of these using Miranda types.
- a number
- a variable
- an arithmetic expression using the functions +, -, *, or / (just the two-argument versions)
- a let expression consisting of a list of names and values, and an expression to evaluate in the new environment. let expressions can of course be nested (using lexical scoping).
Scheme version: 10 Miranda version: Num 10 Scheme version: (+ 10 (* 2 3)) Miranda version: Plus (Num 10) (Times (Num 2) (Num 3)) Scheme version: (let ((x (+ 10 20)) (y 50)) (+ x y)) Miranda version: (Let [ (Def "x" (Plus (Num 10) (Num 20))), (Def "y" (Num 50)) ] (Plus (Var "x") (Var "y"))) Hints
- Consider how you would represent the basic data structures needed in a Scheme interpreter: expressions, definitions (bindings), environments (a collection of bindings).
- The most important operation you will want to define is (naturally) expression evaluation. Expression evaluation takes place in an environment, and you will need to look up the values of bindings in that environment. How can you keep track of environments in a let expression?
- Start early and ask questions on the list!