Differences

This shows you the differences between two versions of the page.

assignment-5 [2016/02/04 13:51]
jhemann
assignment-5 [2016/02/12 10:07] (current)
jhemann
Line 15: Line 15:
==== Part 1 ==== ==== Part 1 ====
-Below is an interpreter that is complete except for its five helpers ''empty-env'', ''extend-env'', ''apply-env'', ''closure'', and ''apply-closure''.  This interpreter should look quite familiar to you, except that it adds two new forms to our language, ''begin2'' and ''random''.+Below is an interpreter that is complete except for its five helpers ''empty-env'', ''extend-env'', ''apply-env'', ''make-closure'', and ''apply-closure''.  This interpreter should look quite familiar to you, except that it adds two new forms to our language, ''begin2'' and ''random''.
<code lisp> <code lisp>
Line 32: Line 32:
      [`(random ,n) (random (value-of n env))]       [`(random ,n) (random (value-of n env))]
      [`,y #:when (symbol? y) (apply-env env y)]       [`,y #:when (symbol? y) (apply-env env y)]
-      [`(lambda (,x) ,body) (closure x body env)]+      [`(lambda (,x) ,body) (make-closure x body env)]
      [`(,rator ,rand) (apply-closure (value-of rator env)       [`(,rator ,rand) (apply-closure (value-of rator env)
                                      (value-of rand env))])))                                       (value-of rand env))])))
Line 47: Line 47:
|call-by-need |''val-of-cbneed'' | |call-by-need |''val-of-cbneed'' |
-  * You will need to implement the ''empty-env'', ''extend-env'', ''apply-env'', ''closure'', and ''apply-closure'' helpers.  Use a **functional representation** of both environments and closures. +  * You will need to implement the ''empty-env'', ''extend-env'', ''apply-env'', ''make-closure'', and ''apply-closure'' helpers.  Use a **functional representation** of both environments and closures. 
-  * For the most part, you can use the same set of helpers for every interpreter.  However, since ''closure'' calls the interpreter, you'll need to implement versions of ''closure'' to go along with each interpreter.+  * For the most part, you can use the same set of helpers for every interpreter.  However, since ''make-closure'' calls the interpreter, you'll need to implement versions of ''make-closure'' to go along with each interpreter.
  * All interpreters must handle the following: booleans, numbers, variables, ''lambda'', application, ''zero?'', ''sub1'', ''*'', ''if'', and ''random''.   * All interpreters must handle the following: booleans, numbers, variables, ''lambda'', application, ''zero?'', ''sub1'', ''*'', ''if'', and ''random''.
  * Your ''val-of-cbr'' and ''val-of-cbv'' interpreters (not the other two) must also handle ''begin2'' and ''set!''.   * Your ''val-of-cbr'' and ''val-of-cbv'' interpreters (not the other two) must also handle ''begin2'' and ''set!''.
Line 210: Line 210:
</code> </code>
-This returns some representation of procedures, depending on how we implement ''closure'' and ''apply-closure''.+This returns some representation of procedures, depending on how we implement ''make-closure'' and ''apply-closure''.
If we think of the language interpreted by ''value-of'' as a set of symbolic terms, though, we don't concern ourselves with more than one representation. Instead, we just rewrite one term to another term according to some rules. For example: If we think of the language interpreted by ''value-of'' as a set of symbolic terms, though, we don't concern ourselves with more than one representation. Instead, we just rewrite one term to another term according to some rules. For example:
 

assignment-5.txt · Last modified: 2016/02/12 10:07 by jhemann