I want to create a function that takes in an array of unknown size and do some index operations on it. I am using strings to construct the expression and then trying to use ToExpression
for evaluating it. But this is not working as I think it should, below is a minimum working example:
a = {{1, 2}, {3, 4}};f[arr_] := ToExpression["arr[[1,1]]"];f[a]
This gives an error:
Part::partd: Part specification arr[[1,1]] is longer than depth of object.
Why is arr
not in the scope of the function body when ToExpression
is called?