[Top][All Lists]

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

[Octave-bug-tracker] [bug #32700] nargout(fn) Matlab compatibility

From: anonymous
Subject: [Octave-bug-tracker] [bug #32700] nargout(fn) Matlab compatibility
Date: Thu, 10 Mar 2011 16:33:02 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv: Gecko/20110218 Firefox/3.6.14

Follow-up Comment #1, bug #32700 (project octave):

I (the original submitter) have now attached a patch (the result of `hg
diff'), which fixes a bug as a side-effect (sorry) of extending the
functionality of nargout to match Matlab.

I think I originally misclassified this bug as "wishlist". Because I think the
fact that `nargout' returns -1 in this context:

% Set testcase.m to contain the following and run it:
function testcase()
function [a,b,c] = bar()
[a,b,c] = deal(1,2,3);

_is_ a bug. The patch fixes this and 3 is now returned, as it is in Matlab.

Other functionality introduced by the patch (all of which matches Matlab's
behavior as far as I can tell):
* nargout can be given a function handle as well as a string
* nargout(fcn) works in the top level
* inline functions always return 1
* anonymous functions always return -1
* functions with varargout optionally preceded by named outputs return

The final bullet means that `nargout(@more_out)' returns -3 for:

function [x,y,varargout] = more_out()
x = 1;
y = 2;

Even with the patch, nargout(@sin) does not work: I couldn't immediately work
out how to get the number of outputs of builtin functions. Can anyone help? If
not, this probably isn't a large cause for concern. Matlab's nargout doesn't
work on _all_ functions:

>> nargout(@histc) % works in Octave with my patch, because histc is an
??? Error using ==> nargout
histc does not know how to answer nargin/nargout.

Although `nargout(@sin)' _does_ work in Matlab.

The patch updates the documentation to take into account all of the above.

I've just noticed that, of course, `nargin' needs similar modifications to be
Matlab compatible. Shall I try to do a patch for that too?

(file #22878)

Additional Item Attachment:

File name: nargout.patch                  Size:3 KB


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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