author | Christian Urban <christian.urban@kcl.ac.uk> |
Fri, 02 Dec 2022 16:26:20 +0000 | |
changeset 901 | 33cff35bdc1a |
parent 876 | 771396fa6cc4 |
child 916 | 10f834eb0a9e |
permissions | -rw-r--r-- |
59 | 1 |
\documentclass{article} |
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
2 |
\usepackage{../style} |
876 | 3 |
\usepackage{../langs} |
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
4 |
\usepackage{../graphics} |
59 | 5 |
|
6 |
\begin{document} |
|
7 |
||
75
898c25a4e399
tuned
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
60
diff
changeset
|
8 |
\section*{Homework 8} |
59 | 9 |
|
359
db106e5b7c4d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
10 |
\HEADER |
db106e5b7c4d
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
292
diff
changeset
|
11 |
|
59 | 12 |
\begin{enumerate} |
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
13 |
\item Write a program in the WHILE-language that calculates |
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
14 |
the factorial function. |
77
49c0beef79a1
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
76
diff
changeset
|
15 |
|
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
16 |
\item What optimisations could a compiler perform when |
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
17 |
compiling a WHILE-program? |
206
85b961f1eee9
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
18 |
|
292
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
19 |
\item What is the main difference between the Java assembler |
7ed2a25dd115
updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
206
diff
changeset
|
20 |
(as processed by Jasmin) and Java Byte Code? |
206
85b961f1eee9
added
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
102
diff
changeset
|
21 |
|
876 | 22 |
\item Consider the following Scala snippet. Are the two functions |
23 |
\texttt{is\_even} and \texttt{is\_odd} tail-recursive? |
|
24 |
||
25 |
\begin{lstlisting}[numbers=none] |
|
901 | 26 |
def is_even(n: Int) : Boolean = { |
27 |
if (n == 0) true else is_odd(n - 1) |
|
876 | 28 |
} |
29 |
||
901 | 30 |
def is_odd(n: Int) : Boolean = { |
876 | 31 |
if (n == 0) false |
901 | 32 |
else if (n == 1) true else is_even(n - 1) |
876 | 33 |
} |
34 |
\end{lstlisting} |
|
35 |
||
36 |
Do they cause stack-overflows when compiled to the JVM (for example by Scala)? |
|
37 |
||
530 | 38 |
|
39 |
\item Explain what is meant by the terms lazy evaluation and eager |
|
577 | 40 |
evaluation. |
41 |
||
42 |
\item \POSTSCRIPT |
|
59 | 43 |
\end{enumerate} |
44 |
||
45 |
\end{document} |
|
46 |
||
47 |
%%% Local Variables: |
|
48 |
%%% mode: latex |
|
49 |
%%% TeX-master: t |
|
50 |
%%% End: |