I am trying to setup a bunch of pure Functions in particular with an identical rahter long parameter list.
({a, b, c, d, e, f} \[Function] a + b)[r, s, t, u, v, w]
({a, b, c, d, e, f} \[Function] a*f)[r, s, t, u, v, w]
({a, b, c, d, e, f} \[Function] a*b/c)[r, s, t, u, v, w]
this works as expected:
r+s
r w
(r s)/t
Now I would like to put the formal parameter List in a variable:
pl = {a, b, c, d, e, f};
(Evaluate@pl \[Function] a + b)[r, s, t, u, v, w]
(Evaluate@pl \[Function] a*f)[r, s, t, u, v, w]
(Evaluate@pl \[Function] a*b/c)[r, s, t, u, v, w]
So far this works too an gives the sam result as above.
But there is a problem with the localization of the formal parameters. If I e.g. assign a value to the global Symbol a:
a=42;
I get an Error:
Function::flpar: Parameter specification {42,b,c,d,e,f} in Function[{42,b,c,d,e,f},a+b] should be a symbol or a list of symbols.
Any hints how to solve this problem? Have already tried various combinations of the usual suspects (Hold, Symbol, ...)
Kind Regards Robert
Ok, very close related to the first question I got a second one.
How can I get the SymbolName's of the Symbol's listed in pl? The need for this feature is e.g. to form a Table with TableForm and TableHeadings -> {None, pl}
a = 42;
pl := {a, b, c, d, e, f};
TableForm[{{1, 2, 3, 4, 5, 6}, {10, 20, 30, 40, 50, 60}}, TableHeadings -> {None, pl}]
5 b c d e f
1 2 3 4 5 6
10 20 30 40 50 60
As can bee seen the assignment to a spoils everything.
I have a little bit nasty solution via string matching:
OwnValues@pl // ToString //
StringCases[#, __~~"{"~~s__~~"}"~~__ :>StringSplit[s, ", "]] &//First
{"a","b","c","d","e","f"}
Can this be don more elegantly?
\[FormalA],\[FormalB]etc instead ofa,betc – Carl Woll Jun 17 '18 at 13:28OwnValues– Carl Woll Jun 18 '18 at 14:33