Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    $\begingroup$ Looks like the x_ is causing the lexical scoping mechanism to come into play but the HoldFirst on Table is breaking that. Check out this: foo3[x_] := With[{reps={log[var_] :> var}}, Table[(unk/.reps)->x, {unk, unks}]] $\endgroup$ Commented Mar 12, 2019 at 8:33
  • $\begingroup$ Also just gonna throw it out there since I think chances are good you know it already, but you're good on the fact that this is probably not the most less efficient way to do this, right? Better would be to do a more targeted Replace[..., rule, {1}] on unks first I imagine. Or if you need it deeper just to the /. there first or do a Replace[..., rule, {1, Infinity}] or something along those lines. $\endgroup$ Commented Mar 12, 2019 at 8:34
  • 1
    $\begingroup$ @b3m2a1 Don't assume anything about my programming knowledge! But in my real problem, I've already got something like {log[n] -> some stuff, log[m] -> some other stuff} that I need to transform to {n -> some (slightly different) stuff, m -> some other (slightly different) stuff}. $\endgroup$ Commented Mar 12, 2019 at 9:04
  • $\begingroup$ might be a place where something like Thread[Replace[Keys[#], log[n_]:>n, {1}]->Values[#]]& might be the least likely to have side effects. Alternately create your replacement rules first with Dispatch to get most of the benefit of vectorizing the call. $\endgroup$ Commented Mar 12, 2019 at 9:20
  • $\begingroup$ @b3m2a1 The HoldFirst of Table doesn't seem to be the issue: 1 /. x_ -> ((var_ -> var) -> x) returns (var$_ -> var) -> 1, which is already broken. From a few quick tests, it seems that all the rules in the example are needed for it to return strange results. $\endgroup$ Commented Mar 12, 2019 at 11:54