-
Notifications
You must be signed in to change notification settings - Fork 11
Description
MATLAB will happily let you add a scalar to a vector, or even a scalar to a matrix. If a is a matrix or vector and b is a scalar value, then a + b will return a copy of a with b added to every element, and likewise b + a, instead of doing the sensible thing and raising a type error.
Of course, we can generalize this a bit for BS. If a is an array, b is a non-array type, and op is an operator -- literally any operator in the whole language -- such that a op b would otherwise be invalid, then instead a op b returns an array with the same length of a such that for each element a_i in the original array a, the returned array has a_i op b in the same position. Likewise for b op a returning an array of b op a_i for each a_i in a.
This also implies that if a is an array of arrays, b is recursively applied to every array in a to produce the output array.