vrod

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

hauleth

It is not possible.

Also Liked

sezaru

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

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])

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement