1 | initial version |
Do you really not want to just have a function of two variables, such as the following?
sage: def f(i,x):
....: return x^(-i)
sage: f(2,2)
1/4
sage: f(3,2)
1/8
I think there is some problem with making a list of lambda functions, but you could use the idea of a "factory" -- a function that returns another function:
sage: def named_function_factory(i):
....: def f(x):
....: return x^(-i)
....: return f
....:
sage: functionlist = [named_function_factory(i) for i in range(10)]
sage: functionlist[2](2)
1/4
sage: functionlist[3](2)
1/8
But note that this is really not so different from just using a function of two variables, i
and x
, so maybe I still haven't answered your question. But I also don't see an appreciable difference between typing "functionnamei(x)
" and "functionname[i](x
)" or "functionname(i,x)
" for that matter. These are of course quite different in terms of their data types, but is that so significant here?