How to Block Symbols without evaluating them?

前端 未结 4 1725
春和景丽
春和景丽 2020-12-28 08:45

Suppose I have a list of names of Symbols:

f1 := Print[\"f1 is evaluated!\"];
list = {\"f1\", \"f2\"};

The obvious way to

4条回答
  •  孤城傲影
    2020-12-28 09:26

    You may consider this construct:

    SetAttributes[block, HoldRest]
    
    block[s : {__String}, body_] := 
     Function[, Block[{##}, body], HoldAll] @@ 
      Join @@ MakeExpression /@ s
    

    Second attempt at a shorter version of Leonid's second function:

    block =
      Function[, Block @@ ToHeldExpression@ToString@#~Join~Hold@#2, HoldRest]
    

提交回复
热议问题