[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Feature request: optional arguments
From: |
Joao Cardoso |
Subject: |
Feature request: optional arguments |
Date: |
Fri, 11 Dec 1998 19:29:21 +0000 |
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
- Feature request: optional arguments,
Joao Cardoso <=