fork(1) download
  1. ; a simple interview question
  2.  
  3. (define (add1 x) (+ x 1))
  4. (define (sub1 x) (- x 1))
  5.  
  6. (define (sum x y)
  7. (while (< x 0) (set! x (add1 x)) (set! y (sub1 y)))
  8. (while (< 0 x) (set! x (sub1 x)) (set! y (add1 y)))
  9. y)
  10.  
  11. (display (sum 3 5)) (newline)
  12. (display (sum 3 -5)) (newline)
  13. (display (sum -3 5)) (newline)
  14. (display (sum -3 -5)) (newline)
Success #stdin #stdout 0.04s 8440KB
stdin
Standard input is empty
stdout
8
-2
2
-8