\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/5/2004}
{} % {Problem Set 4}
{} % {Instructor: foo}
{Tutorial 8} %{Bryan Russell}

\section*{Upcoming Deadlines}

\begin{itemize}
\item Problem set 7 due Tuesday, 4/6 at midnight
\item Lecture 16 due Wednesday, 4/7 at 9am
\item Lecture 17 LIVE on Thursday, 4/8 at 10am
\item Project 4 computer exercise 8 due Wednesday, 4/7 via e-mail
\item Project 4 due Friday, 4/9 at 6pm
\item Office hours next week: Tuesday 4/13, 3-5pm in 34-501
\item Quiz 2 Tuesday, 4/13 7:30pm-9:30pm
\end{itemize}

\section*{Sonnet 6001}

\begin{it}
Double double-oh-one trouble\\
Lambda turn to double bubble\\
Params and body annotated\\
Pointing where evaluated\\
If combination be in question\\
First eval each subexpression\\
Applying first to rest yields trouble\\
When thy first be double bubble\\
To apply beget a frame\\
Where bound each value be to name\\
Point thy frame where bubbles point\\
Frame and bubble be now joint\\
Body's value in this frame\\
Is what thy combo's val became\\
\\
--William Shakespeare
\end{it}

\section*{Fun with OOP Queue}

\begin{verbatim}
(define (create-queue) QUESTION-1)

(define (make-queue QUESTION-2)
  (let (QUESTION-3)
    (lambda (message)
      (case message
        ((TYPE) (lambda () (type-extend 'queue QUESTION-4)))
        ((ENQUEUE) QUESTION-5
        ((DEQUEUE) QUESTION-6
        ((EMPTY?) QUESTION-7
        (else (get-method message QUESTION-8))))))
\end{verbatim}

\section*{I'm Hungry!}

\begin{verbatim}
(define (create-tummy name) QUESTION-9)

(define (make-tummy self name)
  (let (QUESTION-10)
    (lambda (msg)
      (case msg
        ((TYPE) (lambda () (type-extend 'tummy QUESTION-11)))
        ((EMPTY?) (lambda ()
                    (ask queue 'EMPTY?)))
        ((ADD-THING)
         (lambda (new-thing)
           QUESTION-12))
        ((EJECT)
         (lambda ()
           (let ((thing QUESTION-13))
             (cond ((null? thing) nil)
                   ((ask self 'HAVE-THING? thing)
                    (ask place-part 'DEL-THING thing)
                    thing)
                   (else (ask self 'EJECT))))))
        (else (get-method msg QUESTION-14))))))
\end{verbatim}

\begin{verbatim}
(define (create-hungry-dude name birthplace activity miserly) 
  QUESTION-15)

(define (make-hungry-dude self name birthplace activity miserly)
  (let (QUESTION-16)
    (lambda (msg)
      (case msg
        ((TYPE) (lambda () (type-extend 'hungry-dude QUESTION-17)))
        ((INSTALL)
         (lambda ()
           QUESTION-18))
        ((EAT)
         (lambda ()
           (let ((people (ask self 'PEOPLE-AROUND)))
             (map (lambda (p)
                    (ask p 'CHANGE-LOCATION tummy)
                    (ask self 'SAY `(,(ask p 'NAME) " is tasty!"))) 
                  people))))
        ((EJECT)
         (lambda ()
           (if (and (not (ask self 'EMPTY?)) (= (random 2) 0))
               (let ((p QUESTION-19))
                 (ask p 'CHANGE-LOCATION (ask self 'LOCATION))
                 (ask self 'SAY `("I don't need " ,(ask p 'NAME)))))))
        ((DIE)
         (lambda (perp)
           (let ((people (ask self 'THINGS))
                 (location (ask self 'LOCATION)))
             (map (lambda (p)
                    (ask p 'CHANGE-LOCATION location)
                    (ask p 'SAY '("It was cramped in there")))
                  people))
           (ask clock 'REMOVE-CALLBACK self 'eat)
           (ask clock 'REMOVE-CALLBACK self 'eject)
           (ask self 'DIE perp)))
        (else (get-method msg QUESTION-20))))))
\end{verbatim}

\end{document}
