Hello folks,
Suppose I wish to follow a book, which instructs us to key in a set of elixir expressions/functions in IEx. I’m supposed to validate and learn from the outputs/errors coming from the session. Now I’d like to save that session in a file and be able to “replay” it for future reference/refreshing or even for teaching others.
Is there a feature/scheme in IEx which enables me to achieve this? I’ve read about the .iex.exs file but it appears to me this file is not intended for the purpose I’m talking about here.
Any pointers will be greatly appreciated. Many thanks
Ramesh
@rameshkumar There are no features I know that allow saving specific part of history into session files, but there is something really similar for Erlang/OTP 20+ …
You need to set ERL_AFLAGS environment variable for example in bash:
export ERL_AFLAGS="-kernel shell_history enabled"
Make sure you add this to your shell init file (depends on shell and OS/distribution) for example in bash you need to add it to $HOME/.bashrc or ~/.bashrc (same but shorter).
Source:
Of course nothing stops you from writing code like:
defmodule MyBook.MyChapter.MyTopic do
def my_lesson(…) do
end
end
IO.puts("Book: …")
IO.puts("Chapter: …")
IO.puts("Topic: …")
IO.puts("Lesson: …")
result = MyBook.MyChapter.MyTopic.my_lesson(…)
Logger.debug(result, label: "Result:")
# other lessons …
# other topics …
# other chapters …
# other books …
Thank you @Eiji. Not exactly what I had looked for but persisting the history itself is something that I’ve been yearning for.
As for your suggestion of using defmodule, def, IO.puts etc, I wanted to avoid this to enable students to not need to be aware of modules/functions to show some code examples.
For sure I gave examples with modules and directories structure in order to well group code examples. Nobody stops you from writing code to files like examples/1.ex or examples.ex where each example is separated by code. At least for me it’s not a good practice, but in programming you are free to do everything you want - even if it’s one huge mistake.