[Scilab-Dev] list as output in function call
Samuel Gougeon
sgougeon at free.fr
Wed Apr 24 10:07:42 CEST 2019
Le 24/04/2019 à 09:25, Antoine ELIAS a écrit :
> Le 23/04/2019 à 22:50, Samuel Gougeon a écrit :
>> Hello,
>>
>> Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :
>> .../...
>>>
>>> Just a question, specific to ndgrid, why do not update the function
>>> to return a list in case of nargout == 1 ?
>>
>> You likely mean as a unique explicit argout, instead of the varargout
>> "implicit" list.
>> Wrapping the result in a list would break a lot of code, and would
>> make addressing the results more complicated for most frequent cases.
>>
> Absolutely not ;)
> I said that only for this specific case "ndgrid".
Yes, this is what i understood.
> I think that only break non-working code.
With the current implementation, the following works, with argn(1)==1:
--> X = ndgrid(1:4)
X =
1. 1. 1. 1.
2. 2. 2. 2.
3. 3. 3. 3.
4. 4. 4. 4.
> and varargout is a real list ! ( Do not discriminate ^^ )
Yes, it is build as a real list to feed the return. But is not
/processed/ as a classic list when returning, since it is assigned in a
distributive way, while it's not the case for a simple list.
So yes we have to discriminate both, as the test below shows it:
--> function varargout = test()
> varargout = list("a","b","c")
> endfunction
--> [a,b,c] = test()
c =
c
b =
b
a =
a
--> function L = test()
> L = list("a","b","c")
> endfunction
--> [a,b,c] = test()
Wrong number of output arguments.
And, alone, returning a list as the first element in or out of varargout
would not fix the issue:
--> function varargout = test()
> varargout = list(list("a","b","c"))
> endfunction
--> a = list(,,);
--> a(:) = test()
Unable to insert multiple item in a list.
--> function [r,varargout] = test()
> if argn(1)==1
> r = list("a","b","c")
> varargout = list()
> end
> endfunction
--> a = list(,,);
--> a(:) = test()
Unable to insert multiple item in a list.
For the general discussion, i think that, from a user's point a view,
when using a container as LHS argument, a distributive assignment would
be *often* very useful. It might be either through a new *.=*
"operator", or through the classic "=" one but only when for instance
the RHS is a container as well,
* either a list with the right number of elements at depth = 0
* or a cell or struct array with the same sizes as the cell or struct
(or struct or cell) on the LHS
AFAIR, this kind of feature is already reported as a wish.
Best regards
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/dev/attachments/20190424/56d48131/attachment.htm>
More information about the dev
mailing list