-
Notifications
You must be signed in to change notification settings - Fork 14
/
example1.erl2
55 lines (36 loc) · 904 Bytes
/
example1.erl2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
%% Example1:
%% factorial(25) is assumed to take a long time to compute
%% In the generated module mod1.erl
%% we import the result of the earlier computation
defMods mod1 shell end.
addMod shell.
def fac = fun(0) -> 1; (N) -> N*fac(N-1) end.
120 = fac(5).
F25 = fac(25).
addMod mod1.
def a(N) -> F25 + N end.
addMod shell.
io:format("mod1:a(10)=~p~n",[mod1:a(10)]).
erl2:make_mods().
%% Sample output
%% $./erl2 example1.erl2
%% Created:"gen/exprs.tmp"
%% mod1:a(10)=15511210043330985984000010
%% make_mods saving generated code...
%% Created:"gen/all.gen"
%% Created:gen/mod1.erl
%% Created:gen/shell.erl
%% Success
%% $ cat gen/shell.erl
%% -module(shell).
%% -compile(export_all).
%% fac(0) ->
%% 1;
%% fac(N) ->
%% N * fac(N - 1).
%% $cat gen/mod1.erl
%% -module(mod1).
%% -compile(export_all).
%% a(N) ->
%% F25 = 15511210043330985984000000,
%% F25 + N.