I want to return a Hold expression but with some parts pre-evaluated. The easiest way to explain this is probably through code example. Here is what I have currently:
In[1] := y = 3;
In[2] := Hold[f[x, y]]
Out[2] := Hold[f[x, y]]
In[3] := Hold[f[x, Evaluate[y]]]
Out[3] := Hold[f[x, Evaluate[y]]]
But I want something which returns Hold[f[x, 3]]. (My actual use case is to return a Hold expression involving the value of symbols which are local to a Block.)
How can I achieve this?
With[{y=1+1}, Hold[{x,y}]], which will first evaluate1+1then inject the result in a held expression. – Szabolcs Feb 17 '15 at 18:30Hold[f[x, y]] /. HoldPattern[y] :> RuleCondition[y]-- and I think this should be closed as a duplicate of the question linked above. – Mr.Wizard Feb 17 '15 at 19:01Withas Szabolcs showed, or:Function[y, Hold[f[x, y]]][y]– Mr.Wizard Feb 17 '15 at 19:03Function[y, Hold[f[x, y]]][y]pretty much immediately after I posted the question. But anyway I think Szabolc'sWithsolution is slightly cleaner. Yes, the thing to replace is always aSymbol, so it's not an exact duplicate of pattern replacement problem. – Saran Tunyasuvunakool Feb 17 '15 at 19:41y /. y_ :> Hold[f[x, y]]see: (1929) for examples. Would you object to having this question closed as "already answered" via a combination of (29317) and that? – Mr.Wizard Feb 17 '15 at 19:48