0

I have troubles to output an entire symbol, a function in this case, from a module or a block. For instance

 myf = Block[{f}, f[3] = 33; f[4] = 4; f]

Then I want to get the values of f from the module valorization, but I get

 In[531]:= myf[3]

 Out[531]= f(3)

instead I would like to get the value that I have put in the module, in this case `

 "desired behaviour"

 In[531]:= myf[3]

 Out[531]= 33

I might be asking a RTFM question, but I do not see it answered anywhere. Thanks for your help, Roberto

Rho Phi
  • 1,420
  • 11
  • 21

1 Answers1

3

This will probably be closed as a duplicate of either:

In the meantime the simple answer is that you need Module rather than Block, because the former creates a new Symbol whereas the latter merely temporarily changes the value of Symbol.

myf = Module[{f}, f[3] = 33; f[4] = 4; f]
f$1464
myf[3]
33

In the example f$1464 is the new Symbol that was created by Module.

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371