fork download
  1. ;#!/usr/bin/racket
  2. ;#lang scheme
  3.  
  4. ; List reversing
  5. (define (reverse ls)
  6. (define (iter xs result)
  7. (if (null? xs)
  8. result
  9. (iter (cdr xs) (cons (car xs) result))))
  10. (iter ls '()))
  11.  
  12. (define (same-parity a . xs)
  13. (let ((parity (if (odd? a) odd? even?)))
  14. (define (iter items result)
  15. (if (null? items)
  16. (reverse result)
  17. (iter (cdr items)
  18. (if (parity (car items))
  19. (cons (car items) result)
  20. result))))
  21. (iter xs (list a))))
  22.  
  23.  
  24. ; Testing
  25. (display (same-parity 1 2 3 4 5 6 7 8 9 10))
  26. (newline)
  27.  
Success #stdin #stdout 0.03s 8656KB
stdin
Standard input is empty
stdout
(1 3 5 7 9)