| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Tue, 03 Oct 2023 23:23:57 +0100 | |
| changeset 937 | b3a237a5f4ad | 
| parent 916 | 2ab96407f350 | 
| child 940 | 1c1fbf45a03c | 
| permissions | -rw-r--r-- | 
| 59 | 1 | \documentclass{article}
 | 
| 292 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
changeset | 2 | \usepackage{../style}
 | 
| 876 | 3 | \usepackage{../langs}
 | 
| 292 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
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: 
60diff
changeset | 8 | \section*{Homework 8}
 | 
| 59 | 9 | |
| 916 | 10 | %%\HEADER | 
| 359 
db106e5b7c4d
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
292diff
changeset | 11 | |
| 59 | 12 | \begin{enumerate}
 | 
| 292 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
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: 
206diff
changeset | 14 | the factorial function. | 
| 77 
49c0beef79a1
added
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
76diff
changeset | 15 | |
| 292 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
changeset | 16 | \item What optimisations could a compiler perform when | 
| 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
changeset | 17 | compiling a WHILE-program? | 
| 206 
85b961f1eee9
added
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
102diff
changeset | 18 | |
| 292 
7ed2a25dd115
updated
 Christian Urban <christian dot urban at kcl dot ac dot uk> parents: 
206diff
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: 
206diff
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: 
102diff
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: |