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/ Part
details section. And it can be usefulHold[Print[1], Print[2]][[{1}]]
$\endgroup$ – Kuba♦ Feb 21 '18 at 14:09Part[expr,{n}]
seems undocumented. $\endgroup$ – Eric Feb 21 '18 at 14:18{}
(namely, a list) right? $\endgroup$ – Eric Feb 21 '18 at 14:24