[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: inconsitency in behavior of 'size'
From: |
Mike Miller |
Subject: |
Re: inconsitency in behavior of 'size' |
Date: |
Fri, 9 Mar 2018 11:27:47 -0800 |
User-agent: |
Mutt/1.9.3 (2018-01-21) |
On Fri, Mar 09, 2018 at 18:37:02 +0000, Sergei Steshenko wrote:
> Pay attention that in both cases essentially size of [_1,_2]
> expression is calculated, but in the first case the expression is also
> first assigned its value from call to 'sort' while in the second case
> it's just the expression.
I think it might help first to agree that '[x,y]' is syntax that
declares an array, but '[x,y] = something' is a different assignment
syntax that assigns two return values to x and y independently.
If you have a background in C you might assume that the *value* of the
overall assignment expression is the same as the value '[x,y]'. But it's
very important to note that '[x,y]' in assigment syntax is not actually
instantiating an array composed from x and y.
Now, compare the values of the following
([_1,_2] = sort(im(:, 3), "descend"))
([_1,_2] = sort(im(:, 3), "descend"))(:)
[[_1,_2] = sort(im(:, 3), "descend")]
{[_1,_2] = sort(im(:, 3), "descend")}
I don't have any documentation or code to point at, but I would venture
to say that when an assignment to multiple return values is used in
another expression, the value of the expression is that of the first
return value only.
> How does Matlab behave in the same case ?
Matlab does not allow assignments to be used as expressions.
--
mike
signature.asc
Description: PGP signature
- inconsitency in behavior of 'size', Sergei Steshenko, 2018/03/09
- Re: inconsitency in behavior of 'size', Nicholas Jankowski, 2018/03/09
- Re: inconsitency in behavior of 'size',
Mike Miller <=
- Re: inconsitency in behavior of 'size', Sergei Steshenko, 2018/03/09
- Re: inconsitency in behavior of 'size', Mike Miller, 2018/03/10
- Re: inconsitency in behavior of 'size', Sergei Steshenko, 2018/03/10
- Re: inconsitency in behavior of 'size', Mike Miller, 2018/03/10
- Re: inconsitency in behavior of 'size', Sergei Steshenko, 2018/03/10
- Re: inconsitency in behavior of 'size', Przemek Klosowski, 2018/03/12
- Re: inconsitency in behavior of 'size', Nicholas Jankowski, 2018/03/12