edits
[lambda.git] / topics / _week7_interpreter_exposition.mdwn
index 3161f2a..3fa5dae 100644 (file)
@@ -33,14 +33,6 @@ and behind the scenes that got converted into:
 
 which is what the functions of our interpreter program have to deal with.
 
-You're going to work with a program skeleton where these extra nice features are built in to the infrastructure. It will only be the core reduction or evaluation functions that you need to complete, to get us from:
-
-    App(Lambda("x",Var "x"), Var "y")
-
-to:
-
-    Var "y"
-
 As long as we're at it, why don't we make out language a bit more full-featured. We could throw in `let`-terms and `if-then`-terms, too:
 
     type term =
@@ -75,17 +67,17 @@ But then once we have those, we are going to want to have some primitive operati
       | Destructor of destructor
       | Literal of literal
 
-The official term for operations like `head` and `tail` is "deconstructor", not "destructor", but the latter is shorter and more fun to type. In the exercises that follow, the tricky parts that deal with the `Primfun`s and `Constructor`s and `Destructor`s and `Literal`s will always already be supplied for you. You'll just need to think about the `Var`s and `App`s and `Lambda`s and `Let`s and `If`s.
+The official term for operations like `head` and `tail` is "deconstructor", not "destructor", but the latter is shorter and more fun to type.
 
-We're going to explore how to implement the interpreter using two different methods. One is a translation of the method Chris demonstrated for combinatorial logic over to the lambda calculus. You check if any part of a term is reducible, and then keep repeating single-step reductions until you can't find any more eligible redexes. This involves substituting the argument of a redex into any free occurrences of the variable bound in the head. The second method works a bit differently. You can begin by thinking of it an improvement on the first method, that tries to get by without having to do all the laborious substitutions that reducing again and again would entail. But its virtues will be more than merely ones of efficiency. It will also start to look a lot more like the kinds of semantics, using assignment functions, that we're more familiar with as formal semanticists. In programming circles, assignment functions are called "environments" and we'll use that terminology here. So the two methods we're going to look at will be, first, a substitute-and-repeat interpreter; and second, an environment-based one.
+We're going to explore how to implement the interpreter using two different methods. One is a translation of the method Chris demonstrated for combinatory logic over to the lambda calculus. You check if any part of a term is reducible, if so perform the appropriate substitutions, and then keep repeating single-step reductions until you can't find any more eligible redexes. This involves substituting the argument of a redex into any free occurrences of the variable bound in the head. The second method works a bit differently. You can begin by thinking of it an improvement on the first method, that tries to get by without having to do all the laborious substitutions that reducing again and again would entail. But its virtues will be more than merely ones of efficiency. It will also start to look a lot more like the kinds of semantics, using assignment functions, that we're more familiar with as formal semanticists. In programming circles, assignment functions are called "environments" and we'll use that terminology here. So the two methods we're going to look at will be, first, a substitute-and-repeat interpreter; and second, an environment-based one.
 
-Now you could just work this out on paper. That's fine, and will save you some complications. But it will be more fun for you to play with an actual computer implementation. Plus then you will get the benefits of user-friendly input and user-friendly printing of the results.
+The code of this interpreter is based on source code accompanying Pierce's excellent book _Types and Programming Languages_. (In particular, the files here <http://www.cis.upenn.edu/~bcpierce/tapl/checkers/fulluntyped/>.) We aggressively modified that code to suit our somewhat different needs (and taste). Notably, Pierce's code only provides a substitute-and-repeat interpreter; so part of our refactoring was to make it easier to switch back and forth between that and an environment-based interpreter.
 
-But these benefits come at a price. The actual code you're going to look at has some complexity to it. 
+We provided you with a [[homework assignment|/exercises/assignment7]] that is a simplified version of the code of our interpreter. After getting that to work, you may be interested to play around with the fuller version, which adds literal  numbers and booleans, and user-friendly input and printing of results.
 
