How to Block Symbols without evaluating them?

前端 未结 4 1720
春和景丽
春和景丽 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:32

    You could try to use ToExpression:

    In[9]:= list = {"f1", "f2"};
    
    In[19]:= f1 = 25;
    
    In[20]:= ToExpression[
     StringJoin["{", Riffle[list, ","], "}"], InputForm, 
     Function[vars, Block[vars, f1], HoldAll]]
    
    Out[20]= 25
    

提交回复
热议问题