[racket] dotted-tail notation

From: sam (throwit1 at hotmail.com)
Date: Tue Nov 20 12:45:09 EST 2012

I already spent a couple of hours on this, hope I am not missing something really obvious - does the dotted notation produce some kind of flat list instead of cons cells? 



(define list-rf (lambda ( n . items )
  (if (= n 0)
      (car items)
      (list-rf (- n 1)(cdr items)))))

(list-rf 3 1 4 9 16 25 1 4 9 16 25 1 4 9 16 25 1 4 9 16 25)

output: '()

If I try to end the recursion on (null? items) it goes into an infinite loop


(define test2 (lambda  y
                (if (or(null? y)(null? (cdr y)))
                  y
                  (printf"~a~n"(cons (car y) (test2 (cdr y)))))))



(test2 1 2 3 4 5 6 7);&rArr;     <i>(1 3 5 7)</i>
(trace test2)

output:
{2 {3 4 5 6 7}}
{1 {2 3 4 5 6 7}}

and test2 doesn't recur.  If I replace that (if (or (null ...
with 
         (if (null? y)

the prompt never returns.

it's confusing the heck out of me. 

Posted on the users mailing list.