a. After launching the "iex" shell, press Tab. You'll get the list of all built-in commands.
b. The help feature is also very handy for when you're wondering what an operator does. Type "h <command>" for a definition.
h !/1
c. Try the pipe operator. Your code will closely follow the transformations of your data.Instead of this:
m1 = "moo"
m2 = String.replace(m1, "m", "z")
m3 = String.upcase(m2)
Or this: String.upcase(String.replace("moo", "m", "z"))
Try this: "moo" |> String.replace("m", "z") |> String.upcase()
The result of each command will be passed as the first argument to the subsequent command.d. You get seamless interoperability with Erlang libraries.
:crypto.hash(:md5, "bob") |> Base.encode64
e. Try the Observer tool in iex to visualize various aspects of your running application, including the supervision tree, details on each running OTP process, and much more. Seriously very handy stuff. :observer.start()
f. If you're using EC2 like I am, Amazon images have a too-old version of Erlang, but it's trivial to compile things yourself: sudo yum install gcc glibc-devel make ncurses-devel openssl-devel autoconf
wget https://www2.erlang.org/download/otp_src_18.0.tar.gz
tar xvzf otp_src_18.0.tar.gz
cd otp_src_18.0
./configure && make && sudo make install
sudo ln -s /usr/local/bin/escript /usr/bin/escript
sudo ln -s /usr/local/bin/erl /usr/bin/erl