fork download
  1. ; two swaps
  2.  
  3. (define (two-swaps a b c)
  4. (define-syntax swap!
  5. (syntax-rules ()
  6. ((swap! x y)
  7. (let ((z x))
  8. (set! x y)
  9. (set! y z)))))
  10. (if (< a b)
  11. (if (< a c)
  12. (swap! a a)
  13. (swap! a c))
  14. (if (< b c)
  15. (swap! a b)
  16. (swap! a c)))
  17. (if (< b c)
  18. (swap! b b)
  19. (swap! b c))
  20. (list a b c))
  21.  
  22. (display (two-swaps 1 2 3)) (newline)
  23. (display (two-swaps 1 3 2)) (newline)
  24. (display (two-swaps 2 1 3)) (newline)
  25. (display (two-swaps 2 3 1)) (newline)
  26. (display (two-swaps 3 1 2)) (newline)
  27. (display (two-swaps 3 2 1)) (newline)
Success #stdin #stdout 0s 7268KB
stdin
Standard input is empty
stdout
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)