octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Matlab-style empty output/input arguments support


From: Jaroslav Hajek
Subject: Re: Matlab-style empty output/input arguments support
Date: Fri, 29 Jan 2010 21:43:26 +0100

On Fri, Jan 29, 2010 at 1:06 PM, Dupuis <address@hidden> wrote:
>
>
>
> Jaroslav Hajek-2 wrote:
>>
>> The problem with option 1 (shrinking the list) is that you wouldn't be
>> able to do things like
>> [d, ~, f] = [a, ~, c] = myfun (...)
>> with the obvious meaning (f would be undefined here).
>>
>> I like option 2 in the sense that ~ produces [] in this context.
>> There's no need to allow ~ anywhere.
>>
>> thanks for the suggestion. I'll wait for more opinions and unless
>> someone disagrees I'll probably go for this option.
>>
>>
> 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 ?
>

I think the second option is the correct interpretation. The
assignment operator is an expression, it should
1. perform the assignment
2. return the new value
this becomes clear when you think about the computed assignment operators:
a = b += 2.

-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]