I am creating a Manipulate
that evaluates a function that takes an arbitrary number of binary control variables. For example, the Manipulate
takes in three control variables {a,b,c}
and returns the function f[ls_]:=DeleteDuplicates[ls]
. Some minimal working examples show different ways to accomplish this:
f[ls_] := DeleteDuplicates[ls];
m1[controls_] := Manipulate[f[controls],
Grid[{Map[Control[{{#, 1}, {0, 1}}] &, controls]}]];
m2[controls_] := Manipulate[f[controls],
Grid[{Map[Function[x, Evaluate[Control[{{x, 1}, {0, 1}}]]],
controls]}]];
m3[controls_] := Manipulate @@ {f[controls],
Grid[{Map[Control[{{#, 1}, {0, 1}}] &, controls]}]};
m1[{a,b,c}] // Print;
m2[{a,b,c}] // Print;
m3[{a,b,c}] // Print;
As might be expected, function m1
returns the error that the argument specifying the control variables does not have the right form. To rectify this, function m2
uses Function[x,...]
instead of a pure function. But what happens here is the control variable x
gets defined repeatedly. Function m3
rectifies this by using @@
, but when f
gets evaluated it isn't able to figure out that a=b=c
, so returns the strange result that DeleteDuplicates[{a,b,c}]={1,1,1}
.
Output is shown below. The desired output in this case is {1}.
What's going on here? Any way around this?