Restore / recreate function reference?

This is perhaps a crazy question! Forgive my ignorance!

I start with something like this:

iex> f = fn -> IO.puts("hi") end
#Function<45.79398840/0 in :erl_eval.expr/5>

I am wondering if I know 45.79398840/0, how is it possible to recreate the function? Something like

new_f = make_function_somehow(45.79398840/0)
new_f.() # "hi"

Is this possible? Is it only possible on the same node? Or not possible at all? Or is it possible to retrieve the original function definition (fn -> IO.puts("hi") end)?

Thank you in advance!

It is not possible.

1 Like

Thank you for clarifying!

Probably not what you are looking for based on your first post, but just so you know, you can “store” a more “serializable” function reference using the module and function name as an atom, for example:

defmodule Bla do    
  def ble(n), do: "#{n}"

apply(Bla, :ble, [0])
1 Like