Editing Erlang escript files in Emacs using erlang mode
Posted by gldnspud on the 9th of May, 2007 at 11:03 pm under Uncategorized. This post has no comments.After reading about what Erlang has been used for, and about several of its pros and cons, I've decided to break out of my Python shell a bit and learn my first new programming language since 2002, when I was first introduced to Python. (Well, I've learned a bit more about things like JavaScript since then, but Python is the only one that I really dove into.)
It's also the first functional language I've learned, which is exciting, and is making me think about things a lot differently than I have before, even though I'm only 127 pages into Joe Armstrong's book.
I also like Emacs, in particular the variant that I use, Aquamacs.
The concept I just now learned about was the existence of escript, which lets you put a hash-bang line at the top of an erlang source file, make it executable, then run it as a script without using a wrapper script.
Out of the box, Emacs doesn't recognize that first line as an indicator that erlang-mode should be used.
Easy to fix. Just add a mode line in a comment as the second line in the file:
#!/usr/bin/env escript
%% -*- mode: erlang -*-
main([In]) ->
X = list_to_integer(In),
N = factorial(X),
io:format("factorial ~w = ~w~n", [X, N]).
factorial(0) ->
1;
factorial(N) ->
N * factorial(N - 1).
Submit Comment