Skip to main content
Commonmark migration
Source Link

###Solution using Block

Solution using Block

###Use metaprogramming to automate things

Use metaprogramming to automate things

###Solution using Block

###Use metaprogramming to automate things

Solution using Block

Use metaprogramming to automate things

replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Finally, per additional request of the OP - here is what you can do if you want to evaluate those symbols which may expand into other symbols, but not the "final" ones. We will have to use some heavy artillery now. Load the code from this answerthis answer on dependency graphs, and then here is another function:

Finally, per additional request of the OP - here is what you can do if you want to evaluate those symbols which may expand into other symbols, but not the "final" ones. We will have to use some heavy artillery now. Load the code from this answer on dependency graphs, and then here is another function:

Finally, per additional request of the OP - here is what you can do if you want to evaluate those symbols which may expand into other symbols, but not the "final" ones. We will have to use some heavy artillery now. Load the code from this answer on dependency graphs, and then here is another function:

If all variables unfrozen just evaluate expression
Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424
ClearAll[evalWithFrozenSyms]
SetAttributes[evalWithFrozenSyms, HoldAll];
evalWithFrozenSyms[expr_, unfrozen : {___Symbol} : {}, 
   wrapper_: Hold, getsymbolsF_: getHeldSymbols
] :=
   With[{frozen = 
            Thread[
              Complement[
                getsymbolsF[expr],
                Thread[HoldComplete[unfrozen]]
              ],
              HoldComplete
            ]
          },
        If[ReleaseHold[frozen]If[frozen ===== {}, expr, 
          frozen /. HoldComplete[{syms___}] :>
            Block[{syms}, wrapper[##] &@expr]
        ]
   ]
ClearAll[evalWithFrozenSyms]
SetAttributes[evalWithFrozenSyms, HoldAll];
evalWithFrozenSyms[expr_, unfrozen : {___Symbol} : {}, 
   wrapper_: Hold, getsymbolsF_: getHeldSymbols
] :=
   With[{frozen = 
            Thread[
              Complement[
                getsymbolsF[expr],
                Thread[HoldComplete[unfrozen]]
              ],
              HoldComplete
            ]
          },
        If[ReleaseHold[frozen] == {}, expr, 
          frozen /. HoldComplete[{syms___}] :>
            Block[{syms}, wrapper[##] &@expr]
        ]
   ]
ClearAll[evalWithFrozenSyms]
SetAttributes[evalWithFrozenSyms, HoldAll];
evalWithFrozenSyms[expr_, unfrozen : {___Symbol} : {}, 
   wrapper_: Hold, getsymbolsF_: getHeldSymbols
] :=
   With[{frozen = 
            Thread[
              Complement[
                getsymbolsF[expr],
                Thread[HoldComplete[unfrozen]]
              ],
              HoldComplete
            ]
          },
        If[frozen === {}, expr, 
          frozen /. HoldComplete[{syms___}] :>
            Block[{syms}, wrapper[##] &@expr]
        ]
   ]
If all variables unfrozen just evaluate expression
Source Link
Loading
Added more advanced expansion functionality
Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424
Loading
Modified to enable selective evaluation, per OP's request
Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424
Loading
Added automation
Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424
Loading
Source Link
Leonid Shifrin
  • 114.9k
  • 16
  • 333
  • 424
Loading