octave-maintainers
[Top][All Lists]
Advanced

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

Re: functions with 'named' arguments


From: Dupuis
Subject: Re: functions with 'named' arguments
Date: Tue, 18 Mar 2008 07:01:42 -0700 (PDT)



Jaroslav Hajek-2 wrote:
> 
> 
> What I'm trying to explain is that
> hello(closing='bla') already *has* a meaning in Octave, and it is
> *not* what you have
> on mind. In R, this is no problem because the assignment is not "=".
> In Fortran and Python, this is no problem because assignment is not an
> expression (not sure about Python, but I think so).
> 
> It is perfectly legal in Octave (and sometimes useful) to write things
> like
> x = exp (y = -y)
> A possible solution would be to implement keyword arguments using
> different character than "=", but I think that the standard workaround
> using a cell array (of the form {"name", value, "name", value}) is
> already good enough.
> 

OK, I see more clearly the point. In R, "=" is an assignment operator, which
can be used at top level, or as a subexpression in a braced list of
expression.

My opinion is that having an assignment of an variable expressed in the
middle of a function call is a bit strange. OTOH, the semantic meaning
"initialize the function parameter with the corresponding name" makes more
sense. If you look at R, Python or Perl, this adds a level of clarity, both
for the programmer, because the bindings are performed automatically, and
for the user, because each arguments and their default value are evident
from the function definition.

With the list of names and values approach, and given the availability of
functions like "parseparams", it is up to the programmer to test for valid
and invalid cases. From the user perspective, default values and allowed
names are to be searched for inside the function body. 
 
So, having named args 'à la Python/R/...' would add a level of clarity.
Regarding the other use, i.e. mixing variable assignment and function call,
this can be accomplished by x = exp((y=-y)) : the parens ensure the
assignment is performed first, and the "return" value, the new assigned var,
used as function parameter. 

I insist on this because I was Java programmer in a previous life, and
dealing with objects usually means playing with a lot of so-called
attributes. To this end, objects were created, and numerous calls were
performed to modify attributes one-by-one. This was a nightmare to devise
and to use. Later, I had opportunities to touch Python scripts, and found
their approach of named args cleaner and safer.

Greetings

Pascal  
-- 
View this message in context: 
http://www.nabble.com/functions-with-%27named%27-arguments-tp16095584p16121881.html
Sent from the Octave - Maintainers mailing list archive at Nabble.com.




reply via email to

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