Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>This is how isOdd returns true on an even number:</h2> <p>When you pass 2 to isOdd, it will forward this to isEven. Your call stack now looks like this (newest function is up):</p> <pre><code>isEven(2) isOdd(2) main </code></pre> <p>isEven will now call isOdd with 1:</p> <pre><code>isOdd(1) isEven(2) isOdd(2) main </code></pre> <p>isOdd will again forward this to isEven:</p> <pre><code>isEven(1) isOdd(1) isEven(2) isOdd(2) main </code></pre> <p>the whole happens again with 0</p> <pre><code>isEven(0) isOdd(0) isEven(1) isOdd(1) isEven(2) isOdd(2) main </code></pre> <p>isEven now terminates with true, and the whole call-stack is rewinded. True is returned to isOdd:</p> <pre><code>isOdd(0) &lt;-true isEven(1) isOdd(1) isEven(2) isOdd(2) main </code></pre> <p>isOdd will negate the return value, and thus return false to isEven:</p> <pre><code>isEven(1) &lt;- false isOdd(1) isEven(2) isOdd(2) main </code></pre> <p>isEven again returns the result as-is to isOdd</p> <pre><code>isOdd(1) &lt;- false isEven(2) isOdd(2) main </code></pre> <p>isOdd negates and returns:</p> <pre><code>isEven(2) &lt;- true isOdd(2) main </code></pre> <p>isEven returns as-is:</p> <pre><code>isOdd(2) &lt;- true main </code></pre> <p>isOdd negates and returns to main:</p> <pre><code>main &lt;- false </code></pre> <h2>this is how isOdd returns false on an uneven number:</h2> <p>When isEven terminates, the call-stack looks like that.</p> <pre><code>isEven(0) isOdd(0) isEven(1) isOdd(1) main </code></pre> <p>isOdd receives true:</p> <pre><code>isOdd(0) &lt;-true isEven(1) isOdd(1) main </code></pre> <p>isOdd negates:</p> <pre><code>isEven(1) &lt;- false isOdd(1) main </code></pre> <p>isEven returns the unchanged value:</p> <pre><code>isOdd(1) &lt;- false main </code></pre> <p>isOdd negates and returns to main:</p> <pre><code>main &lt;- true </code></pre> <h2>So whats the explanation?</h2> <p>The whole trick is that when you have an odd number, there is an even number of negations in the call-stack. When you negate a boolean value an even number of times, it comes out as it was before. When you have an even number, you have an odd number of negations, and the result is changed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload