fork(1) download
  1. ; sets without replacement
  2.  
  3. (define s (list)) ; set of current items
  4. (define t (list)) ; tombstones of deleted items
  5.  
  6. (define (add s x) ; add x to set s
  7. (if (member x s)
  8. (error 'add "can't add already existent element")
  9. (if (member x t)
  10. (error 'add "can't add previously existent element")
  11. (begin (set! s (cons x s)) s))))
  12.  
  13. (define (del s x) ; remove x from set s
  14. (if (not (member x s))
  15. (error 'del "can't delete non-existent element")
  16. (begin (set! s (remove x s))
  17. (set! t (cons x t))
  18. s)))
  19.  
  20. (set! s (add s 1))
  21. (set! s (add s 3))
  22. (set! s (add s 5))
  23.  
  24. (set! s (add s 3))
  25. (set! s (del s 3))
  26. (set! s (add s 3))
Runtime error #stdin #stdout #stderr 0.01s 7636KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: (add) can't add already existent element

	Call history:

	<eval>	  [add] (member x s)
	<eval>	  [add] (member x t)
	<eval>	  [add] (cons x s)
	<syntax>	  (set! s (add s 5))
	<syntax>	  (##core#set! s (add s 5))
	<syntax>	  (add s 5)
	<eval>	  (add s 5)
	<eval>	  [add] (member x s)
	<eval>	  [add] (member x t)
	<eval>	  [add] (cons x s)
	<syntax>	  (set! s (add s 3))
	<syntax>	  (##core#set! s (add s 3))
	<syntax>	  (add s 3)
	<eval>	  (add s 3)
	<eval>	  [add] (member x s)
	<eval>	  [add] (error (quote add) "can't add already existent element")	<--