Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Nasser for Behaviour of `ToExpression` inside a function definition

It is because "arr" inside string do not bind to the input argument. You have to do it separatly.

a = {{1, 2}, {3, 4}};f[arr_] := ToExpression[ToString[arr] <> "[[1,1]]"]

And now it works

Image may be NSFW.
Clik here to view.
Mathematica graphics

But this type of coding can easily lead to errors and is fragile. It is better to find different approach for what you are trying to do.

takes in an array of unknown size

There is a command in Mathematica to find the size of list, it is called Dimensions and this way the called function can find the size of the input.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>