Let's say I've got a list of procedures:
{Print[1];, Print[2];, Print[3];}
And I want to only evaluate 3rd one:
{Print[1];, Print[2];, Print[3];}[[3]]
1... 2... 3...
Well, that's not what I've wanted, the walkaround would be to use Hold
:
Hold[{Print[1];, Print[2];, Print[3];}][[ 1, 3]]
3
My question is: is there more "proper" way to do this?
p.s. the most tidy what I thought of is Switch
:
Switch[2,
1, Print[1],
2, Print[2],
3, Print[3] ]
2
Part
doesn't have attribute HoldAll, you either 1) wrap the commands inHold
orUnevaluated
, 2) redefinePart
, or 3) add viaUpSet
a new definition toPart
to handle held input (wrapped in e.g.hold
) differently. $\endgroup$