Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This behaviour hints at a missing tail call optimization, so that your recursion blows the stack. A possible reason is that you have declaimed debugging optimization.</p> <p>By the way, you don't need to make an explicit call to <code>return-from</code>. Since <code>sum</code> is a self-evaluating symbol, you can change this line</p> <pre><code>(return-from count-reduced-fractions sum)</code></pre> <p>to</p> <pre><code>sum</code></pre> <p><em>edit:</em> Explanation of the proposed change: "sum" evaluates to its own value, which becomes the return value of the "if" statement, which (since this is the last statement in the defun) becomes the return value of the function.</p> <p><em>edit:</em> Explanation of declaimed optimization: You could add the following to your top level:</p> <pre><code>(declaim (optimize (speed 3) (debug 0)))</code></pre> <p>or use the same, but with <code>declare</code> instead of <code>declaim</code> as the first statement in your function. You could also try (space 3) and (safety 0) if it doesn't work.</p> <p>Tail call optimization means that a function call whose return value is directly returned is translated into a frame replacement on the stack (instead of stacking up), effectively "flattening" a recursive function call to a loop, and eliminating the recursive function calls. This makes debugging a bit harder, because there are no function calls where you expect them, resp. you do not know how "deep" into a recursion an error occurs (just as if you had written a loop to begin with). Your environment might make some default declamations that you have to override to enable TCO.</p> <p><em>edit:</em> Just revisiting this question, what is <code>g</code>? I think that you actually want to</p> <pre><code>(let ((g (gcd n d))) ;; ... ) </code></pre>
 

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