3.5: adda/syntax/parameters/varying numbers of:
. if only some functions can accept lists
(varying numbers of parameters)
how do you define these functions?
. should we assume they are like numeric's args
where the {addition, multiplication}
is taking {2, or more} args,
while the {subtraction, division}
is taking only {1,2} args ?
. for the {1,2}-arg case,
we would define 2 args,
and then give one a default;
eg, here's numeric's division operation:
/(numerator.R`= 1, denominator.R).R
-(minuend.R`= 0, subtrahend.R).R
. for the {2, or more}-arg case,
the (...)-symbol would be used;
eg, here's numeric's multiplication operation:
*(x1.R, x2.R, ...).R .
. when dealing with a list (...) of args,
we need some way to refer to items of the list,
or we can let the user name the list ?
*( x1.R, x2.R, ... xn.List(R) ).R
. that says any other params beyond 2
will be placed in a list named xn .
. we can do Python's idea of args like this:
( x1., x2., ..., xn.List, fn.Map)
-- now any extra values are put in xn,
and any other named-param-associations are in fn .
2012-03-31
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment