Let’s dive into the code base and see how this works. Elixir has awesome meta programming capabilities and all this can be done in less than 50 LOC.

There are 2 main macros in this file:

First is the Zombie.bury which stores the variables available in the current scope in a file named .iex_state , Elixir provides an easy way to get a hold of all the variables in the current scope using a macro called binding which returns a keyword list of variable names and their values. Now, we take this and use the :erlang.term_to_binary function to convert the whole expression into a binary which can then be saved to a file.

And the second macro is named Zombie.resurrect which reads a previously stored state file and passes it through :erlang.binary_to_term to deserialize the data from our file into Erlang/Elixir terms. Once we have these terms, it is just a matter of looping over the variable property list and creating a function for each (which returns the associated value) and finally wrapping it in a module named Zombie.Vars

That was all that was needed resurrect dead variables 😁 I’d love to see other folks do this for projects which use ruby, javascript etc.