[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matlab-style empty output/input arguments support
From: |
Judd Storrs |
Subject: |
Re: Matlab-style empty output/input arguments support |
Date: |
Fri, 29 Jan 2010 12:34:23 -0500 |
On Fri, Jan 29, 2010 at 7:06 AM, Dupuis <address@hidden> wrote:
> To me, the problem boils down to the lifetime of the function output
> argument. In something like
> [a, ~, b] = [c, d, ~] = somefunc(),
> the steps are
> 1) the function returns three arguments
> 2) evaluating right to left, the first assignement results in the first
> output argument copied to c, the second to d, and the third is not used
> 3) now, from what does [a, ~, b] receive a value ?
> - if we consider that we are reusing the function three output arguments,
> which should still be on scope, and disregard what was assigned previously,
> the operation makes sense : b receive the value of the third output argument
> - if we consider that, after the first assignment, the output arguments
> are out of scope and the value taken from the [c, d, ~] construct, then what
> should 'b' receive is ill-defined : is it an error, or should it receive an
> empty value ?
>
> The real question is thus what should the assignement operator return ? A
> pointer to the destination object, of a pointer to the source object ?
Perhaps ~ could be thought of as a global variable that discards all
assigned values and that always evaluates as []? Then we don't worry
about the lifetime and
[a,~,b] = [c,d,~] = [out1,out2,out3] = somefunc()
evaluates like:
1)
c = out1
d = out2
~ = out3 # discarded
2)
a = c
~ = d # discarded
b = [] # because ~ evaluates as []
So in the end:
a = out1
b = []
c = out1
d = out2
The thing is,I can't see why anyone would do this to set a variable to
[]? This is why I sort of prefer the other idea of making ~ disappear
from the cs-list when it's on the right-hand side. Then you would
write this instead:
[a,b] = [c,d,~] = [out1,out2,out3] = somefunc()
Which, to me is less ambiguous.
1)
c = out1
d = out2
~ = out3 # discarded
2)
cs-list [c,d,~] is now on the right hand side of an expression,
discard all ~. The result is cs-list [c,d]
3)
a = c
b = d
--judd
Re: Matlab-style empty output/input arguments support, Jaroslav Hajek, 2010/01/29
- Re: Matlab-style empty output/input arguments support, John W. Eaton, 2010/01/29
- Re: Matlab-style empty output/input arguments support, Jaroslav Hajek, 2010/01/29
- Re: Matlab-style empty output/input arguments support, Søren Hauberg, 2010/01/29
- Re: Matlab-style empty output/input arguments support, Jaroslav Hajek, 2010/01/29
- Re: Matlab-style empty output/input arguments support, John W. Eaton, 2010/01/29
Re: Matlab-style empty output/input arguments support, Michael D Godfrey, 2010/01/29