nhpip

nhpip

Variable bindings in IEx shell

First of all, don’t ask me why I want to do this :grinning: It was an experiment I was trying. I since decided to do it a different way, but it got me curious.

In the shell (or any other process for that matter), given a string like "time = System.os_time()" I can evaluate it with Code.eval_string("time = System.os_time()") and get back {1628697855326337000, [time: 1628697855326337000]}.

Yes, I know I can copy/paste the thing too, but humor me.

Is there a way I can programmatically inject the variable time into the shell’s variable bindings?

Basically do something like:

iex(1)> MagicModule.magic_function("time = System.os_time()")
1628697855326337000
iex(2)> time
1628697855326337000
iex(3)>

Most Liked

nhpip

nhpip

I found a really hacky way to do it in the shell

command = "foo = :ets.info(:pg2_table)"
send(self(), {:eval, Process.info(self())[:dictionary][:iex_server], command, %IEx.State{}})

Where Next?

Popular in Questions Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
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
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
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
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement