[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: functions with 'named' arguments
From: |
Søren Hauberg |
Subject: |
Re: functions with 'named' arguments |
Date: |
Mon, 17 Mar 2008 18:04:29 +0100 |
man, 17 03 2008 kl. 09:19 -0700, skrev Dupuis:
> Would itbe possible to implement one of those mechanisms in Octave ? The
> problem I don't see a solution at present is passing multiple optionnal args
> of the same type, with different roles, in a free-form fashion.
We already have default arguments. The following gives an example
function hello (who = "World")
printf("Hello, %s\n", who);
endfunction
>> hello()
Hello, World
>> hello("Wonderful World")
Hello, Wonderful World
Matlab has (kinda) always had named arguments, and you can do the same
in Octave. The standard syntax for calling a function the looks
something like this:
my_function(some_normal_argument, "name_of_var", value_of_var)
That is, the user provides the name of variable/option as a string, and
its values as the next parameter. The developer who implements the
function must then check the input for strings, and handle the values
correctly. This can be a bit tedious, but it works. And it's what Matlab
does.
Søren
- functions with 'named' arguments, Dupuis, 2008/03/17
- Re: functions with 'named' arguments,
Søren Hauberg <=
- Re: functions with 'named' arguments, Dupuis, 2008/03/18
- Re: functions with 'named' arguments, Søren Hauberg, 2008/03/18
- Re: functions with 'named' arguments, Dupuis, 2008/03/18
- Re: functions with 'named' arguments, Jaroslav Hajek, 2008/03/18
- Re: functions with 'named' arguments, Dupuis, 2008/03/18
- Re: functions with 'named' arguments, Shai Ayal, 2008/03/18
- Re: functions with 'named' arguments, Jaroslav Hajek, 2008/03/18
- Re: functions with 'named' arguments, Dupuis, 2008/03/18
- Re: functions with 'named' arguments, Jaroslav Hajek, 2008/03/18
- Re: functions with 'named' arguments, Dupuis, 2008/03/19