<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Le 24/04/2019 à 09:25, Antoine ELIAS a
écrit :<br>
</div>
<blockquote
cite="mid:395e75be-b64f-042f-5978-661ca57ad07d@scilab-enterprises.com"
type="cite">Le 23/04/2019 à 22:50, Samuel Gougeon a écrit :
<br>
<blockquote type="cite">Hello,
<br>
<br>
Le 23/04/2019 à 22:28, Antoine ELIAS a écrit :
<br>
.../...<br>
<blockquote type="cite">
<br>
Just a question, specific to ndgrid, why do not update the
function to return a list in case of nargout == 1 ?
<br>
</blockquote>
<br>
You likely mean as a unique explicit argout, instead of the
varargout "implicit" list.
<br>
Wrapping the result in a list would break a lot of code, and
would make addressing the results more complicated for most
frequent cases.
<br>
<br>
</blockquote>
Absolutely not ;)
<br>
I said that only for this specific case "ndgrid". </blockquote>
<br>
Yes, this is what i understood.<br>
<br>
<blockquote
cite="mid:395e75be-b64f-042f-5978-661ca57ad07d@scilab-enterprises.com"
type="cite">I think that only break non-working code.
<br>
</blockquote>
<br>
With the current implementation, the following works, with
argn(1)==1:<br>
<br>
<font size="-1"><tt>--> X = ndgrid(1:4)</tt><tt><br>
</tt><tt> X = </tt><tt><br>
</tt><tt> 1. 1. 1. 1.</tt><tt><br>
</tt><tt> 2. 2. 2. 2.</tt><tt><br>
</tt><tt> 3. 3. 3. 3.</tt><tt><br>
</tt><tt> 4. 4. 4. 4.</tt></font><br>
<br>
<blockquote
cite="mid:395e75be-b64f-042f-5978-661ca57ad07d@scilab-enterprises.com"
type="cite">and varargout is a real list ! ( Do not discriminate
^^ )
<br>
</blockquote>
Yes, it is build as a real list to feed the return. But is not <i>processed</i>
as a classic list when returning, since it is assigned in a
distributive way, while it's not the case for a simple list.<br>
So yes we have to discriminate both, as the test below shows it:<br>
<font size="-1"><tt>--> function varargout = test()</tt><tt><br>
</tt><tt> > varargout = list("a","b","c")</tt><tt><br>
</tt><tt> > endfunction</tt><tt><br>
</tt><tt><br>
</tt><tt>--> [a,b,c] = test()</tt><tt><br>
</tt><tt> c = </tt><tt><br>
</tt><tt> c</tt><tt><br>
</tt><tt><br>
</tt><tt> b = </tt><tt><br>
</tt><tt> b</tt><tt><br>
</tt><tt><br>
</tt><tt> a = </tt><tt><br>
</tt><tt> a</tt><tt><br>
</tt><tt><br>
</tt><tt>--> function L = test()</tt><tt><br>
</tt><tt> > L = list("a","b","c")</tt><tt><br>
</tt><tt> > endfunction</tt><tt><br>
</tt><tt><br>
</tt><tt>--> [a,b,c] = test()</tt><tt><br>
</tt><tt>Wrong number of output arguments.</tt><br>
</font><br>
And, alone, returning a list as the first element in or out of
varargout would not fix the issue:<br>
<br>
<font size="-1"><tt>--> function varargout = test()</tt><tt><br>
</tt><tt> > varargout = list(list("a","b","c"))</tt><tt><br>
</tt><tt> > endfunction</tt><tt><br>
</tt><tt><br>
</tt><tt>--> a = list(,,);</tt><tt><br>
</tt><tt>--> a(:) = test()</tt><tt><br>
</tt><tt>Unable to insert multiple item in a list.</tt></font><br>
<br>
<font size="-1"><tt>--> function [r,varargout] = test()</tt><tt><br>
</tt><tt> > if argn(1)==1</tt><tt><br>
</tt><tt> > r = list("a","b","c")</tt><tt><br>
</tt><tt> > varargout = list()</tt><tt><br>
</tt><tt> > end</tt><tt><br>
</tt><tt> > endfunction</tt><tt><br>
</tt><tt>--> a = list(,,);</tt><tt><br>
</tt><tt>--> a(:) = test()</tt><tt><br>
</tt><tt>Unable to insert multiple item in a list.</tt></font><br>
<br>
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 <b>often</b> very useful. It might be either
through a new <b>.=</b> "operator", or through the classic "=" one
but only when for instance the RHS is a container as well,<br>
<ul>
<li>either a list with the right number of elements at depth = 0</li>
<li>or a cell or struct array with the same sizes as the cell or
struct (or struct or cell) on the LHS</li>
</ul>
<p>AFAIR, this kind of feature is already reported as a wish.</p>
<p>Best regards<br>
Samuel<br>
<br>
</p>
</body>
</html>