-
Notifications
You must be signed in to change notification settings - Fork 1
/
2.6.tex
35 lines (32 loc) · 882 Bytes
/
2.6.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
\documentclass[a4paper,12pt]{article}
\usepackage{listings}
\lstset{language=Lisp}
\begin{document}
We have,
\begin{lstlisting}
(add-1 zero)
\end{lstlisting}
$\rightarrow$ \lstinline!(lambda (f) (lambda (x) (f ((zero f) x))))! \\
$\rightarrow$ \lstinline!(lambda (f) (lambda (x) (f x)))!
\medskip
Thus we can define \lstinline!one! as
\begin{lstlisting}
(define one (lambda (f) (lambda (x) (f x))))
\end{lstlisting}
Continuing the evaluation
\begin{lstlisting}
(add-1 one)
\end{lstlisting}
$\rightarrow$ \lstinline!(lambda (f) (lambda (x) (f ((one f) x))))! \\
$\rightarrow$ \lstinline!(lambda (f) (lambda (x) (f (f x))))!
\medskip
Thus, we have
\begin{lstlisting}
(define two (lambda (f) (lambda (x) (f (f x)))))
\end{lstlisting}
And finally we can define $+$ as,
\begin{lstlisting}
(define (+ m n)
(lambda (f) (lambda (x) ((m f) ((n f) x)))))
\end{lstlisting}
\end{document}