Strings do some similar things. 1-character strings and strings that appear in source code are interned.
RichardB@kallisti ~$ cat argvpairs.py
import sys
for (ai, a) in enumerate(sys.argv[1:]):
for (bi, b) in enumerate(sys.argv[2 + ai:]):
print (1 + ai, a, 2 + bi, b, a is b)
RichardB@kallisti ~$ python argvpairs.py ha ha a a
(1, 'ha', 2, 'ha', False)
(1, 'ha', 3, 'a', False)
(1, 'ha', 4, 'a', False)
(2, 'ha', 2, 'a', False)
(2, 'ha', 3, 'a', False)
(3, 'a', 2, 'a', True)
I wonder how many versions of this article with pretty much the same examples and code exist by now…
Strings do some similar things. 1-character strings and strings that appear in source code are interned.
Sometimes I don’t know how the world turns with referential opacity.
This is pretty standard in most of the OO languages I’ve encountered. Also mentioned in good books about python.