help-octave
[Top][All Lists]
Advanced

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

Re: Forcing Variable Outputs


From: Bill Denney
Subject: Re: Forcing Variable Outputs
Date: Wed, 29 Mar 2006 11:00:10 -0500 (EST)

On Wed, 29 Mar 2006, John W. Eaton wrote:

I think what you want is

 function varargout = fxn1 (varargin)
   varargout = cell (nargout, 1);
   [varargout{:}] = fxn2 (varargin{:});
 endfunction

but this feature of Matlab is not yet implemented in Octave.

That's exactly what I'm wanting (I didn't realize that it was a matlab feature).

The reason it is not done yet is that decoding the LHS of the assignment

 [varargout{:}] = fxn2 (varargin{:});

must be done before the function on the RHS is called so that nargin
may be set properly when the function is called, and doing that in the
general case is relatively complex and may require partial evaluation
of the expression inside the square brackets on the LHS.  For example,
think about a case like

 [foo(i,j(k),f(x,y,z)).bar{s:t}] = fxn2 (...);

the index expressions used here could be functions with side effects,
etc.

I realize that this is a complex case, and I would think it would be feasible to require the LHS to be an expanded cell of some type for it to be evaluated.

But maybe it would be relatively simple to correctly handle simple
cases like the one in your example above, and implementing that might
get 90% of the uses of this kind of feature.

I think that I would be very helpful to hit the 90% of cases. I acknowledge that this is probably a relatively rare request of the interpreter. The reason that I was wanting it is I was trying to write an ndgrid function that is the same as meshgrid, but with the first two input and output arguements swapped. Meshgrid takes an arbitrary list of arguements and an equal number of output arguements. I could fudge it by just making nargout=nargin, but I was wanting to do it right.

But this seems like a missing feature/bug in Matlab.  Why not simply
set nargout to 0 if varargout is empty in the expression
[varargout{:}]?  Am I missing something here?

That makes complete sense to me.

Bill

--
"Be who you are and say what you feel, because those who mind don't
matter and those who matter don't mind."
  -- Dr. Suess



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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