<commit_before>---
num: "h04"
desc: "Guttag, Chapter 4"
ready: false
assigned: 2016-08-03 09:00:00.00-7:00
due: 2016-08-04 09:00:00.00-7:00
---


Please read Chapter 4 in the Guttag textbook, then answer these questions.

<ol>

<li markdown="1" style="margin-bottom:8em;">

(10 pts) On page 34, Guttag contends that you can solve any problem that is computationally solvable using the programming constructs from Chapters 1-3. List four main reasons for using *functions* in your program. Write your answer based on your entire reading of Chapter 4, rather than the arguments provided by Guttag on page 34 alone.

</li>



<li markdown="1" style="margin-bottom:8em;">

(10 pts) What is a function specification and why is it used in programming?

</li>


<li markdown="1" style="margin-bottom:10em;" >

(10 pts) Explain via an example the basic ingredients of a recursive function implementation. Try to use an example that is different from those used in your reading.
</li>


<li markdown="1" style="margin-bottom:8em;" >

(10 pts) In the implementation of the program given in Figure 4.8 of Guttag, what is the purpose of the helper function <code> isPal() </code>? 

</li>


<li markdown="1" style="list-style-type: none" class = "page-break-before" >
In the following questions we will practice tracing code to understand how functions. Code tracing is the process of reading a piece of code line by line and visualizing what would happen if it were to actually run on your computer. This is not only a way to test your understanding of programming concepts but also an essential tool for debugging your programs. Trace the code given below and answer the questions that follow.

<pre>
<code> 
    def swap(x, y):
      tmp = x
      x = y
      y = tmp
      print x, y

    a = 3
    b = 4
    print a, b
    swap(a,b)
    print a, b
</code>
</pre>
</li>



<li markdown="2" style="margin-bottom:2em;">
 (2 pts) Identify the formal and actual parameters in the above code
</li>

<li markdown="2" style="margin-bottom:16em;">
(6 pts) Using diagrams similar to those in Figure 4.4 on page 39 of Guttag, show the state of the runtime stack and the values of the variables <code> a,b,x,y </code> when the program execution is at the print statement specified 

a) prior to the call to the swap function
b) in the body of the swap function 
c) following the call to the swap function

</li>


<li markdown="2" style="margin-bottom:8em;">
(2 pt) What are the values printed to console when the above code is executed? 
</li>



</ol>
<commit_msg>Update h04.md<commit_after>---
num: "h04"
desc: "Guttag, Chapter 4"
ready: false
assigned: 2016-08-03 09:00:00.00-7:00
due: 2016-08-04 09:00:00.00-7:00
---


Please read Chapter 4 in the Guttag textbook, then answer these questions.

<ol>

<li markdown="1" style="margin-bottom:8em;">

(20 pts) On page 34, Guttag contends that you can solve any problem that is computationally solvable using the programming constructs from Chapters 1-3. List four main reasons for using *functions* in your program. Write your answer based on your entire reading of Chapter 4, rather than the arguments provided by Guttag on page 34 alone.

</li>



<li markdown="1" style="margin-bottom:8em;">

(20 pts) What is a function specification and why is it used in programming?

</li>


<li markdown="1" style="margin-bottom:10em;" >

(20 pts) Explain via an example the basic ingredients of a recursive function implementation. Try to use an example that is different from those used in your reading.
</li>


<li markdown="1" style="margin-bottom:8em;" >

(20 pts) In the implementation of the program given in Figure 4.8 of Guttag, what is the purpose of the helper function <code> isPal() </code>? 

</li>


<li markdown="1" style="list-style-type: none" class = "page-break-before" >
In the following questions we will practice tracing code to understand how functions. Code tracing is the process of reading a piece of code line by line and visualizing what would happen if it were to actually run on your computer. This is not only a way to test your understanding of programming concepts but also an essential tool for debugging your programs. Trace the code given below and answer the questions that follow.

<pre>
<code> 
    def swap(x, y):
      tmp = x
      x = y
      y = tmp
      print x, y

    a = 3
    b = 4
    print a, b
    swap(a,b)
    print a, b
</code>
</pre>
</li>



<li markdown="1" style="margin-bottom:2em;">
 (4 pts) Identify the formal and actual parameters in the above code
</li>

<li markdown="1" style="margin-bottom:16em;">
(12 pts) Using diagrams similar to those in Figure 4.4 on page 39 of Guttag, show the state of the runtime stack and the values of the variables `a`,`b`,`x` and `y` when the program execution is at the print statement specified 

<ol>
<li>prior to the call to the swap function</li>
<li>in the body of the swap function </li>
<li>following the call to the swap function</li>
</ol>

</li>


<li markdown="1" style="margin-bottom:8em;">
(4 pt) What are the values printed to console when the above code is executed? 
</li>



</ol>

{'fraction_non_alphanumeric': 0.09568443663347002, 'fraction_numerical': 0.03378246436242921, 'mean_word_length': 3.8184383819379115, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3334065', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1521, 'n_words': 763}