
Untitled
By: a guest on
May 16th, 2012 | syntax:
None | size: 2.31 KB | hits: 18 | expires: Never
How to use a macro from inside a macro in the definition of Manipulate controls?
Manipulate[Text["ok"],
Evaluate@With[{
x = Function[{}, (*----> macro x *)
TabView[{
"x" -> "working on x"
}], HoldAll
],
y = Function[{}, (*----> macro y *)
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
(* now use the above macros *)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
ContentSize -> 300
]
Evaluate@With[{
checkBox = Function[{}, Checkbox[Dynamic[c]], HoldAll],
x = Function[{},
TabView[{
"x" -> checkBox[] (*=====> DOES NOT WORK, did not bind *)
}], HoldAll
],
y = Function[{},
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
{{c, True}, None},
ContentSize -> 300
]
Manipulate[Text["ok"],
Evaluate@With[{
x = Function[{},
TabView[{
"x" -> Checkbox[Dynamic[c]] (* add the definition directly *)
}], HoldAll
],
y = Function[{},
TabView[{
"y" -> "working on y"
}], HoldAll
]
},(*WITH*)
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[Which[choice == 1, x[], choice == 2, y[]] ]}
}]
],
{{choice, 1}, None},
{{c, True}, None},
ContentSize -> 300
]
In[3]:= With[{a=b,c=f[a]},g[c]]
Out[3]= g[f[a]]
In[5]:=
With[{a=b},
With[{c=f[a]},g[c]]]
Out[5]= g[f[b]]
ClearAll[LetL];
SetAttributes[LetL, HoldAll];
LetL /: Verbatim[SetDelayed][lhs_, rhs : HoldPattern[LetL[{__}, _]]] :=
Block[{With}, Attributes[With] = {HoldAll};
lhs := Evaluate[rhs]];
LetL[{}, expr_] := expr;
LetL[{head_}, expr_] := With[{head}, expr];
LetL[{head_, tail__}, expr_] :=
Block[{With}, Attributes[With] = {HoldAll};
With[{head}, Evaluate[LetL[{tail}, expr]]]];
DynamicModule[{choice = 1, c = False},
Grid[{
{SetterBar[Dynamic[choice], {1, 2}]},
{Dynamic[
Which[choice == 1, TabView[{"x" -> Checkbox[Dynamic[c]]}],
choice == 2, TabView[{"y" -> "working on y"}]]]},
{Dynamic[choice], Dynamic[c]}
}]
]