Version 0 of ldiff

Updated 2013-12-31 16:33:24 by PeterLewerin

Find the difference of two lists, i.e. the list of elements that occur in list a but not in list b (and not the intersection, i.e. the list of elements that occur in only one of the two lists).

proc ldiff {a b} {
    lmap elem $a {
        expr {[lsearch -exact $b $elem] > -1 ? [continue] : $elem}
    }
}

ldiff {2 3 4 5 6 7 8 9 10} {2 3 5 7}
# -> 4 6 8 9 10
ldiff {1 2 3} {2 3 4}
# -> 1

This command probably isn't very efficient.