help-octave
[Top][All Lists]
Advanced

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

Re: Feature request: optional arguments


From: A. Scottedward Hodel
Subject: Re: Feature request: optional arguments
Date: Fri, 11 Dec 1998 13:43:44 -0600

What I've done with the control systems toolbox is
to pass an empty matrix for such optional arguments, e.g.

    sys = ss2sys(a,b,c,[],0.01)

constructs a zero "D" matrix of appropriate dimension and sets the system 
sampling time
to 0.01sec.  The procedure in the script is identical to yours except that one 
uses
isempty(d) instead of exist("d"). 

>Hi,
>
>Whenever a script function has several optional arguments it's a pain to
>write the script function and use it.
>
>Suppose that I want to have a function
>
> foo (x,y,z)
>
>where *any* argument can be optional! If some argument is not specified,
>than a default would be supplied. The usual approach would be to
>consider some magic number to mean "use the default"; one could use "0",
>so
>
> foo(0,0,123)
>
>would mean: use default value for x and y, and use "123" for z.
>Of course every function must have its own magic number for defaults, as
>"0" can be meaningful for some functions.
>
>What I propose is that Octave parser accepts missing argument as valid,
>but do not assign it: for example:
>
> foo(,,123)
>
>would set z=123 and let x and y undefined. Then in the script file one
>would just check for the existence of each argument:
>
> if (!exist("x"))
>  x=11;
> endif
> ...
>
>without having to check for the multiple occurrence/combination of
>arguments: each one would be checked individually.
>
>Of course, one could also specify the defaults in the function
>declaration:
>
> function o = foo(x=11, y=22, z=33)
>
>but to be useful it should allow *any* missing argument, not as in C++.
>
>But this is ask too much, I think that the first approach is enough, and
>it still keeps compatibility with existing script files.
>
>As a concrete example, think in the script function "axis", and that you
>want to keep all axis in autoscaling mode *except*, say, ymin and ymax.
>
>Comments?
>Joao
>
>---
>Joao Cardoso                |   e-mail: address@hidden
>INESC, R. Jose Falcao 110   |   tel: + 351 2 2094322
>4050 Porto, Portugal        |   fax: + 351 2 2008487
>



A S Hodel Assoc. Prof. Dept Elect Eng, Auburn Univ,AL  36849-5201
On leave at NASA Marshall Space Flight Center (256) 544-1426
http://www.eng.auburn.edu/~scotte



reply via email to

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