\iffalse

INSTRUCTIONS: (if this is not ps1, use the right file name)

  Clip out the ********* INSERT HERE ********* bits below and insert
appropriate TeX code.  Once you are done with your file, run

  ``latex template.tex''

from the Athena shell.  If your TeX code is clean, the latex will exit
back to a prompt.  Once this is done, run

  ``dvips template.dvi -o template.ps''

which should print your file to the nearest printer.  There will be
residual files called ps1.log, ps1.aux, and ps1.dvi.  All these can be
deleted, but do not delete ps1.tex.

\fi
\documentclass[11pt]{article}
\usepackage{amsfonts}
\usepackage{latexsym}
\usepackage{graphicx}
\setlength{\oddsidemargin}{.25in}
\setlength{\evensidemargin}{.25in}
\setlength{\textwidth}{6in}
\setlength{\topmargin}{-0.4in}
\setlength{\textheight}{8.5in}
\setlength{\parindent}{0pt}
%\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}

\newcommand{\var}[0]{
  \textrm{var}
}

\newcommand{\E}[0]{
  \mathbf{E}
}

\newcommand{\cov}[0]{
  \textrm{cov}
}

\newcommand{\handout}[5]{
   \renewcommand{\thepage}{\arabic{page}}
   \noindent
   \begin{center}
   \framebox{
      \vbox{
    \hbox to 5.78in { {\bf 6.001 SICP Spring 2004} \hfill #2 }
       \vspace{4mm}
       \hbox to 5.78in { {\Large \hfill #5  \hfill} }
       \vspace{2mm}
       \hbox to 5.78in { {\it #3 \hfill #4} }
      }
   }
   \end{center}
   \vspace*{4mm}
}

\newcommand{\ho}[5]{\handout{#1}{#2}{Instructor:
#3}{Teaching Assistant: #4}{Handout #1: #5}}
\newcommand{\al}{\alpha}
\newcommand{\Z}{\mathbb Z}

\begin{document}
\handout{P1}{4/12/2004}
{} % {Problem Set 4}
{} % {Instructor: foo}
{Tutorial 9} %{Bryan Russell}

\section*{Upcoming Deadlines}

\begin{itemize}
\item Office hours this week: Tuesday 4/13, 3-5pm in 34-501
\item Quiz 2 Tuesday, 4/13 7:30pm-9:30pm
\item Lecture 18 due Friday, 4/16 at 9am
\item No tutorial Monday/Tuesday next week (institute holiday)
\end{itemize}

\section*{Quiz II Review}

\begin{verbatim}
(define (memoize proc)
  (let ((return '()))
    (lambda (arg)
      (if (assq arg return)
          (cadr (assq arg return))
        (let ((new-val (proc arg)))
          (set! return (cons (list arg new-val) return))
          new-val)))))
\end{verbatim}

\subsection*{Exercise 1}
\begin{verbatim}
(define memo-sq EXERCISE1)
\end{verbatim}

\subsection*{Exercise 2}
Draw the environment diagram for the following:

\begin{verbatim}
(memo-sq 5)
\end{verbatim}

\subsection*{Exercise 3}
Do the same for fibonacci:

\begin{verbatim}
(define memo-fib EXERCISE3)

(memo-fib 3)
\end{verbatim}

\subsection*{Exercise 4}

What does the following do?

\begin{verbatim}
(define (mystery x)
  (define (loop x y)
    (if (null? x)
        y
      (let ((temp (cdr x)))
        (set-cdr! x y)
        (loop temp x))))
  (loop x '()))
\end{verbatim}

\subsection*{Exercises 5-9: Trie Data Structure}

\begin{verbatim}
(define (make-node value) EXERCISE5)

(define (trie-node? x) EXERCISE6)

(define (node-value node) EXERCISE7)

(define (node-child item node) EXERCISE8)

(define (trie-lookup key node)
  (if (null? key)
      (node-value node)
      (let ((child (node-child (car key) node)))
        (if child
            (lookup (cdr key) child)
            #f))))

(define (trie-insert! key value node)
  EXERCISE9)
\end{verbatim}


% \begin{verbatim}
% (define (create-ring lst)
%   (create-instance make-ring lst))

% (define (make-ring self lst)
%   (let ((root-part (make-root-object self))
%         (pointer lst)
%         (last-pointer lst))
%     (lambda (msg)
%       (case msg
%         ((CONNECT) (lambda ()
%                      (set-cdr! (last lst) lst)))
%         ((VALUE) (lambda ()
%                    (car pointer)))
%         ((RIGHT) (lambda ()
%                    EXERCISE5))
%         ((LEFT) (lambda ()
%                   EXERCISE6))
%         ((UPDATE) (lambda ()
%                     (set! last-pointer pointer)
%                     'done))
%         ((ROTATE) (lambda (dirn)
%                     (ask self dirn)
%                     (ask self 'UPDATE)))
%         (else (get-method msg root-part))))))
% \end{verbatim}

% \subsection*{Exercise 7}
% Write last:

% \begin{verbatim}
% (define (last lst) EXERCISE7)
% \end{verbatim}

\end{document}
