I have a large number of data variables that are represented in MMA as symbols set to lists. For example:
x = {1, 2, 3};
y = {4, 5, 6};
I want to be able to write simple transformation rules on the data that I'd like to apply to the variables without writing the code out for each variable. For example, instead of
x = f[x];
y = f[y];
I'd like to write:
vars = {x, y};
(# = f[#])& /@ vars;
Or, if vars was defined too late (and x and y are already set to the actual data lists) then:
(# = f[#])& /@ {x, y};
Of course neither of these approaches work because x,y are evaluated. I've tried various combinations of Hold applied to the variable list vars but have been unable to get anything to work. Is something like this even possible? Or, is there a MMA way of doing this?
Attributes
. In particularHoldFirst
$\endgroup$Scan[Function[p, p = f /@ p, HoldAll], Hold[x, y]]
$\endgroup$