add erlang, more-complex shell examples

- some Erlang and escript files
 - .escript extension
 - .erlang extension
 - shell script with %, ##, name tokens
This commit is contained in:
Patrick Reynolds
2013-06-06 15:24:25 -05:00
parent e33f4ca96e
commit 2db2f5a46d
8 changed files with 960 additions and 27 deletions

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname factorial -mnesia debug verbose
main([String]) ->
try
N = list_to_integer(String),
F = fac(N),
io:format("factorial ~w = ~w\n", [N,F])
catch
_:_ ->
usage()
end;
main(_) ->
usage().
usage() ->
io:format("usage: factorial integer\n"),
halt(1).
fac(0) -> 1;
fac(N) -> N * fac(N-1).