mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 20:38:47 +00:00
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:
21
samples/Erlang/factorial.script!
Executable file
21
samples/Erlang/factorial.script!
Executable 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).
|
||||
Reference in New Issue
Block a user