AndyL
Can I extend iex helpers?
I’d like to add some custom helper functions to iex. I use .iex.exs and can define a module there with my custom functions. But I can’t figure out how to auto-import the module into my iex environment. I’ve tried hacking the iex bash script (at /usr/local/bin/iex), browsed thru the iex source - no luck. Is there a way to extend IEx.Helpers, or auto-import my .iex.exs module?
Most Liked
josevalim
In Elixir v1.14+ you will be able to import the module as you define it in .iex.exs files, as we now evaluate it line by line: Evaluate --dot-iex line by line · elixir-lang/elixir@395b053 · GitHub
AndyL
I couldn’t figure out how to load .beam files with the Code module. I ended up putting my helper source and beam files in ~/.iex, then made a bash alias ie=iex -pa ~/.iex. The -pa bit adds the .iex directory to the load path.
axelson
Is there an easy way to define an IEx helper now? I’d prefer to keep the helper definition inside .iex.exs if possible.
AndyL
So Code.load_file didn’t work, but I found a solution:
- create a helper module (
cd ~ && vim my_helpers.ex) - compile the helper module (
elixirc my_helpers.ex) - add an import statement to
.iex.exs(import MyHelpers) - test in
iex
What happens is that iex auto-loads the compiled beam file - then you can auto-import the helper module in .iex.exs.
You can tweak the beam-path by hacking the iex shell script (at /usr/local/bin/iex).
@gregvaughn thanks for your suggestions! 
Qqwy
Unfortunately, no, because it is not possible to import a module in the same file as in which it was defined: you will get above compile error scenario.







