list manipulation – How to convert Symbol to Number?

Question

I have a variable x which is associated with the number 1 : x= 1

In the program, I faced with the data type problem that x is evaluated as a Symbol but not a Number(integer ,double, etc).
(The detail of the problem is written in Background -> My trial section below.)

Not being familiar with the specification of Wolfram language, I’m naively thinking of solving this by converting the Symbol to Number using some standard function of Mathematica. However, I cannot find it.

Is it possible?

Any information would be appreciated.

Background

I want to make a function for fetching a value from some array by designating the entry(index) in mathematical style.

For example, I want to have a function fetchValue like this:

field1 = {{5,34,7},{9,77,11}}; (**)
field2 = {2,3,8,8,4,20,7,0,3}

fetchValue({1,2},field1) (* expected return: 34 *)
fetchValue({5},field2) (* expected return: 4 *)
fetchValue({55,1},field1) (* expected return: "Reference error. Check out the range of the array." *)
fetchValue({3,1,5,4},field1)(* expected return: "Reference error. Check out the dimension of the array." *)

My trial

Let me say we have the following two arrays:

  • the array field whose dimension is unknown(say d) and the size is n^d
  • the array position whose dimension is 1 and the size is d (the same with dimension of field)

Now, we want a function named fetchValue which takes

  • argument1 position : size d array (if d = 2, position = {2,5},{12,6},…)
  • argument2 field: size n^d array
fetchValue(position_, field_) := (
    width = Length(field);height = Length(field);
    dimension = Depth(field);
    index = 1;
    
    ret = field;
  
  While(level <= dimension,
   index = position((level));
 
   IF(1 <= index <= Length(ret), 
      ret = ret((index)), Return("Range is wrong")
    );
 
   level++;
 )

    Return (ret);
   );

This exactly returns the target entry of the field, but the data type of it is somehow a Symbol, not a Number, meaning I have to look for the way to convert Symbol to Number.

Further background

I’m in a project of calculating some fields on a discrete lattice and trying to use Mathematica.

The fields are not given as a analytical function, but all formed by computer calculation.

The fields are managed by array(list). So, if we want value of lattice point (1,2,5), we get the value by field((1))((2))((5)).

What I want is to make it easy to get access to the value of field on a certain lattice point like
field({1,2,5}).