# Tag Info

5

Old versions: Use StringForm[]: example[a_, b_] := Module[{c = a + b}, ToString[StringForm["The solution is ", c]]] example[x, x + 1] "The solution is 1 + 2 x" New versions: Use StringTemplate[]: example[a_, b_] := Module[{c = a + b}, StringTemplate["The solution is sol"] @ <|"sol" -> ToString[c, ...

3

Apart from StringForm["The solution is ", c], another solution is using StringJoin[](<>) directly. example[a_, b_] := Module[{c}, c = a + b; "The solution is " <> ToString[c] ] Or example[a_, b_] := "The solution is " <> ToString[a + b]

2

I think that value injection using With will work for you. Let's first define the sample g value you want: g = 1 + x^2 Now we define myfunc injecting the current definition of g inside its definition: Clear[myfunc] With[{g = g}, myfunc[f_] := Simplify[f/g]] Now let's change the value of g and check whether the definition of myfunc is affected: g = ...

2

lead[f_Function ] := lead[f@\[FormalX]] lead[f_?PolynomialQ] /; (Length[(v = Variables[f])] == 1) := Last@CoefficientList[f, v[[1]]] lead[2 x^2 - x + 7 ] lead[ 3 #^2 - # + 7 &] 2 3 Note this breaks if you supply a pure function with more than one slot. See here if you need to deal with that: How can I get the number of slots in Function?

1

Maybe something like this? g = 1 + x^2 Unprotect[saveg] saveg = g; myfunc[f_] := Simplify[(f/saveg)] Protect[saveg]

Only top voted, non community-wiki answers of a minimum length are eligible