fork download
  1. ; nth item in a linked list
  2.  
  3. (define (nth n xs)
  4. (if (null? xs)
  5. (error 'nth "out of range")
  6. (if (zero? n) (car xs)
  7. (nth (- n 1) (cdr xs)))))
  8.  
  9. (display (nth 0 '(0 1 2 3 4))) (newline)
  10. (display (nth 1 '(0 1 2 3 4))) (newline)
  11. (display (nth 2 '(0 1 2 3 4))) (newline)
  12. (display (nth 3 '(0 1 2 3 4))) (newline)
  13. (display (nth 4 '(0 1 2 3 4))) (newline)
Success #stdin #stdout 0.01s 7912KB
stdin
Standard input is empty
stdout
0
1
2
3
4