Posted to tcl by jima at Wed Jan 29 14:17:34 GMT 2014view raw

  1. proc distinct {l} {
  2. if {{} in $l} {
  3. error "no {} allowed"
  4. }
  5. lmap {e1 e2} $l {
  6. if {$e1 eq $e2} {
  7. set e1
  8. } else {
  9. if {$e2 ne {}} {
  10. $e1 $e2
  11. } else {
  12. set e1
  13. }
  14. }
  15. }
  16. }
  17.  
  18. # DOING:
  19. distinct {a b c c}
  20.  
  21. # GIVES:
  22. # {{a b}} c
  23.  
  24.