help-octave
[Top][All Lists]
Advanced

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

Re: matlab nargin() function alternative in octave?


From: John W. Eaton
Subject: Re: matlab nargin() function alternative in octave?
Date: Wed, 21 Jan 2004 09:38:34 -0600

On 21-Jan-2004, Sharene Deanne Bungay <address@hidden> wrote:

| Thank you for making those additions!
| I've checked out the latest CVS, compiled, and get the following
| when attempting to use nargin():
| 
| octave-2.1.52:1> nargin("sin")
| error: nargin: invalid function

The new nargin and nargout functions only work for .m files or
functions defined on the command line.  I think that is consistent
with the way that Matlab works.  If not, it would be easy to change
for things like sin (all built-in mapper functions take one input and
produce one output).  But making it work for other built-in functions
would be a lot of work and require some incompatible changes, because
there is currently no way to ask those functions about the number of
inputs they accept or the number of outputs they produce, and I see no
way of doing that other than to add that number to the DEFUN macro,
which is likely to be unreliable over time (it seems likely that some
functions will be modified to accept an additional argument or produce
an additional output, but the numbers will not be updated
accordingly).

BTW, Octave doesn't prevent you from doing something like

  function f (a)
    ## some code
  endfunction

  f (1, 2)  ## or more arguments

but Matlab will apparently automatically produce an error for code
like this, so you can never call a user-defined function with more
than the declared number of arguments.  Likewise for output values, so
given the above function definition,

  x = f (1)

would also be trapped before the function is called.

Should Octave do the same?  Now that we have the new nargin and
nargout functions, it would be relatively easy to implement.  The real
question is whether it is useful or just annoying.

jwe



-------------------------------------------------------------
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]