\batchmode










\documentstyle[11pt,psfig,epsf,landscape,twoside,color]{article}
\makeatletter

\pagestyle{myheadings}

%
\evensidemargin 35pt

%
\setcounter{secnumdepth}{0}

%

\setlength{\oddsidemargin}{0in}
%
\setlength{\textwidth}{6.5in}

%


\setlength{\topmargin}{-0.5in}
%
\setlength{\headheight}{0.25in}
%
\setlength{\headsep}{0.25in}
%
\setlength{\textheight}{8.5in}

%

\setlength{\parindent}{0in}

%
\setlength{\parskip}{\medskipamount}

%



%



%


%






%

\newlength{\hlessmm}
\setlength{\hlessmm}{\textwidth}
\addtolength{\hlessmm}{-2em}

\newlength{\hlessmmmm}
\setlength{\hlessmmmm}{\textwidth}
\addtolength{\hlessmmmm}{-4em}

%



%



%





%









\outer

\outer

\outer

{\obeyspaces\gdef {\ }}

%



 

%
\newlength{\illuswidth}
\setlength{\illuswidth}{\textwidth}
\addtolength{\illuswidth}{-7pt}

%


%



%


%



%


%








%














\setlength{\textheight}{9in}
\setlength{\textwidth}{6.7in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{-0.2in}

\definecolor{HiddenAnswer}{rgb}{1,1,1}
\definecolor{HighlitedAnswer}{rgb}{1,0,0}
\definecolor{EndOfAnswer}{rgb}{0,0,0}

\ifx\undefined\AnswerSheet

\else

\fi

%




\def\AnswerSheet{1}

\newcommand {\evalsto}{$\Longrightarrow$}

\newcommand {\hstrut}[1]{\hspace*{#1}}

\newcommand {\vstrut}[2]{\rule[#1]{0in}{#2}}

\newcommand {\hm}{\hspace*{1em}}

\newcommand {\hmm}{\hspace*{2em}}

\newcommand {\hmmm}{\hspace*{3em}}

\newcommand {\hmmmm}{\hspace*{4em}}

\newenvironment {tightlist}%
{\begin{list}{$\bullet$}{%
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\parsep}{0in}
    \setlength{\leftmargin}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}
}
}%
{\end{list}
}

\newcommand {\cf}{\footnotesize\tt}

\newcommand {\IP}{$\bullet$}

\newcommand {\RA}{{\Large \bf $\Rightarrow$}}

\newcommand {\goesto}{$\longrightarrow$}

\def\lisp#1{\footnotesize\tt #1}

\def\beginlispA{%
  \begin{minipage}[t]{\linewidth}
  \begin{list}{$\bullet$}{%
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\parsep}{0in}
    \setlength{\leftmargin}{0in}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}
  }\item[]
  \obeyspaces
  \obeylines \footnotesize\tt}

\def\beginlisp{%
  \begin{minipage}[t]{\linewidth}
  \begin{list}{$\bullet$}{%
    \setlength{\topsep}{0in}
    \setlength{\partopsep}{0in}
    \setlength{\itemsep}{0in}
    \setlength{\parsep}{0in}
    \setlength{\leftmargin}{1.5em}
    \setlength{\rightmargin}{0in}
    \setlength{\itemindent}{0in}
  }\item[]
  \obeyspaces
  \obeylines \footnotesize\tt}

\def\endlisp{%
  \end{list}
  \end{minipage}
  }

\def\psfileprefix{/usr/nikhil/parle/}

\def\illustration#1#2{
\vbox to #2{\vfill\special{psfile=\psfileprefix#1.ps hoffset=-72 voffset=-45}}}

\newcommand {\closure}[2]{%
\begin{tabular}[t]{l}
\raisebox{-1.5ex}{%
  \setlength{\unitlength}{0.2ex}
  \begin{picture}(25,15)(0,-7)
   \put( 5,5){\circle{10}}
   \put( 5,5){\circle*{1}}
   \put( 5,5){\vector(0,-1){10}}
   \put(15,5){\circle{10}}
   \put(15,5){\circle*{1}}
   \put(15,5){\vector(1,0){12}}
  \end{picture}}
  \fbox{\footnotesize #2} \\ 
%
\hspace*{0.8ex} \fbox{\footnotesize #1}
\end{tabular}
}

\newcommand {\proc}[2]{%
\begin{tabular}{l}
params: #1 \\ 
body: #2 \\ 
\end{tabular}
}

\newcommand {\psetheader}[2]{%
\markboth{6.001, #1---#2}{6.001, #1---#2}
\begin{center}
MASSACHVSETTS INSTITVTE OF TECHNOLOGY \\ 
Department of Electrical Engineering and Computer Science \\ 
6.001---Structure and Interpretation of Computer Programs \\ 
#1 \\ 
\medskip
{\bf #2}
\end{center}
}

\newcommand {\problem}[1]{{\bf #1}}

\newcommand {\key}[1]{\fbox{{\sc #1}}}

\newcommand {\ctrl}{\key{ctrl}--}

\newcommand {\shift}{\key{shift}--}

\newcommand {\run}{\key{run} \ }

\newcommand {\runkey}[1]{\run \key{#1}}

\newcommand {\extend}{\key{extend} \ }

\newcommand {\kkey}[1]{\key{k$_{#1}$}}

\def\fbox#1{%
  \vtop{\vbox{\hrule%
              \hbox{\vrule\kern3pt%
                    \vtop{\vbox{\kern3pt#1}\kern3pt}%
                    \kern3pt\vrule}}%
        \hrule}}

\def\emptybox#1#2{\fbox{\vbox to #2{\hbox to #1 {\null}}}}

\def\pscenter#1{\hbox to\hsize{\hss\psadobenomag{#1}\hss}}

\def\itemx{\vspace{-0.1in}\item}

\def\ANSWER#1{{\color{HiddenAnswer} #1 \color{EndOfAnswer}}}

\def\ANSWER#1{{\color{HighlitedAnswer} #1 \color{EndOfAnswer}}}

\makeatother
\newenvironment{tex2html_wrap}{}{}
\newwrite\lthtmlwrite
\def\lthtmltypeout#1{{\let\protect\string\immediate\write\lthtmlwrite{#1}}}%
\newbox\sizebox
\begin{document}
\pagestyle{empty}
\setcounter{secnumdepth}{0}
{\newpage
\clearpage
\samepage \begin{tabular}{p{3.0in}p{3.5in}} 

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (get-method message object)
  (object message))
\null
(define method? procedure?)

\end{list}
\end{minipage} 
&

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (ask object message . args)
  (let ((method (get-method message object)))
    (if (method? method)
        (apply method object args)
        (error "No method for mesage" message))))

\end{list}
\end{minipage} 
\end{tabular}
}

{\newpage
\clearpage
\samepage \begin{tabular}{p{3.5in}p{2.5in}}

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (create-stack)
{\color{HighlitedAnswer} 
  (let ((value '()))
 \color{EndOfAnswer}}
    (lambda (message)
      (case message
        ((PUSH)
{\color{HighlitedAnswer} 
         (lambda (self new)
           (set! value (cons new value))) \color{EndOfAnswer}})
        ((PEEK)
{\color{HighlitedAnswer} 
         (lambda (self) (car value)) \color{EndOfAnswer}})
        ((CLEAR)
{\color{HighlitedAnswer} 
         (lambda (self) (set! value '())) \color{EndOfAnswer}})
        ((POP)
{\color{HighlitedAnswer} 
         (lambda (self)
           (let ((return (ask self 'peek)))
             (set! value (cdr value))
             return)) \color{EndOfAnswer}})))))

\end{list}
\end{minipage} 
&

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define s (create-stack))
(ask s 'push 5)
(ask s 'push 3)
(ask s 'pop)            ==> 3
(ask s 'push 1)
(ask s 'pop)            ==> 1
(ask s 'pop)            ==> 5

\end{list}
\end{minipage} 
\end{tabular}
}

{\newpage
\clearpage
\samepage \begin{tabular}{p{3.5in}p{2.5in}}

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (create-var value)
{\color{HighlitedAnswer} 
  (let ((undo (create-stack)))
    (ask undo 'push value)
 \color{EndOfAnswer}}
    (lambda (message)
      (case message
        ((SET!)
{\color{HighlitedAnswer} 
         (lambda (self new)
           (ask undo 'push new)) \color{EndOfAnswer}})
        ((GET)
{\color{HighlitedAnswer} 
          (lambda (self)
            (ask undo 'peek)) \color{EndOfAnswer}})
        ((UNDO!)
{\color{HighlitedAnswer} 
         (lambda (self)
           (ask undo 'pop)) \color{EndOfAnswer}})))))

\end{list}
\end{minipage} 
&

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define a (create-var 1))
(ask a 'get)                    ==> 1
(ask a 'set! 2)                 
(ask a 'get)                    ==> 2
(ask a 'undo!)
(ask a 'get)                    ==> 1

\end{list}
\end{minipage} 
\end{tabular}
}

{\newpage
\clearpage
\samepage \begin{tabular}{p{3.5in}p{2.5in}}

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (create-pair car-val cdr-val)
{\color{HighlitedAnswer} 
  (let ((last-change (create-var '()))
        (the-car (create-var car-val))
        (the-cdr (create-var cdr-val)))
 \color{EndOfAnswer}}
   (lambda (message)
    (case message
      ((SET-CAR!)
{\color{HighlitedAnswer} 
       (lambda (self new)
         (ask last-change 'set! 'car)
         (ask the-car 'set! new)) \color{EndOfAnswer}})
      ((SET-CDR!)
{\color{HighlitedAnswer}        (lambda (self new)
         (ask last-change 'set! 'cdr)
         (ask the-cdr 'set! new)) \color{EndOfAnswer}})
      ((CAR)
{\color{HighlitedAnswer}        (lambda (self) (ask the-car 'get)) \color{EndOfAnswer}})
      ((CDR)
{\color{HighlitedAnswer}        (lambda (self) (ask the-cdr 'get)) \color{EndOfAnswer}})
      ((PRINT)
       (lambda (self)
         (display (ask self 'car))
         (display "."
         (display (ask self 'cdr))))
      ((UNDO!)
{\color{HighlitedAnswer}        (lambda (self)
         (case (ask last-change 'undo!)
           ((CAR) (ask the-car 'undo!))
           ((CDR) (ask the-cdr 'undo!)))) \color{EndOfAnswer}})))))

\end{list}
\end{minipage} 
&

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define p (create-pair 1 2))
(ask p 'print)         ==> (1 . 2)
(ask p 'set-car! 3)  
(ask p 'print)         ==> (3 . 2)
(ask p 'set-cdr! 4)  
(ask p 'print)         ==> (3 . 4)
(ask p 'set-car! 5)  
(ask p 'print)         ==> (5 . 4)
(ask p 'undo!)       
(ask p 'print)         ==> (3 . 4)
(ask p 'undo!)       
(ask p 'print)         ==> (3 . 2)
(ask p 'undo!)       
(ask p 'print)         ==> (1 . 2)

\end{list}
\end{minipage} 
\end{tabular}
}

{\newpage
\clearpage
\samepage \begin{tabular}{p{3.5in}p{2.5in}}

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define (create-var value)
{\color{HighlitedAnswer} 
  (let ((undo (create-stack))
        (redo (create-stack)))
   (ask undo 'push value)
 \color{EndOfAnswer}}
   (lambda (message)
    (case message
      ((SET!)
{\color{HighlitedAnswer} 
       (lambda (self new)
         (ask redo 'clear)
         (ask undo 'push new)) \color{EndOfAnswer}})
      ((GET)
{\color{HighlitedAnswer}         (lambda (self)
          (ask undo 'peek)) \color{EndOfAnswer}})
      ((UNDO!)
{\color{HighlitedAnswer}        (lambda (self)
         (ask redo 'push (ask undo 'pop))) \color{EndOfAnswer}})
      ((REDO!)
{\color{HighlitedAnswer}        (lambda (self)
         (ask undo 'push (ask redo 'pop))) \color{EndOfAnswer}})))))

\end{list}
\end{minipage} 
&

\begin{minipage}[t]{\linewidth}
\begin{list}{$\bullet$}{%
\setlength{\topsep}{0in}
\setlength{\partopsep}{0in}
\setlength{\itemsep}{0in}
\setlength{\parsep}{0in}
\setlength{\leftmargin}{1.5em}
\setlength{\rightmargin}{0in}
\setlength{\itemindent}{0in}
}\item[]
\obeyspaces
\obeylines \footnotesize\tt 
(define a (create-var 1))
(ask a 'set! 2)
(ask a 'undo!)
(ask a 'get)    ==> 2
(ask a 'undo!)
(ask a 'get)    ==> 1
(ask a 'redo!)
(ask a 'get)    ==> 2

\end{list}
\end{minipage} 
\end{tabular}
}

\stepcounter{section}

\end{document}
