Why does Join not throw an error message when attempting to concatenate a List with an Integer, using infix notation?
Suppose I have my10List, a list of the ten integers from 1 to 10. Suppose I wish to rearrange the list so that the element 8 appears at the end; in other words, I wish to obtain the list {1, 2, 3, 4, 5, 6, 7, 9, 10, 8}.
Of course, there are numerous ways to accomplish this. One way is to use Join to join three sublists obtained using Part ([[]]) and Span (;;). One can do this using Join with the standard function notation or with infix notation:
Note that the braces ({}) around my10List[[8]] -- that is, {my10List[[8]]} -- are necessary because Join "concatenates lists or other expressions that share the same head," to quote the documentation. Obviously, my10List[[8]] does NOT have head List (i.e., executing Head[my10List[[8]]] gives Integer), but {my10List[[8]]} does (i.e., executing Head[{my10List[[8]]}] gives List).
Once, however, I mistakenly forgot to put the braces around my10List[[8]]. The result for Method 1 in this case is unsurprising -- Join throws an error and then prints the call in unevaluated form:
The result for Method 2, on the other hand, is surprising to me:
Surprisingly, no error is thrown and the list simply returned without the element 8. Why is this the case?
I also tried this on version 14, and the result is the same:
Look at the full form of your infix notation version:
So you essentially have Join[_List, 3], which fits the second usage of Join:
In the non-infix version you have Join[_List, _List, n_Integer], and if the input lists don't have n levels you get a message. But when joining just one list, as in Join[_List, n_Integer] it short circuits and doesn't even check if the list has n levels.