[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: Mon, 07 Mar 2011 11:35:29 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv: Gecko/20110218 Firefox/3.6.14


                 Summary: nargout(fn) Matlab compatibility
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Mon 07 Mar 2011 11:35:27 UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Feature Request
                  Status: None
             Assigned to: None
         Originator Name: Iain Murray
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: dev
        Operating System: GNU/Linux



In Matlab the nargout function can take a function handle or name and will
return the number of output arguments that it takes. The number is negative
for variable numbers of outputs and (undocumented) -1 if the number is
variable "[varargout]".

In Octave (according to the documentation) "At the top level, `nargout' is
undefined." The only functions Octave will report nargout for are those within
the same m-file (and Octave 3.2.3 reports -1 for those regardless). Support
for function handles has not been implemented at all. Example output in Matlab
and Octave are given below.

Use case: I ran into this compatibility wishlist item while trying to use a
routine for robustly timing functions:
    (Motivated here:
http://blogs.mathworks.com/steve/2008/02/29/timing-code-in-matlab/ )
This routine works in Octave if its second input argument is specified, as
then nargout isn't called. Otherwise it crashes.


>> fn = @() deal(1,2,3)
fn = 
>> nargout(fn)
ans =


octave:1> fn = @() deal(1,2,3)
fn =

@() deal (1, 2, 3)

octave:2> nargout(fn)
error: octave_base_value::convert_to_str_internal (): wrong type argument
`function handle'
error: nargout: expecting string as first argument


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

Running foo in Matlab prints out '3', whereas Octave prints out '-1'.


I'm not familiary enough with Octave internals to immediately write a patch. I
just got as far as finding nargout implemented at the line beginning "DEFUN
(nargout," in ov-usr-fcn.cc


Reply to this item at:


  Message sent via/by Savannah

reply via email to

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