I often need to extract to restrict value lists to sublists, ie if vals gives values of vars={x1,x2,x3,x4}, and I need values of svars={x2,x4} I do restrict[list,vars,svars] where
restrict[vars_, svars_, vals_] :=
Extract[vals, Flatten[Position[vars, #] & /@ svars, 1]]
I'd like to improve code readability, perhaps by defining following custom notation for restrict[vars,svars,vals]
(source: yaroslavvb.com)
My questions are
- What is a good way to implement this?
- Is this a good idea altogether?