[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: named arguments
From: |
CdeMills |
Subject: |
Re: named arguments |
Date: |
Fri, 16 Mar 2012 09:46:18 -0700 (PDT) |
I discussed the idea a few years ago. I think R interface is MUCH cleaner
through named arguments. OTOH when I tried to put on paper the idea behing
named args, make the distinction between positional and named arguments the
right way was everything but trivial. In the mean time, I settled upon:
function somefunc(pos1, pos2, pos3, varargin)
%#optionnal arguments
numarg = nargin - 3;
indopt = 1;
option_args = {'Method'; 'Corr'};
while (numarg)
dummy = varargin{indopt++};
if (!ischar (dummy))
error ("somefunc: optional arg %d at pos %d is not a string", dummy,
indopt-1);
endif
switch (find (strcmpi (dummy, options_args)
case 1
Method = varargin{indopt};
case 2
Corr = varargin{indopt};
otherwise
unknown_par = varargin{indopt};
warning ("pronysq: %s is not a known option", dummy);
endswitch
indopt++; numarg -= 2;
endwhile;
This way, arguments comes as pair (name, value). The name matching is case
insensitive, because forgetting the right uppercase/lowercase settings is
easy ...
Regards
Pascal
--
View this message in context:
http://octave.1599824.n4.nabble.com/named-arguments-tp4477933p4478689.html
Sent from the Octave - General mailing list archive at Nabble.com.
- Re: named arguments, (continued)
- RE: named arguments, Damian Harty, 2012/03/16
- Re: named arguments, Jordi Gutiérrez Hermoso, 2012/03/16
- Re: named arguments, fork, 2012/03/16
- Re: named arguments, John W. Eaton, 2012/03/16
- Re: named arguments, fork, 2012/03/16
- Re: named arguments, Miguel Bazdresch, 2012/03/16
- Re: named arguments, Francesco Potortì, 2012/03/17
- Re: named arguments,
CdeMills <=