-The skeleton program we'll be providing you with is based on source code accompanying Pierce's excellent book _Types and Programming Languages_. (In particular, the files here <http://www.cis.upenn.edu/~bcpierce/tapl/checkers/fulluntyped/>.) We aggressively modified that code to suit our somewhat different needs (and taste). Notably, Pierce's code only provides a substitute-and-repeat interpreter; so part of our refactoring was to make it easier to switch back and forth between that and an environment-based interpreter.
+But these benefits come at a price. The code has some complexity to it. 
 
-Now part of the complexity of this can be factored out into extra files that you can just ignore, and we've tried to organize the code to maximize that. But sadly, some of the complexity inevitably ends up polluting our nice simple datatype. We're going to explain where this pollution comes from, in the hope that then you'll be able to see through it to the simple underlying form, that we displayed above.
+Now part of the complexity can be factored out into extra files that you might just ignore, and we've tried to organize the code to maximize that. But sadly, some of the complexity inevitably ends up polluting our nice simple datatype. We're going to explain where this pollution comes from, in the hope that then you'll be able to see through it to the simple underlying form, that we displayed above.
 
 A **first source of complexity** is that we want to get friendlier error messages, for example if we run the interpreter on a file `./input` that contains:
 
@@ -118,13 +110,13 @@ using the variable `fi` for the "source file info".
 
 A **second complication** has to do with the distinction between `term`s in general and what we want to count as `result`s of our computations.
 
-In these exercises, unlike the combinatorial logic ones, we are only going to work with "call-by-value" interpreters. That is, we will only apply functions (whether primitives or those expressed by Lambdas) to what we deem as "value"s or "result"s. At a minimum, these must be terms that it is not possible to reduce further. So `1` and `\x. x` count as values. But we will also legislate that terms like `1 (\x. x)`, though non-reducible (our booleans and numbers won't be Church functions, but rather will be non-functional atoms), count as "stuck" and so aren't results either. (As suggested in class, you can think of "stuck" terms as representing or being crashed computations.)
+In these exercises, unlike the combinatory logic ones, we are only going to work with "call-by-value" interpreters. That is, we will only apply functions (whether primitives or those expressed by Lambdas) to what we deem as "value"s or "result"s. At a minimum, these must be terms that it is not possible to reduce further. So `1` and `\x. x` count as values. But we will also legislate that terms like `1 (\x. x)`, though non-reducible (our booleans and numbers won't be Church functions, but rather will be non-functional atoms), count as "stuck" and so aren't results either. (As suggested in class, you can think of "stuck" terms as representing or being crashed computations.)
 
 As a result of never applying functions to non-results, non-results will never get bound to any variables, either.
 
-Now in the V1/substitute-and-repeat part of the exercise, results will simply be a proper subset of our terms. They will be abstracts, plus literals and all the other primitives. They won't include free/unbound variables. We'll count those as "stuck" or crashed computations, too. (But _bound_ variables are okay, because they'll always be bound to results.)
+Now in the VA/substitute-and-repeat part of the exercise, results will simply be a proper subset of our terms. They will be abstracts, plus literals and all the other primitives. They won't include free/unbound variables. We'll count those as "stuck" or crashed computations, too. (But _bound_ variables are okay, because they'll always be bound to results.)
 
-However, when we move to the V2/environment-based interpreter, we will need to introduce some results that aren't (just) terms, called `Closure`s. We'll discuss these later; but the upshot is that we're going to need eventually to work with code where the result datatype and the term datatype may be partly disjoint. So we are going to need two parallel datatypes:
+However, when we move to the VB/environment-based interpreter, we will need to introduce some results that aren't (just) terms, called `Closure`s. We'll discuss these later; but the upshot is that we're going to need eventually to work with code where the result datatype and the term datatype may be partly disjoint. So we are going to need two parallel datatypes:
 
     type bare_term =
       | TermVar of identifier
@@ -157,7 +149,7 @@ Having these two parallel datatypes is rather annoying, and requires us to inser
 
 A **third complication** has to do with environments. On the one hand, we don't have any really compelling need for environments in the first phase of the exercise, when we're just making a substitute-and-repeat interpreter. They don't play any role in the fundamental task we're focusing on. But on the other hand, weaving environments into the system when we *will* need them, for the second phase of the exercise, is not simple and would require lots of code changes. So that is a reason to include them from the beginning, just off to the side not doing any important work until we want them.
 
-And as long as we've got them at the party, we might just as well give them _something_ to do. Pierce's original code takes a source file, which it expects to contain a sequence of terms or other toplevel declarations separated by semicolons, and prints out the result of maximally reducing each of the terms. Note I said "or other toplevel declarations." In addition to terms like this:
+And as long as we've got them at the party, we might just as well give them _something_ to do. Pierce's original code takes a source file as input, which it expects to contain a sequence of terms or other toplevel declarations separated by semicolons, and prints out the result of maximally reducing each of the terms. Note I said "or other toplevel declarations." In addition to terms like this:
 
     1 + 2;
     let x = 1 in x + 2
@@ -183,7 +175,7 @@ will crash, because `w` has no result bound to it. Note that you can locally reb
 
 evaluates to `(3,0)`. (You have to enclose the `let y = 0 in y` in parentheses in order to embed it in terms like the pair construction `(_, _)`.)
 
-Note that what I'm writing above isn't the syntax parsed by Pierce's actual program. He uses a syntax that would be unfamiliar to you, so we've translated his code into a more local dialect; and the above examples are expressed using that dialect.
+Note that what I'm writing above isn't the syntax parsed by Pierce's original code. He uses a syntax that would be unfamiliar to you, so we've translated his code into a more local dialect; and the above examples are expressed using that dialect.
 
 Pierce's code had a second kind of toplevel declaration, too, which looks like this (in our dialect, not his):
 
@@ -192,22 +184,18 @@ Pierce's code had a second kind of toplevel declaration, too, which looks like t
 
 Now that won't crash, but will instead evaluate to `(0,w)`. The code now treats unbound occurrences of `w` as atomic uninterpreted symbols, like Scheme's `'w`. And these symbols do count as results. (They are also available to be rebound; that is, you are allowed to say `symbol w; let w = 0 in ...`. But perhaps we should prohibit that.)
 
-So these two kinds of toplevel declarations are already handled by Pierce's code, in a form, and it seemed neatest just to clean them up to our taste and leave them in place. And environments are needed, even in the V1/substitute-and-repeat interpreter (which is all Pierce's code provides), to implement those toplevel declarations. But as I said before, you can for now just think of the environments as sitting in the sidelines. They aren't used in any way for interpreting terms like:
+So these two kinds of toplevel declarations are already handled by Pierce's code, in a form, and it seemed neatest just to clean them up to our taste and leave them in place. And environments are needed, even in the VA/substitute-and-repeat interpreter (which is all Pierce's code provides), to implement those toplevel declarations. But as I said before, you can for now just think of the environments as sitting in the sidelines. They aren't used in any way for interpreting terms like:
 
     let y = 1 + 2 in
     let x = y + 10 in
     (x, y)
 
-But now *what are* environments? In order to emphasize the essential commitments rather than any one particular implementation of environments, we're going to show you the general interface environments need to satisfy, and then show you a couple of different ways of implementing that interface. These will be just plug-and-play. You should be able to switch the implementations at will, and have everything work out the same.
-
-TODO selecting an environment
-
 Okay, that **completes our survey of the complications**.
 
-The V1/reducuction-based interpreter
+The VA/reducuction-based interpreter
 ------------------------------------
 
-For phase 1 of this exercise, you're going to write a `reduce_head_once` function that converts OCaml values like:
+For one part of the homework, we had you complete a `reduce_head_once` function that converts OCaml values like:
 
     TermApp(TermApp(TermLambda("x", TermApp(Var "x", Var "y")), TermLambda("w", Var "w")), ...)
 
@@ -221,7 +209,7 @@ The further reduction, to:
 
 has to come from a subsequent re-invocation of the function.
 
-Before we get down to business, let's think about how we will detect that the term has been reduced as far as we can take it. In the reduce-and-repeat interpreter Chris demonstrated for combinatorial logic, we had the `reduce_head_once` function perform a single reduction *if it could*, and then it was up to the caller to compare the result to the original term to see whether any reduction took place. That worked for the example we had. But it has some disadvantages. One is that it's inefficient. Another is that it's sensitive to the idiosyncracies of how your programming language handles equality comparisons on complex structures; and these details turn out to be very complex and vary from language to language (and even across different versions of different implementations of a single language). We'd be glad to discuss these subtleties offline, but if you're not prepared to master them, it would be smart to foster an ingrained hesitation to blindly applying a language's `=` operator to complex structures. (Some problem cases: large numbers, set structures, structures that contain functions.) A third difficulty is that it's sensitive to the particular combinators we took as basic. With `S` and `K` and `I`, it can never happen that a term has been reduced, but the output is identical to the input. That can happen in the lambda calculus, though (remember `&omega; &omega;`); and it can happen in combinatorial logic if other terms are chosen as primitive (`W W1 W2` reduces to `W1 W2 W2`, so let them all just be plain `W`s).
+Let's think about how we should detect that the term has been reduced as far as we can take it. In the substitute-and-repeat interpreter Chris demonstrated for combinatory logic, we had the `reduce_if_redex` function perform a single reduction *if it could*, and then it was up to the caller to compare the result to the original term to see whether any reduction took place. That worked for the example we had. But it has some disadvantages. One is that it's inefficient. Another is that it's sensitive to the idiosyncrasies of how your programming language handles equality comparisons on complex structures; and these details turn out to be very complex and vary from language to language (and even across different versions of different implementations of a single language). We'd be glad to discuss these subtleties offline, but if you're not prepared to master them, it would be smart to foster an ingrained hesitation to blindly applying a language's `=` operator to complex structures. (Some problem cases: large numbers, set structures, structures that contain functions.) A third difficulty is that it's sensitive to the particular combinators we took as basic. With `S` and `K` and `I`, it can never happen that a term has been reduced, but the output is identical to the input. That can happen in the lambda calculus, though (remember `ω ω`); and it can happen in combinatory logic if other terms are chosen as primitive (`W W1 W2` reduces to `W1 W2 W2`, so let them all just be plain `W`s).
 
 So let's consider different strategies for how to detect that the term cannot be reduced any further. One possibility is to write a function that traverses the term ahead of time, and just reports whether it's already a result, without trying to perform any reductions itself. Another strategy is to "raise an exception" or error when we ask the `reduce_head_once` function to reduce an irreducible term; then we can use OCaml's error-handling facilities to "catch" the error at an earlier point in our code and we'll know then that we're finished. Pierce's code used a mix of these two strategies.
 
@@ -235,10 +223,29 @@ The structure of our `reduce_head_once` function, then, will look like this:
 
     let rec reduce_head_once (term : term) (env : env) : reduceOutcome =
       match term with
-      | _, AA -> TODO
-      | _, BB ->
-
-We've supplied some of the guts of this function, especially the fiddly bits about how to deal with primitives and literals. But you need to fill in the gaps yourself to make it work. As mentioned before, don't worry about the environments. They're needed to see if variables are associated with any toplevel declarations, but we've filled in that part of the code ourselves. You don't need to worry about the primitives or literals, either.
+      | _,TermLambda _
+      | _,TermPrimfun _
+      | _,TermConstructor _
+      | _,TermDestructor _
+      | _,TermLiteral _ -> AlreadyResult (result_of_term term)
+
+      | fi,TermVar var -> ...
+
+      (* notice we never evaluate a yes/no branch until it is chosen *)
+      | _,TermIf((_,TermLiteral(Bool true)),yes,no) ->
+          ReducedTo yes
+      | _,TermIf((_,TermLiteral(Bool false)),yes,no) ->
+          ReducedTo no
+      | fi,TermIf(test,yes,no) ->
+          (match reduce_head_once test env with
+          | AlreadyResult _ -> StuckAt term (* if test was not reducible to a bool, the if-term is not reducible at all *)
+          | StuckAt _ as outcome -> outcome (* propagate Stuck subterm *)
+          | ReducedTo test' -> ReducedTo(fi,TermIf(test',yes,no)))
+
+      | ...
+  
+
+The homework asked you to fill in some of the gaps in this function. As mentioned before, the only role that environments play in this function is to see if variables are associated with any toplevel bindings. (If you're willing to forego those, you can select an implementation `Env0` of the environments that is guaranteed to do nothing.)
 
 Now, some function needs to call the `reduce_head_once` function repeatedly and figure out when it's appropriate to stop. This is done by the `reduce` function, which looks like this:
 
@@ -250,15 +257,17 @@ Now, some function needs to call the `reduce_head_once` function repeatedly and
 
 This recursively calls `reduce_head_once` until it gets a result or gets stuck. In the latter case, it calls a function that prints an error message and quits the program. If it did get a result, it returns that to the caller.
 
+The structure of these two functions, `reduce_head_once` and `reduce`, is similar to the functions `reduce_if_redex` and `reduce_try2` in the [[combinatory evaluator|/code/ski_evaluator.ml]]. The only difference is that `reduce_if_redex` only
+performed a reduction if its argument was exactly a redex. It had to rely on its caller to detect cases where the term was instead a longer sequence of applications that had a redex at its head.  In the present code, on the other hand, we have `reduce_head_once` take care of this itself, by calling itself recursively where appropriate. Still, it will only perform at most one reduction per invocation.
 
 One of the helper functions used by `reduce_head_once` is a `substitute` function, which begins:
 
     let rec substitute (ident : identifier) (replacement : term) (original : term) =
       match original with ...
 
-This makes sure to substitute the replacement for any free occurrences of `Var ident` in the original, renaming bound variables in the original as needed so that no terms free in the replacement become captured by binding `Lambda`s or `Let`s in the original. This function is tricky to write correctly; so we're just supplying it for you.
+This makes sure to substitute the replacement for any free occurrences of `Var ident` in the original, renaming bound variables in the original as needed so that no terms free in the replacement become captured by binding `Lambda`s or `Let`s in the original. This function is tricky to write correctly; so we supplied it for you.
 
-However, one of the helper functions that *it* calls is `free_in (ident : identifier) (term : term) : bool`, and this was a function that you did write for an earlier homework. You should adapt your implementation of that to the datatype we're using here. Here is a skeleton:
+However, one of the helper functions that *it* calls is `free_in (ident : identifier) (term : term) : bool`, and this was a function that you did [[write for an earlier homework|/exercises/assignment5/#occurs_free]]. Hence we asked you to adapt your implementation of that to the term datatype used in this interpreter. Here is a skeleton of this function:
 
     let rec free_in (ident : identifier) (term : term) : bool =
       match term with
@@ -277,19 +286,27 @@ However, one of the helper functions that *it* calls is `free_in (ident : identi
 
 That is, `Var ident` occurs free in `Var var_ident` iff the identifiers `ident` and `var_ident` are the same. The last four cases are easy: primitive functions, constructors, destructors, and literals contain no bindable variables so variables never occur free in them. These values may contain *results*, for instance if we partially apply the primitive function `+` to `3`, what we'll get back is another primitive function that remembers it has already been applied to `3`. But our interpreter is set up to make sure that this only happens when the argument (`3`) is already a result, and in our design that means it doesn't contain any bindable variables.
 
-But now what about the cases for App, Lambda, Let, and If? You will need to supply the missing code for these. It's just an adaptation/extension of what you did in the previous week's homework.
+But now what about the cases for `App`, `Lambda`, `Let`, and `If`? Think about what the code for these should look like. It's just an adaptation/extension of what you did in the previous week's homework. In the assignment, we supplied some of the code for these, and asked you to complete the rest.
 
-For reference, OCaml's disjunction operator is written with an infix `||`; conjunction with `&&`; equality with `=`; and inequality with `<>`. TODO MORE TIPS
+We also asked you to fill in some gaps in the `reduce_head_once` function.
+
+
+Moving to the VB/environment-based interpreter
+----------------------------------------------
 
-You should also fill in the gaps in the `reduce_head_once` function, as described above. You can do this all with pencil and paper and your brain, and **that will constitute phase 1 of (this part of) the homework.** But you can also download the real source code, as we'll explain below, and try to build/compile your work, and see if OCaml accepts it. Then you can play around with the result.
+The previous interpreter strategy is nice because it corresponds so closely to the reduction rules we give when specifying our lambda calculus. (Including specifying evaluation order, which redexes it's allowed to reduce, and so on.) But keeping track of free and bound variables, computing fresh variables when needed, that's all a pain.
 
-If you're not going to do that, then skip down and read about Moving to the V2 interpreter. TODO link
+Here's a better strategy. Instead of keeping all of the information about which variables have been bound or are still free implicitly inside of the terms, we'll keep a separate scorecard, which we will call an "environment". This is a familiar strategy for philosophers of language and for linguists, since it amounts to evaluating terms relative to an assignment function. The difference between the substitute-and-repeat approach above, and this approach, is one huge step towards monads.
+
+[[Read this page explaining about the need for Closures in this interpreter strategy.|/topics/week7_environments_and_closures]].
+
+Now `Closure`s are not a new kind of lambda _term_: the syntax for our language doesn't have any constituents that get parsed into `Closure`s. `Closure`s are only created _during the course of evaluating_ terms: specifically, when a variable gets bound to an abstract, which may itself contain variables that are locally free (not bound by the abstract itself). This is why we have separate datatypes for _terms_ and for the _results_ that terms can evaluate to. `Closure`s are results, but they aren't terms. `App`s are terms, but not results. Our boolean and number literals, as well as our primitive functions, constructors, and destructors, are both.
 
 
 Getting, reading, and compiling the source code
 -----------------------------------------------
 
-You can download the source code for the intepreter here: TODO link. That link will always give you the latest version. We will update it as we find any issues. Let us know about any difficulties you experience.
+You can download the source code for the intepreter [[here|/code/untyped_full.tgz]]. That link will always give you the latest version. We will update it as we find any issues. Let us know about any difficulties you experience.
 
 When you unpack the downloaded source code, you will get a folder with the following contents, sorted here by logical order rather than alphabetically.
 
@@ -308,17 +325,30 @@ When you unpack the downloaded source code, you will get a folder with the follo
     hilevel.mli
     lolevel.mli
     Makefile
+    test.f
     .depend
 
-The first three files in this list are the only ones you need to worry about.
+The first three files in this list are the ones you should focus on.
+
+An `.mli` file like `interface.mli` specifies types for OCaml, in a way that gets published for other files in the same program to see. This `interface.mli` file contains the basic datatypes the program works with. And even this file (necessarily) has some complexity you can ignore. All you really need to pay attention to at first are the datatypes we described before.
 
-An `.mli` file like `interface.mli` specifies types for OCaml, in a way that gets published for other files in the same program to see. This `interface.mli` file contains the basic datatypes the program works with. And even this file (necessarily) has some complexity you can ignore. All you really need to pay attention to at first are the datatypes we described before. For phase 1 of the exercise TODO, you shouldn't need to change anything in this file anyway.
+The second file, `types.ml`, contains different implementations for the environments. If you like, you can look at how these work. The common interface these implementations have to supply is declared in the previous file:
 
-The second file, `types.ml`, contains different implementations for the environments. If you like, you can look at how these work, since they will play an important role in phase 2 of the exercise. The common interface these implementations have to supply is: TODO Each implementation is itself pretty simple, though this file also needs to have some trickery in it to work around constraints imposed by OCaml. (The trickery is marked as such.)
+    module type ENV = sig
+      type env
+      val empty : env
+      val shift : identifier -> binding -> env -> env
+      val lookup : identifier -> env -> binding option
+      val version : string
+    end (* ENV *)
 
-The third file, `engine.ml`, is where you should be focusing your attention. That contains the skeleton of the `reduce_head_once` and `free_in` functions that you need to complete for phase 1 of the exercise, and also contains the skeleton of the `eval` function that you need to complete for phase 2 of the exercise. At the bottom of the file are also instructions on how to shift the interpreter between using the V1 or the V2 functions.
+Each implementation of that interface is itself pretty simple, though the file `types.ml` does need to have some trickery in it to work around constraints imposed by OCaml. (The trickery is marked as such.)
 
-After you've edited the `engine.ml` file to complete the `reduce_head_once` function, you can try building it and running the interpreter like this. First, make sure you're in a Terminal and that you're working directory is the folder that the source code unpacked to. Then just type `make`. That should take care of everything. If you see errors that you don't think are your fault, let us know about them.
+TODO
+
+The third file, `engine.ml`, is where the action is. Most of the homework assignment was just a simplified version of this file. At the bottom of the file are also instructions on how to shift the interpreter between using the VA or the VB functions.
+
+You can try building it and running the interpreter like this. First, make sure you're in a Terminal and that you're working directory is the folder that the source code unpacked to. Then just type `make`. That should take care of everything. If you see errors that you don't think are your fault, let us know about them.
 
 Possibly some Windows computers that _do_ have OCaml on them might nonetheless fail to have the `make` program. (It isn't OCaml-specific, and will be found by default on Macs and many Linux systems.) In that case, you can try entering the following sequence of commands by hand:
 
@@ -351,7 +381,7 @@ The interpreter you built is called `interp` (or on Windows, `interp.exe`). You
 
 The interpreter takes input that you feed it, by any of various methods, and passes it through a _parser_. The parser expects the input to contain a sequence of terms (plus possibly the other toplevel declarations we described before), separated by semicolons. It's optional whether to have a semicolon after the last term.
 
-If the input doesn't parse correctly, you will have a Syntax error TODO. If it does parse, then the parser hands the result off to your interpretation functions (either `reduce`/`reduce_head_once` in V1 of the interpreter, or `eval`/`evaluate`, in V2 described below). If they are able to reduce/evaluate each term to a result, they will print those results in a user-friendly format, and then move to the next result. If they ever encounter a stuck term or unbound variable, they will instead fail with an error.
+If the input doesn't parse correctly, you will get a "Syntax error." If it does parse, then the parser hands the result off to your interpretation functions (either `reduce`/`reduce_head_once` in VA of the interpreter, or `eval`/`evaluate`, in VB). If they are able to reduce/evaluate each term to a result, they will print those results in a user-friendly format, and then move to the next result. If they ever encounter a stuck term or unbound variable, they will instead fail with an error.
 
 So how do you supply the interpreter with input. Suppose the file `./input` contains:
 
@@ -368,7 +398,7 @@ Then here is a demonstration of three methods for supplying input. These will al
 
 In the last method, the different `-e` elements are concatenated with `;`s; and then it works just like the preceding methods.
 
-The format the parser accepts should look somewhat familiar to you. Lambda expressions work as normal, except that they must always be "dotted". You can also use some infix operators in the ways you can in Kapulet and Haskell:
+The format the parser accepts should look somewhat familiar to you. Lambda expressions work as normal, except that they must always be "dotted" (that is, use `\x.x` not `\x x`). You can also use some infix operators in the ways you can in Kapulet and Haskell:
 
     2-1
     (-) 2 1
@@ -384,6 +414,8 @@ As an experiment, the parser accepts two kinds of numeric input. Numbers like `0
 
 The supplied primitives `pred`, `succ`, and `zero?` work only on the dotted numbers; whereas the supplied infix primitives `+`, `-`, and `*` work only on the undotted numbers. There are also `<` and `<=` and `==` for the undotted numbers. (The parser will also accept `>` and `>=`, but will translate them into the corresponding uses of `<` and `<=`.)
 
+This version of the interpreter doesn't come pre-equipped with any Church numbers (or booleans or tuples or lists), but you can code them manually if you like. You can also code a fixed point combinator manually if you like. But be sure to use [[Θ′ or Y′|topics/week4_fixed_point_combinators/#primed]], since the unprimed fixed point combinators we introduced you to won't terminate in a call-by-value interpreter, like this one. (The [[lambda evaluator on the website|/code/lambda_evaluator]], by contrast, uses a normal order evaluation strategy.)
+
 Here is some more sample inputs, each of which the parser is happy with:
 
     /* these are comments */
@@ -414,12 +446,13 @@ Here is some more sample inputs, each of which the parser is happy with:
     id x
     const x y /* our friend the K combinator */
     flip f x y /* gives f y x */
-    g comp f /* comp is an infix composition operator */
-    f pmoc g /* this is flip comp, that is \x.g(f x) */
+    g o f /* `o` is an infix composition operator */
     f x $ g y $ h z /* as in Haskell, this is f x (g y (h z)) */
     /* note that it's not f x (g y) (h z) */
     "strings" /* you can input these and pass them around, but can't perform any operations on them */
 
+Predefined combinators include: `S`, `K` (same as `const`), `I` (same as `id`), `B` (same as `(o)`, occurring in prefix not infix position), `C` (same as `flip`), `T`, `V` (the Church pairing combinator), `W`, `M` (better known as `ω`), and `L`.
+
 The parser also accepts `letrec ... in ...` terms, but currently there is no implementation for how to reduce/interpret these (that's for a later assignment), so you'll just get an error.
 
 As explained before, you can also include toplevel declarations like:
@@ -437,10 +470,3 @@ Another toplevel declaration `symbol w` tells the interpreter that you want to s
 
 If the interpreter encounters other locally-unbound variables, where no toplevel declaration has already been given, it will fail with an error.
 
-
-
-Moving to the V2/environment-based interpreter
-----------------------------------------------
-
-...
-