fork download
  1. ;#!/usr/bin/racket
  2. ;#lang scheme
  3.  
  4.  
  5.  
  6. (define (same-parity a . xs)
  7. (define parity (remainder a 2))
  8. (define (iter items result)
  9. (if (null? items)
  10. result
  11. (iter (cdr items)
  12. (if (= (remainder (car items) 2) parity)
  13. (cons result (car items))
  14. result))))
  15. (iter xs (list a)))
  16.  
  17. ; Testing
  18. (define x (list 1 2 3 4 5 6 7 8 9 10))
  19.  
  20. (display (same-parity 1 x))
  21. (display)
  22.  
Runtime error #stdin #stdout #stderr 0.07s 10248KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Backtrace:
In ice-9/boot-9.scm:
 157: 13 [catch #t #<catch-closure 9acfbd0> ...]
In unknown file:
   ?: 12 [apply-smob/1 #<catch-closure 9acfbd0>]
In ice-9/boot-9.scm:
  63: 11 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
 432: 10 [eval # #]
In ice-9/boot-9.scm:
2401: 9 [save-module-excursion #<procedure 9adecc0 at ice-9/boot-9.scm:4045:3 ()>]
4052: 8 [#<procedure 9adecc0 at ice-9/boot-9.scm:4045:3 ()>]
1724: 7 [%start-stack load-stack ...]
1729: 6 [#<procedure 9ae4738 ()>]
In unknown file:
   ?: 5 [primitive-load "/home/XwkReZ/prog.scm"]
In ice-9/eval.scm:
 387: 4 [eval # ()]
 387: 3 [eval # #]
 399: 2 [eval # #]
 387: 1 [eval # #]
In unknown file:
   ?: 0 [remainder (1 2 3 4 5 6 7 8 9 ...) 2]

ERROR: In procedure remainder:
ERROR: In procedure remainder: Wrong type argument in position 1: (1 2 3 4 5 6 7 8 9 10)