Hi everyone, Here is some more information about the first homework assignment. First are some tips on things to look out for when doing it, and then is a description of what to turn in and how to turn it in. Tips ---- *) Scoping: You should make sure to implement lexical, as opposed to dynamic, scoping in your interpreter. This distinction is important for implementing the evaluation of function calls properly. *) Recursion: If you don't do anything special, your interpreter will not properly support recursive functions. For this assignment, recursion is optional. You can get extra credit by implementing it, but you should not use side effects to do so. *) Function invocation: You must implement the semantics of invoking the first function case whose pattern is matched by the argument value (we'll go over pattern matching in class on Friday). The (partially implemented) matchPattern function in eval.sml will try to match a value to a pattern, raising a MatchFailure exception if this cannot be done. Therefore, a nice way to implement the function-case lookup semantics is as follows: Try to match the argument against the first case's pattern. If it succeeds, invoke the case's body in an appropriately extended environment. If it fails, handle the MatchFailure exception and (in the handler body) recursively try to match against the rest of the cases. If there are no more cases, then an EvalError should be reported. What to turn in --------------- You should turn in your version of the file eval.sml. In addition, we'd like you to answer the following questions: 1) Is it possible to support mutually recursive functions in the current syntax of the interpreter? Why or why not? 2) Consider the following code: val x = 3 fun f() = x val x = 4 f() The result of f() is 3, not 4. Explain why. 3) Consider the following code: fun f(x) = (let val x = 3 in x*x end) + x f(2) The result of f(2) is 11. In this invocation of f, the first two uses of x in the body have value 3, while the last use of x has value 2. How does the binding from x to 3 get removed from the environment in your interpreter? How to turn in -------------- Turn in your assignment by emailing it to me at todd@cs. Please send the assignment as two attachments: one for eval.sml and another for a text file with the answers to the three questions above. Thanks. Todd