# Taking a Part of a Part of a Variable

Say I have Part of a variable x.

Part[x, 1]


Then, I'll get an error message, as the variable x is not recognised as a list with multiple parts.

If I want to suppress this error, because I know for sure x will have multiple parts, I can use the Quiet function.

Quiet[Part[x, 1], {Part::partd}]


But now imagine that the list variable x itself is an element of another list y such that x=y[[1]].

Quiet[Part[Part[y, 1], 1], {Part::partd}]


I expect this to return y[[1][[1]], however, what I get is y.

Any ideas why this happens? Obviously the examples are simplified working examples, but it should work. How can I get my expected behaviour?

• A robust way would be to use Indexed instead of Part. See also here. – Henrik Schumacher Sep 14 '18 at 13:36
• You get y because Part[y, 1] doesn't evaluate if y is atomic. So the outer Part then extracts the first argument of Part[y,1], which is y. This is because Part works on arbitrary expression, not just Lists – Sjoerd Smit Sep 14 '18 at 13:45
• @SjoerdSmit Ah, that makes sense. Though adding an Evaluate around the inner Part doesn't seem to work. The Indexed solution is much nicer anyway, as it also doesn't require the Quiet. – LBogaardt Sep 14 '18 at 13:47
• Evaluate will not do anything here since there's no hold attribute to override (see also mathematica.stackexchange.com/a/180500/43522) . Mathematica tries to evaluate Part[y, 1], but since there's nothing it can evaluate to, it stays the way it is. That's how Mathematica handles most ill-defined expressions: it's part of the symbolic nature of the language. Mathematica uses a term-rewriting style of evaluation and when there's no applicable rules available, things just stay the way they are. – Sjoerd Smit Sep 14 '18 at 13:51

Based on Henrik Schumacher's comment (feel free to answer yourself, then you'll get the credits).

Indexed[x, 1]