Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A list in Scheme is either the empty list <code>()</code> (also known as <code>nil</code> in some Lisps), or a cons cell whose <code>car</code> (also known as <code>first</code>) is an element of the list and whose <code>cdr</code> (also known as <code>rest</code>) is either the rest of the list (i.e., another list), or an atom that terminates the list. The conventional terminator is the empty list <code>()</code>; lists terminated by <code>()</code> are said to be "proper lists". Lists terminated by any other atom are called "improper lists". The list <code>(1 2 3 4 5)</code> contains the elements 1, 2, 3, 4, and 5, and is terminated by <code>()</code>. You could construct it by </p> <pre><code>(cons 1 (cons 2 (cons 3 (cons 4 (cons 5 ()))))) </code></pre> <p>Now, when the system <em>prints</em> a cons cell, the general case is to print it by </p> <pre><code>(car . cdr) </code></pre> <p>For instance, the result of <code>(cons 1 2)</code> is printed as </p> <pre><code>(1 . 2) </code></pre> <p>Since lists are built of cons cells, you can use this notation for lists too:</p> <pre><code>'(1 2 3 4 5) == '(1 . (2 . (3 . (4 . (5 . ()))))) </code></pre> <p>That's rather clunky, though, so most lisps (all that I know of) have a special case for printing cons cells: if the <code>cdr</code> is a list (either another cons cell, or <code>()</code>), then don't print the <code>.</code>, and don't print the surrounding parenthesis of the <code>cdr</code> (which it would otherwise have, since it's a list). So, if you're seeing a result like </p> <pre><code>(1 2 3 . 4) </code></pre> <p>it means you've got an improper list that is terminated by the atom <code>4</code>. It has the structure</p> <pre><code>(1 . (2 . (3 . 4))) </code></pre> <p>Now the question is: where in your code did the list construction go awry? <code>..</code> is always supposed to return a proper list, so let's look at the cases: The first case always returns a proper list (the empty list):</p> <pre><code>((&gt; (add1 start) stop) (quote ())) </code></pre> <p>The second case looks like it can return something that's not a list (assuming that <code>(sub1 stop) == (- stop 1)</code>):</p> <pre><code>((eq? (add1 start) stop) (sub1 stop)) </code></pre> <p>Now, if <code>..</code> were functioning correctly, then the third case would always be returning a proper list (since <code>(cons x y)</code> is a proper list if <code>y</code> is):</p> <pre><code>(else (cons start (.. (add1 start) stop))) </code></pre> <p>Make your second case return a list and you should be all set.</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.
 

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