next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Macaulay2Doc > The Macaulay2 language > operators > #?

#? -- check existence of value in a list, hash table, database, or string



If x is a list, x#?i tells whether there is an ith element of x. The entries of the list are numbered starting with 0. If i is negative, then the entries are numbered ending with -1.

i1 : L = {a, b, c, b, a};
i2 : L#?2

o2 = true
i3 : L#?12

o3 = false

If x is a hash table or database, x#?i tells whether there is a value associated with the key i.

i4 : T = new HashTable from {a => 103, b => 89.4, c => 92};
i5 : T#?a

o5 = true
i6 : T#?A

o6 = false

If x is a string, x#?i tells if x has an ith character.

i7 : s = "a perfectly adequate example of a string";
i8 : s#?2

o8 = true
i9 : s#?52

o9 = false

#? can be very useful in avoiding errors from attempting to access nonexistent elements of lists or hash tables.

See also

Ways to use symbol #? :

For the programmer

The object #? is a keyword.