help-octave
[Top][All Lists]
Advanced

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

Re: varargout{:} = func() ?


From: John W. Eaton
Subject: Re: varargout{:} = func() ?
Date: Wed, 24 Feb 2010 10:43:39 -0500

On 24-Feb-2010, forkandwait wrote:

| I guess there is no notation in case one doesn't know the number of expected 
| outputs?  I am just curious at this point.

The value of nargout for the function call is determined by what
appears on the left hand side of the assignment.  So you have to be
able to look at the left hand side of the assignment *before* the
function call to decide what nargout will be for the function call.

The syntax is either

  x = func ();             ## nargout is 1

  [x, y, ...] = func ();   ## nargout is the number of elements in the
                           ## comma-separated list appearing inside
                           ## the square brackets.

An expression like x{:} expands to a comma-separated list.  If x is
not defined, then the number of elements is not defined.

Even if Matlab allows you to play fast and loose with things like

  clear x
  [x{:}] = func ()  ## nargout is 1

or

  clear x
  x{:} = func ()    ## nargout is 1

or worse

  x = cell (3, 1);
  x{:} = func ()    ## nargout is 1, but why?  If x{:} is a
                    ## comma-separated list, then it seems that it
                    ## should be equivalent to
                    ##
                    ##   x{1}, x{2}, x{3} = func ()

To me  to me, this looks like an unintended consequence of the
particular implementation.  Or, it could be intentional
inconsistency.  If the latter, then I think it is even worse, as
I can see no particular benefit from having this inconsistency in the
language.

In any case, I would prefer to NOT copy this behavior.

jwe


reply via email to

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