<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=24.187.72.209</id>
		<title>explain xkcd - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://www.explainxkcd.com/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=24.187.72.209"/>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php/Special:Contributions/24.187.72.209"/>
		<updated>2026-04-15T03:14:10Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=1270:_Functional&amp;diff=49623</id>
		<title>1270: Functional</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=1270:_Functional&amp;diff=49623"/>
				<updated>2013-09-27T11:39:47Z</updated>
		
		<summary type="html">&lt;p&gt;24.187.72.209: /* Explanation */ Reward is a pun of reword.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{comic&lt;br /&gt;
| number    = 1270&lt;br /&gt;
| date      = September 26, 2013&lt;br /&gt;
| title     = Functional&lt;br /&gt;
| image     = functional.png&lt;br /&gt;
| titletext = Functional programming combines the flexibility and power of abstract mathematics with the intuitive clarity of abstract mathematics.&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Explanation==&lt;br /&gt;
{{incomplete|if that's the recursion pun I think it is, Randall needs a caning.}}&lt;br /&gt;
&lt;br /&gt;
'''TL;DR:''' After [[White Hat]] questions his faith in {{w|functional programming}}, [[Cueball]] says that &amp;quot;tail recursion is its own reward.&amp;quot; This is a pun of the phrase &amp;quot;Tail recursion is its own reword&amp;quot;.  To reword a statement is to express it using different words.  Tail recursion refers to when a function finishes by going back and calling itself with different arguments, forming a loop. The structure of this technique allows a compiler to compiled into a more efficient form (&amp;quot;reworded&amp;quot;). If you aren't groaning by now, read on.&lt;br /&gt;
&lt;br /&gt;
Recursion refers to functions that invoke themselves at some point to perform a smaller part of their computation - except where the task at hand is simple enough not to require it.&lt;br /&gt;
&lt;br /&gt;
For example, the {{w|factorial}} function has a recursive definition:&lt;br /&gt;
&lt;br /&gt;
 factorial(n) = 1                       if n = 0&lt;br /&gt;
 factorial(n) = n * factorial(n - 1)    if n &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
which can be coded as:&lt;br /&gt;
&lt;br /&gt;
 factorial(n):&lt;br /&gt;
     if n == 0:&lt;br /&gt;
         return 1&lt;br /&gt;
     else:&lt;br /&gt;
         return n * factorial(n - 1)&lt;br /&gt;
&lt;br /&gt;
{{w|Tail recursion}} refers to a recursive function whose final operation is to invoke the function itself - crucially with no subsequent computation involved. This means that instead of pushing each level of recursion onto the stack, the compiler can simply arrange for the recursive call to jump to the start of the function with the new parameters - effectively turning a recursive call into an iterative loop, whilst retaining the simplicity of a recursive call.&lt;br /&gt;
&lt;br /&gt;
The efficiency and elegance are the literal rewards of tail recursion.&lt;br /&gt;
&lt;br /&gt;
The {{w|greatest common divisor}} function can be coded as:&lt;br /&gt;
&lt;br /&gt;
 gcd(a, b):&lt;br /&gt;
     if b == 0:&lt;br /&gt;
         return a&lt;br /&gt;
     else:&lt;br /&gt;
         return gcd(b, a % b)&lt;br /&gt;
&lt;br /&gt;
Here, the recursive call to gcd is tail recursive since its the last step of the function.&lt;br /&gt;
&lt;br /&gt;
The first example is not tail recursive because the multiplication cannot be evaluated until after its right operand has been calculated. This next example performs its multiplication before the final step - the recursion - and is, thereby, tail recursive.&lt;br /&gt;
&lt;br /&gt;
 factorial2(n, acc):&lt;br /&gt;
     if n == 0:&lt;br /&gt;
         return acc&lt;br /&gt;
     else:&lt;br /&gt;
         return factorial2(n - 1, n * acc)&lt;br /&gt;
 &lt;br /&gt;
 factorial(n):&lt;br /&gt;
     return factorial2(n, 1)&lt;br /&gt;
&lt;br /&gt;
The technique used here is to use a helper function with an additional argument called an accumulator which will accumulate results from previous calls to the function. It is often used to implement tail recursive or iterative versions of recursive functions. This is not applicable for all recursive functions, though.&lt;br /&gt;
&lt;br /&gt;
Cueball is making the pun that &amp;quot;(functional programming) is an end unto itself&amp;quot;, which would be both figuratively and literally correct.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The title text describes that to {{w|Abstract mathematics|abstract mathematicians}} functional programming is both powerful and flexible, as well as intuitive and clear since it comes very close to the way mathematicians usually describe functions. On the other hand to non-mathematicians, functional programming can be exactly the opposite (thus being non-intuitive and unclear as abstract mathematics appears to them).&lt;br /&gt;
&lt;br /&gt;
The title text is also a reference to a common saying about C (An {{w|Imperative programming|imperative programming}} language): &amp;quot;C combines the flexibility and power of assembly language with the user-friendliness of assembly language&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==Transcript==&lt;br /&gt;
:[White Hat stands behind Cueball, who is sitting at a computer]&lt;br /&gt;
:White Hat: Why do you like functional programming so much? What does it actually ''get'' you?&lt;br /&gt;
:Cueball: Tail recursion is its own reward.&lt;br /&gt;
&lt;br /&gt;
{{comic discussion}}&lt;br /&gt;
[[Category:Comics featuring White Hat]]&lt;br /&gt;
[[Category:Comics featuring Cueball]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Recursion]]&lt;/div&gt;</summary>
		<author><name>24.187.72.209</name></author>	</entry>

	<entry>
		<id>https://www.explainxkcd.com/wiki/index.php?title=Talk:1270:_Functional&amp;diff=49622</id>
		<title>Talk:1270: Functional</title>
		<link rel="alternate" type="text/html" href="https://www.explainxkcd.com/wiki/index.php?title=Talk:1270:_Functional&amp;diff=49622"/>
				<updated>2013-09-27T11:31:08Z</updated>
		
		<summary type="html">&lt;p&gt;24.187.72.209: Reward is a pun  of Reword&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;I'm getting the adblock message at the top.. on mobile. On an unrelated note, I laughed and I don't even get it. Edit: I'm also seeing an ad while seeing the message.[[Special:Contributions/50.159.5.112|50.159.5.112]] 06:03, 27 September 2013 (UTC)&lt;br /&gt;
:This shouldn't be in comic discussion. I have written an updated version of our ad plugin that should only display a message to people using adblock, but we're using a sitenotice for now to test the waters. We'll take it down in about a day, promise!&lt;br /&gt;
:Also, would you be complicit if I were to move this to the relevant forum? '''[[User:Davidy22|&amp;lt;u&amp;gt;{{Color|#707|David}}&amp;lt;font color=#070 size=3&amp;gt;y&amp;lt;/font&amp;gt;&amp;lt;/u&amp;gt;&amp;lt;font color=#508 size=4&amp;gt;²²&amp;lt;/font&amp;gt;]]'''[[User talk:Davidy22|&amp;lt;tt&amp;gt;[talk]&amp;lt;/tt&amp;gt;]] 06:13, 27 September 2013 (UTC)&lt;br /&gt;
I removed that misguided explanation about lists that was not tail recursive. I'm also wondering if we should also mention that tail call optimization is also applicable to mutually recursive functions. In fact proper functional languages will always apply it whether the functions are recursive or not. Maybe emphasize the fact that &amp;quot;The efficiency and elegance are the literal rewards of tail recursion.&amp;quot;?&lt;br /&gt;
&lt;br /&gt;
I feel like the examples should be in Haskall, because that is the major functional language... [[Special:Contributions/67.160.98.42|67.160.98.42]] 09:48, 27 September 2013 (UTC) GBGamer117&lt;br /&gt;
:I think Hask'''e'''ll is more common, but I agree. And to emphasize the clarity, usually if/else blocks are avoided using pattern matching. I.e. tail-recursive factorial can be written as follows:&lt;br /&gt;
  fac2::Integer-&amp;gt;Integer-&amp;gt; Integer  -- optional function header&lt;br /&gt;
  fac2 acc 0 = acc&lt;br /&gt;
  fac2 acc n = fac2 (acc*n) (n-1)&lt;br /&gt;
  &lt;br /&gt;
  fac::Integer-&amp;gt; Integer&lt;br /&gt;
  fac = fac2 1&lt;br /&gt;
:--[[User:Chtz|Chtz]] ([[User talk:Chtz|talk]]) 10:34, 27 September 2013 (UTC)&lt;br /&gt;
::Addendum: I did not dare to edit that yet, as I am unsure if this actually helps anyone not familiar with functional programming (and I don't think this page should include a Haskell crash course just to explain this comic). --[[User:Chtz|Chtz]] ([[User talk:Chtz|talk]]) 10:43, 27 September 2013 (UTC)&lt;br /&gt;
&lt;br /&gt;
I thought about the text a little and don't the the interpretation &amp;quot;tail recursion is an end unto itself&amp;quot; is correct.  I think what's going on is a pun of the word &amp;quot;reward&amp;quot;.  &amp;quot;Tail recursion is it's own reword&amp;quot; makes more sense since you are calling the same function but are &amp;quot;rewording&amp;quot; the arguements.  To reword means to re-express something with different words.  --[[Special:Contributions/24.187.72.209|24.187.72.209]] 11:31, 27 September 2013 (UTC)&lt;/div&gt;</summary>
		<author><name>24.187.72.209</name></author>	</entry>

	</feed>