vrod
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!
Marked As Solved
hauleth
Also Liked
sezaru
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}"
end
apply(Bla, :ble, [0])
Last Post!
sezaru
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}"
end
apply(Bla, :ble, [0])
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









