For me, the natural meaning of the function Part is "get the sub-expression at appointing position." It is quite unlike Take, Take always keeps the head in the process. For example, by using Take:
Take[f[a, b, c[i], d[j, k], e, f], {3, 4}, 1]
(* Take the third to fourth position at level 1; and first position at level 2 *)
(* Output: f[c[i], d[j]] *)
When using Part:
Part[f[a, b, c[i], d[j, k], e, f], 4, 2]
(*Take the expression directly at the position 4, 2*)
(* Output: k *)
Until now, the mechanism of both functions is quite natural to me. However, the next result leaves me feeling confused:
f[a, b, c[i], d[j, k], e, f][[4]]
f[a, b, c[i],d[j, k], e, f][[4;;5]]
The output is d[j, k] versus f[d[j, k], e]. I don't know why I get the latter result -- where the extracted parts are wrapped with f. I was expecting {d[j, k], e}.
Is this design reasonable or useful in most cases? What is its intended use?
ref/ Partdetails section. And it can be usefulHold[Print[1], Print[2]][[{1}]]– Kuba Feb 21 '18 at 14:09Part[expr,{n}]seems undocumented. – Eric Feb 21 '18 at 14:18{}(namely, a list) right? – Eric Feb 21 '18 at 14:24Extract[f[a, b, c[i], d[j, k], e, f], {{4}, {5}}]. – Michael E2 Feb 21 '18 at 15:07Part[expr, Span[__]]andPart[expr, All]are basically syntactic sugar for invokingTake. – Sjoerd Smit Feb 21 '18 at 15:23Takeinstead ofPart[expr, List[__]]? – Eric Feb 21 '18 at 15:26Part[expr, List[__]]is something you can't really do withTake. For example, there's no way to dof[a,b,c,d,e][[{1, 2, 5}]]withTake. As for personal preference: I actually prefer to stick withPartmost of the time, except when I needTake[list, UpTo[n]](which actually works withPartandSpanas well, but is rather ugly). – Sjoerd Smit Feb 23 '18 at 10:39