Let's say I want to define a function indexed by an natural number $g$, which is given by $$f_g(x)=g+x$$
I could (I guess naively) write the following code to define it up until $g=19$
For[g = 1, g < 20, g++, f[g] = g + # &]
But, for some reason, this doesn't work. If you try to evaluate, let's say
f[3]
f[3][10]
you see that the use of # delays the replacement of $g$ until you give the function an argument. $f_3(10)$ above returns $30$ for example, since that's the value of $g$ at that point in the code.
Now, I am aware I could just define a two-variable function (I think that's actually doable in the original problem I'm working on too) but I would still like to understand what is going on here and how I can get around this without actually avoiding the problem altogether.
Thank you all.