I noticed that there's a test case in the testsuite that seemingly explicitly tests that the order in the right operand takes precedence in |:
test_equal( ({1,2,3,4,4}) | ({3,5,6}), ({1,2,4,4,3,5,6}))
Even so I'd like to change it, partly for the reasons I've given elsewhere in this comment tree, partly for consistency with &, which just as the manual says takes the order from the left operand.
The test was changed to this by Hubbe on October 3rd 1999 with the comment "operator fixes (I hope)". Does anyone remember any preceding discussion about it?
/ Martin Stjernholm, Roxen IS
Previous text:
2002-12-03 22:51: Subject: `| and order on arrays
That's what the documentation states, anyway.
http://pike.ida.liu.se/generated/manual/ref/chapter_4.html#4:
When intersection, union or symmetric difference is used on an array each element in the array is considered by itself. So intersecting two arrays will result in an array with all elements that are present in both arrays. Example: ({7,6,4,3,2,1}) & ({1, 23, 5, 4, 7}) will return ({7,4,1}). The order of the elements in the returned array will always be taken from the left array.
...but it's been broken for ages. Those who want a workaround can use a + (b - a) instead of a | b but I'd rather see the bug fixed.
(While looking through the module reference for `| I also noticed that it incorrectly says that it performs _concatenation_ if the arguments are arrays.)
/ Jonas Walldén