6 ms·
we already have `set1 | set2` for set unions and dict keys are basically a set
by anentropic 7y ago
we already have `set1 | set2` for set unions
and dict keys are basically a set
- fulafel 7y agoI think that's cryptic too for most people, intuitive just for people who are conversant in bitwise operations.
- anentropic 7y agothese are standard set operations, not bitwise
- fulafel 7y agoThe choice of the "|" operator for set union comes from bitwise operations: bitwise OR works as a union operator if you are using integers as bit vectors to represent sets of boolean attributes. And it was a common idiom back in the day when people used to program in C/assembly, using words as bit vectors was a common way to save memory. Hence "|" as set union is intuitive for people who are familiar with this application of bit vectors.
- heavenlyblue 7y agoI think the OR operator comes from set theory and has nothing to do with the low-level boolean flag fieldsets.
- fulafel 7y agoI looked up set theory a couple of places (WP[1] and Britannica[2]) and didn't find any references of the OR operator in this context.. do you have a link? [1] https://en.wikipedia.org/wiki/Algebra_of_sets https://en.wikipedia.org/wiki/Algebra_of_sets [2] https://www.britannica.com/science/set-theory/Operations-on-sets https://www.britannica.com/science/set-theory/Operations-on-...
- housecarpenter 7y agoThe analogue of the OR operator in set theory is the union operator. People think of them as basically the same thing because of the correspondence between a property and the set of things with that property. If A is the property of being either B or C, then the set of the things that are A is the union of the set of things that are B and the set of things that are C.