Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > hash tables > remove
next | previous | forward | backward | up | index | toc

remove -- remove an entry from a mutable hash table, list, or database

Synopsis

Description

remove(T, k) removes the entry of T stored under the key k.

i1 : T = new MutableHashTable from {a => 1, b => 2, c => 3}; peek T

o2 = MutableHashTable{a => 1}
                      b => 2
                      c => 3
i3 : remove(T, a)
i4 : peek T

o4 = MutableHashTable{b => 2}
                      c => 3

If T is not a mutable hash table, an error is thrown. One way to remove an entry from an immutable hash table is with the function applyPairs:

i5 : T = new HashTable from {a => 1, b => 2, c => 3}

o5 = HashTable{a => 1}
               b => 2
               c => 3

o5 : HashTable
i6 : T = applyPairs(T, (k, v) -> if k =!= a then (k, v))

o6 = HashTable{b => 2}
               c => 3

o6 : HashTable

remove works similarly when T is a database. See Database for more information.

If T is a mutable list, then k gives the index of the element to be removed.

i7 : T = new MutableList from {1, 2, 3, 4}; peek T

o8 = MutableList{1, 2, 3, 4}
i9 : remove(T, 0)
i10 : peek T

o10 = MutableList{2, 3, 4}

If k is negative, then the index is determined by counting backwards from the end of T.

i11 : remove(T, -1)
i12 : peek T

o12 = MutableList{2, 3}

The remove command does not return any output.

See also

Ways to use remove :

For the programmer

The object remove is a compiled function.