Homework 3

This is the archived website of SI 413 from the Fall 2012 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

- Print version, with cover page (pdf)
**Due Date**: 7 Sep- Relevant units: Unit 2 and Unit 3

**Use a separate sheet of paper for your answers!** Many of these exercises are programming exercises, but you do not need to submit them electronically. Everything should be turned in in one packet, all printed out for me to see.

Write a Scheme expression that is equivalent to the following Java code, by using a series of 3 nested `let`

expressions.

int x = 1; x += 3; x *= 12; return x;

The Wikipedia page on homoiconicity claims that raw machine code can be considered homoiconic, just like Scheme.

Explain what this means in a few sentences of your own.

Then tell me what properties of most homoiconic languages (like Scheme) does machine code definitely *not* have.

Scheme has a built-in function `add1`

which adds 1 to its argument.

But what if we wanted to create a similar function like `add2`

or `add20`

? Write a **function that produces a function** `make-adder`

that takes an argument `n`

and produces a lambda expression (function) that takes one argument and adds `n`

to it.

So for example `((make-adder 5) 10)`

produces `15`

.

Write a Scheme function `letter`

that takes a **quoted** `let`

expression and turns it into an equivalent quoted `lambda`

expression.

For example, calling

(letter '(let ((a 7) (b 10)) (* a b)))

should produce the expression `((lambda (a b) (* a b)) 7 10)`

. (And if you call `eval`

on that expression from the interactions window in DrScheme, you should get the result, 70.)

Write a function

`(double f)`

which takes a 1-argument function`f`

and produces a 1-argument function (as a lambda expression) that takes an argument`x`

and applies`f`

to it twice, like`(f (f x))`

.So for example calling

`((double sqrt) 16)`

is the same as calling`(sqrt (sqrt 16))`

, which is`2`

.Can we do

`(double double)`

? What does it do?