On 03/10/2018 07:21 PM, Sergei
Steshenko wrote:
"The
syntax for slicing values out of a comma-separated list looks a
lot like matrix concatenation" - which is obfuscation.
I.e.
[foo, bar] should always mean the same. The situation is really
bad - see copy-paste of a session:
octave:9>
[a1, a2] = sort([1 2 3; 4 5 6](:,1))
a1 =
1
4
a2 =
1
2
octave:10> foo = [a1, a2] = sort([1 2 3; 4 5 6](:,1))
foo =
1
4
Output of
command 9 shows TWO columns, while output of command 10 shows
ONE column, and the difference is that in command 10 output of
command 9 is assigned to a variable.
Given the compatibility requirement that [] on the left of '=' is
not the same as [] on the right size, it does make sense.
[a1,a2] = ... assigns two variables.
foo = [a1,a2] = ... is equivalent to
<return object> = ...
[a1,a2] = <return object>
foo = <return object>
In both of those cases, a1=[1;4], a2=[1;2], foo = [1;4]
foo = [a1, a2]
is different: foo = [1,1;4,2], because in this case [] is matrix
concatenation. It's not really bad---it's just the way it is given
Matlab design from back in the 1970s.