If x is a list, x#i returns the 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. If i is out of range, an error is signaled.
i1 : L = {a, b, c, b, a}; |
i2 : L#2 o2 = c o2 : Symbol |
i3 : L#-2 o3 = b o3 : Symbol |
If x is a hash table or database, x#i provides the value associated with the key i.
i4 : T = new HashTable from {a => 103, b => 89.4, c => 92}; |
i5 : T#a o5 = 103 |
i6 : T#b o6 = 89.4 o6 : RR (of precision 53) |
If x is a string, x#i provides the ith character of x, if there is one. Negative indices are counted backward from the end, as with lists. If i is out of range, an error is thrown.
i7 : s = "a perfectly adequate example of a string"; |
i8 : s#2 o8 = p |
i9 : s#-2 o9 = n |
Assignment to x#i can change x if x is mutable.
i10 : V = new MutableHashTable from T; |
i11 : V#a = 5; |
i12 : V#d = 22.3; |
i13 : peek V o13 = MutableHashTable{a => 5 } b => 89.4 c => 92 d => 22.3 |