Skip to main content

evaluation - Defer parts of the expression


Is there a way to Defer only parts of the expression? For example, I have


a=1;

and then I want the expression to be shown asa = 1;by usingDefer[a = Evaluate[a]],But the actual output is just


a = Evaluate[a]]

Is there away to only Defer part of an expression?



Answer



You can insert into held expressions in a number of ways:



Using ReplaceAll (/.): Defer[a=x]/.x->a


Using function evaluation: Defer[a=#]&[a]


Using With : With[{x=a}, Defer[a=x]


Example:


a = 2; z = 4; w = 5;
{Defer[a + w = x + z] /. x->a, Defer[a + w = # + z]&[a], With[{x = a},Defer[a + w = x + z]]}
(* {a + w = 2 + z, a + w = 2 + z, a + w = 2 + z} *)

Comments