Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although it can be dangerous to apply textual substitution to Lisp forms (since there are dangers of multiple evaluation, etc.), in this case it may help to look at this form and see how it fits together:</p> <pre><code>((lambda (len) (lambda (l) ...)) eternity) </code></pre> <p>is an application, i.e., a function call. The function getting called takes one argument, called <code>len</code>, and returns another function that takes a single argument <code>l</code>. The function getting called is called with <code>eternity</code>. When the call completes, the result is this function:</p> <pre><code>(lambda (l) (cond ((null? l) 0) (else (+ 1 (eternity (cdr l)))))) </code></pre> <p>Now, this function takes a list <code>l</code> and if it's empty, returns <code>0</code>. Otherwise, it computes <code>(cdr l)</code> (the rest of the list), and calls <code>eternity</code> with that value. When that returns, <code>1</code> is added to the result, and that's the return value of the whole function. The problem, of course, is that <code>eternity</code> </p> <pre><code>(define eternity (lambda (x) (eternity x))) </code></pre> <p>which could also be written as </p> <pre><code>(define (eternity x) (eternity x)) </code></pre> <p>simply takes an argument <code>x</code>, and then calls <code>eternity</code> with <code>x</code>. That's an infinite loop. In the above, I wrote "When that returns", but in fact, <code>(eternity (cdr l))</code> <em>never</em> returns. So, </p> <pre><code>((lambda (len) (lambda (l) (cond ((null? l) 0) (else (+ 1 (len (cdr l))))))) eternity) </code></pre> <p>is a function call that returns a function <code>(lambda (l) …)</code> that returns <code>0</code> if called with an empty list, and goes into an infinite loop with a non-empty list.</p> <p>From a program analysis side of things, it's worth noting that there <em>are</em> other values for which this won't go into an infinite loop. For instance, if you call it with a string, then <code>(cdr l)</code> will be an error.</p>
    singulars
    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.
    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