Description
Preliminary information This is your third Scam assignment.
At the top of your assignment, place a definition similar to the following:
(define (author) (println “AUTHOR: Izzy Iterator iiter@crimson.ua.edu”) ) with the name and email replaced by your own name and email.
For each numbered task (unless otherwise directed), you are to provide a function with a name of the form runN, with the N corresponding to the task number (as in run1, run2, etc.). This function is in addition to all other requested functions. These run functions will test your implementation and are to take no arguments. For example, if task 5 is: 5. Implement factorial so that it implements a recursive process. Name your function fact. you should provide a run function similar to:
(define (run5) (print “The result of (fact 3) is ” (fact 3)) (println “[it should be 6]”) … ) Woe betide students who provide insufficient testing should their implementations prove to be incorrect! If you do not complete an exercise, do not provide a run function for that exercise. If you omit the run function corresponding to an exercise, it will be assumed that you are skipping that part and you will receive no credit for that exercise.
When you have completed testing of your run functions, comment out any calls to them (but do not comment out the definitions).
Iwillprovideatestscriptwhichperformsminimaltestingofyourimplementation. Ifyourprogramdoesnotpasstheprovided test script without failing, I will not grade your exercise and you will receive zero credit for the assignment.
You may use assignment and loops for this set of tasks, unless otherwise directed. Tasks 1. Defineafunctionnamedlevel thatreturnsthestaticscopinglevelofagivenvariable. Ifthevariableislocal(i.e., defined in the same frame as the call to level, level should return 0. If the variable is found in the next outer scoping level, the return value should 1, and so on. Here is an example call: (define a 3) (define (f x) (inspect (level ‘a)) (* a x) ) The level function should return the symbol UNDEFINED if the desired variable is not defined locally or in any enclosing scope. You must decompose Scam environments (they are structured as lists) to do this task. That is, you may not use the local? function or any similar functions. You may find the predefined variable this and the predefined function ppTableuseful. Thevariablethispointstothecurrentenvironment/scope,whilethefunctionppTabledisplaysareadable rendering of an environment/scope. Example: (ppTable this) You can get the enclosing scope of an environment named e with the command:
(e’__context) 2. Define a function named cache that replaces all the non-local variables in a function body with the values found in the definition environment. You may assume that local variables will be defined with the define function. You do not need to process the bodies of nested functions.
You can retrieve the definition environment from a closure with: (define denv (get ‘__context square)) You can retrieve the value of a symbol in a list of symbols with: (define listOfSymbols ‘(+ – * /)) (get (car listOfSymbols) denv) ; get the closure bound to + Example: scam (define m 2) scam (define (msquare x) (* m x x)) scam (include “pretty.lib”) scam (pretty msquare) (define (msquare x) (* m x x) ) scam (cache msquare) scam (pretty msquare) (define (msquare x) (

