# PS6

91.301 Organization of Programming Languages
Prof. F. Martin

Out: Mar 21, 2011
Due: Mar 28, 2011

## Overview

This problem set introduces streams, which are like lists but where the cdr of a stream is a procedural “promise” to evaluate something later, when it is needed.

Before doing this problem set, read the following material:

## Part 1: Environment Problems

First, some problems on the environment model and mutation. Read Section 3, 3.1, and 3.2.

Problem 1: Exercise 3.1 on pp. 224. After writing and testing the code, draw the environment diagram that would result from evaluating the three statements in the exercise.

Problem 2: Exercise 3.2 on pp. 224-225. After writing and testing the code, draw the environment diagram that would result from evaluating the three statements in the exercise.

Problem 3: Exercise 3.3 on pp. 225, creating a password-protected bank account.

Problem 4: Exercise 3.4 on pp. 225, modifying it to keep track of incorrect password accesses.

## Part 2: Now, the streams stuff.

Problem 5: Use `stream-map` (pp. 320 of textbook) to define a procedure called ` convert-temps` that takes a stream of temperatures in Fahrenheit and returns a stream of converted temperatures in Celsius. Recall that to convert Fahrenheit to Celsius, the equation is C = 5/9 * (F-32).

Problem 6: Use `stream-filter` (pp. 322 of textbook) to define the stream of all integers that are evenly divisible by 2, 3, or 5.

Problem 7: Complete the following alternative definition of the integers stream:

``` (define integers (cons-stream 1 (stream-map <??> integers)))
```

Problem 8: Exercise 3.51 on pp. 325, examining the delayed evaluation by printing results as they are computed.

Problem 9: Exercise 3.52 on pp. 325–326, delayed evaluation while state is changing.

Problem 10: Exercise 3.53 on pp. 330, thinking about how streams defined in terms of themselves operate.

Problem 11: Exercise 3.54 on pp. 331, implementing factorial with `mul-streams`, analogous to how Fibonacci is done in the text.

Problem 12: Exercise 3.57 on pp. 332, understanding memo-ization as it applies to the Fibonacci computation.

Turn in all of the above using `submit fredm 301-ps6 <your file.rkt>`.

## Part 3: Final Project Exploration 1

note: turn in with `submit fredm 301-fpe1 your-file`

In this exercise, you will play with at least one library provided by the PLT Scheme developers. You will have the opportunity to explore another library in each of the next two weeks.

Please choose libraries that you think you might be interested in using in your final project.

Then there are two places you can go for library code:

Your job is to explore one library and write up your results. Load the library and write some code to drive it around.

For example, if we look at the `net/url` library, we will find functions for creating URLs, issuing HTTP GET commands, and displaying the results. Here is a little bit of code for driving around a few of the functions in this library:

```#lang racket

(require net/url)

(define myurl (string->url "http://www.cs.uml.edu/"))
(define myport (get-pure-port myurl))
(display-pure-port myport)
```

Notice that `(require net/url)` is all you need to put in your buffer in order to load the library and start using it.

This above is a trivial example; to complete this for the purposes of this assignment (if you go down the path of pulling HTTP requests), you should use the parsing libraries to parse the HTML that is returned, and then do something with the results.

To turn in: at least 2 pages of interspersed code and narrative explaining what you did. Reminder again: please think about what you might want to work on for your final project, and choose a relevant library to work with.

REMEMBER YOU MUST GET SOMETHING WORKING! Do not just read about some API—play with it enough so that you can make it do stuff! And show me the stuff!