6

1

One can do

```
expression = a + 1;
f[a_] := Evaluate[expression]
```

but how would one do something like this

```
expression = a + 1;
g[x_] := Module[{a,b},
a=1;
b=Evaluate[expression];
x*b
]
```

so that only variable b right-hand side would be evaluated and not the whole Module. This would be useful for using long formulas generated by mathematica in own function definitions.

**The solution suitable for me:**

Thanks Jens for the answer, that pointed me to the right direction. The solution I was looking for and works for me is

```
expression = a + 1;
With[{expr=expression},
f[x_]:=Block[{a,b},
a = 1;
b = expr;
x*b
]
]
```

So using With outside of SetDelayed causes evaluation of expression as desired (Jens answer) and the naming problem (a and $a) is solved by using Block instead of Module.

Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise.

– bbgodfrey – 2015-08-10T22:01:46.960Relevant link, though not necessarily a duplicate due to

– Jens – 2015-08-10T23:06:14.403`Module`

: Evaluation in lambda function. There may well be other duplicate Q&As, but I haven't found one yet.