This part is about Assignment, local state and the environment model.
There is a lot of new material here. It will take getting used to. You will find this material in Sections 3.1 and 3.2 of the text.
For this first part of the assignment, you will hand in problems 2 and 5 as a pdf, and the rest of the problems as code to the autograder (similar to HW3)
- Please note that problems 2 and 5 are exercises that show that you understand the environment model. To do this, you have to go back and do exactly what we discussed in class. If you just think you sort of understand things and write down what seems to be correct, you will almost certainly get these problems wrong. Many students in the past have done just that, and then they are astonished to find out that what they did makes no sense at all. Note: You may hand-draw the environments or use any software you want, but one thing is important I should be able to read and understand what you wrote.
- Put your answers to the rest of the problems in file scm and upload it to Gradescope, with discussion when required as Scheme comments. Any tests that you ran that are in this file should also be commented out. As before your code should be written in R5RS.
Questions
- Rewrite the make-account procedure on page 223 so that it uses lambda more explicitly. Create several versions, as follows. (Important: please do exactly what each of the three following versions specifies; no more and no less.)
(a) First version: First, replace
(define (make-account balance)
)
by
(define make-account-lambda (lambda
)
)
Then, for the first two internal procedure definitions, replace (define (proc args) ) with (define proc (lambda (args) )).
Finally, replace the
(define (dispatch ) ) dispatch)
construction with a lambda expression which is evaluated and returned (but of course not called). As indicated above, call this procedure make-account-lambda.
- Second version: Start with a copy of the first version. Then inline the internal procedures deposit and withdraw. That is, replace references to them by the bodies of the procedures. Then you can eliminate the definitions of those procedures. Call this procedure make-account-inline.
- Third version (A little extra credit): Start with a copy of the second version. I dont know how to say this without doing it for you, but you might then notice that a lambda can be factored out of the cond in your last version. (If you dont know what Im talking about here, just ignore this part of the problem.) If you do this, call this new version make-account-inline-factored.
Note that none of these three versions of make-account contains a dispatch procedure.
- Consider the procedure new-withdraw which we talked about in Lecture 6, and which we discussed again in Lecture 7. The implementation of that procedure is sketched in Figure 10 on page 8 of Lecture 7 (the figure numbers refer to the class notes at lec07.pdf).
- I want you to draw what that picture looks like after
(new-withdraw 25)
is evaluated.
- Then draw a second picture that shows the situation after
(new-withdraw 30)
is subsequently evaluated.
- Exercise 3.2 (page 224). Please read the statement of the problem very carefully. It tells you precisely what you should do. Please do exactly what it says. And do not use any global variables in doing this problem.
- Exercise 3.3 (page 225). In doing this problem, build on your solution to Problem 1. In fact, see if you can use one of your solutions to Problem 1 as a black box that is, make the solution to this problem a wrapper procedure that just invokes one of the versions of make-account from Problem 1, after handling password checks. In this way, you dont have to copy any of the body of the original make-account (It isnt necessary that you do it this way this is just a suggestion.)
Call your new function make-pw-account. And yes, I really mean this note that this is different from what the book says.
- Exercise 3.9 (page 243). Lets make it simpler, however: show how to compute (factorial 3) (rather than (factorial 6)).
Be sure to read the footnote. And follow the construction that I gave in class exactly. You may think the pictures should look different. And if something bothers you about how the pictures look, you should write about as a comment in your submitted pdf. But the construction that I specified is actually what happens internally. You will have to understand it for later assignments.

![[Solved] CS450 Assignment 4](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] CS450 Project3-RSA Encryption](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.