If you are looking for a solution that doesn't iterate over a list, you may be interested by what is called "memoization". The target of memoization is not to assign DownValues to a symbol as you ask. Memoization is a optimization for speed. Assignment of Dowvalues to a symbol is a "side effect" (in all meanings of the term), which is not recommended, but here, that may correspond to your need.
The idea of Memoization is that your array is built more and more each time you call array[index]
whith a new index :
Here is the intialisation :
list = {3, 1, 4, 8};
array[i_] := (array[i] = list[[i]])
Definition[array]
The array definition is no more than array[i]=list[i]
. This is a parasitic term that may annoy you, depending of your application.
Then if you call array[index]
with say, index=1, then the DownValue 3 is added to the definiton of array (array[1]=3
) :
array[1]
Definition[array]
and so on ...
array[2]
Definition[array]
Of course, if you want to load the entire array in one time at the beginning, you need to do something similar to a iteration, for example :
array /@ Range[Length[list]]
Definition[array]
DownValues
instead of "Array". TheArray
function just creates lists and is in no way connected to something likesomeArrayName[someIndex]
$\endgroup$Map
,Fold
andSelect
. If you really need some kind of readily available "index" additional to your data have a look atAssociation
$\endgroup$a[i]
(single brackets!) were used to represent subscripted variables, as found in standard mathematical notation, i.e. $a_i$. Maybe this is no longer "good Mathematica", but I think it was "the official line" at some point. $\endgroup$