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

proc distinct {l} {
    if {{} in $l} {
        error "no {} allowed"
    }
    lmap {e1 e2} $l {
        if {$e1 eq $e2} {
            set e1
        } else {
            if {$e2 ne {}} {
                $e1 $e2
            } else {
                set e1
            }
        }
    }
}

# DOING:
distinct {a b c c}

# GIVES:
# {{a b}} c