# Indexing a function result

Having a function resolving into a list:

IntegerDigits[19835193751, 2^8, 8]
> {0,0,0,4,158,69,9,151}


Its result can be indexed fine like this:

IntegerDigits[19835193751, 2^8, 8][[5]]
> 158


But when symbolics are involved, all hell breaks loose:

IntegerDigits[q, 2^8, 8][[1]]
> q

IntegerDigits[q, 2^8, 8][[2]]
> 256

IntegerDigits[q, 2^8, 8][[3]]
> 8

IntegerDigits[q, 2^8, 8][[0]]
> IntegerDigits


I understand what happens and why, but how could I explain to the program that I want the results indexed, not an object which holds the function and its arguments?

Added: I suppose it boils down to defining a resolution order for functions - Part should stay deferred until its argument becomes a List. Still figuring out an implementation though.

• Look up Indexed – Carl Woll Apr 16 '18 at 23:28
• @CarlWoll good point, but this feature is relatively new, older versions don't have it. – ogurets Apr 16 '18 at 23:40

In M10+ you can use Indexed. In versions before M10, you could do:

indexed[l_List, n_Integer?NonNegative] := l[[n]]


For example:

expr = indexed[IntegerDigits[q, 256, 8], 5]

expr /. q->13943312222


indexed[IntegerDigits[q, 256, 8], 5]

63