programming erlang ch6 - andstudy/forge GitHub Wiki
- ^G๋๋ฅด๊ณ (Windows์์๋ ^Break) A ๋๋ฅด๊ธฐ
- erlang:halt() - ์์คํ ์ ์ฆ๊ฐ ์ค๋จ์ํค๋ BIF. ์ค๋ฅ ๋ณต๊ตฌ ์ ์ฐจ ํ์
- q()
๋ก๋๋์ง ์์ ์ด๋ค ๋ชจ๋์ ํจ์๋ฅผ ํธ์ถํ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ๊ณ ์์คํ ์ ํ์ฌ ๋ก๋ ๊ฒฝ๋ก์ ๋ค์ด์๋ ๋ชจ๋ ๋๋ ํ ๋ฆฌ์์ ํด๋น ๋ชจ๋์ ๋ชฉ์ ์ฝ๋ ํ์ผ์ ๊ฒ์ํ๋ค.
> code:get_path().
> code:add_patha(Dir).
> code:add_pathz(Dir).
> code:all_loaded().
> code:clash().
-----------------------------------------------------
$ erl -pa Dir1 -pa Dir2 ... -pz DirK1 -pz DirK2
์ผ๋ญ ๋ฐํ์ ์์คํ ์ ์ผ๋ญ์ผ๋ก ๋ง๋ค์ด์ง ์ฝ๋ ์๋ ๋ก๋ ๋ฉ์ปค๋์ฆ์ ์ฌ์ฉํ๋ค. E.4์ '๋์ ์ฝ๋ ๋ก๋ฉ'(483์ชฝ) ์ฐธ๊ณ
-
ํ ๋๋ ํ ๋ฆฌ์ .erlang ํ์ผ์ ์ผ๋ญ ์ฝ๋ ์์ฑ
-
ํ์ฌ ๋๋ ํ ๋ฆฌ์ .erlang ํ์ผ์ด ์ฐ์ - ์ด๋์ ์์ํ๋๋์ ๋ฐ๋ผ ์ผ๋ญ์ด ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ์๋ํ๋๋ก ๊ตฌ์ฑํ ์ ์๋ค.
-
์ผ๋ญ์ด ํ๋จํ๋ ํ ๋๋ ํ ๋ฆฌ ๋ณด๊ธฐ
1> init:get_argument(home). {ok,[["/user1/bt22d"]]}
-module(hello).
-export([start/0]).
start() ->
io:format("Hello world~n").
[bt22d@fog:/user1/bt22d/STUDY/erlang 11 ] erl
Erlang (BEAM) emulator version 5.6.3 [source] [smp:4] [async-threads:0] [hipe] [kernel-poll:false]
Running Erlang DIR(erlang)
Eshell V5.6.3 (abort with ^G)
1> c(hello).
{ok,hello}
2> hello:start().
Hello world
ok
[bt22d@fog erlang]$ erlc hello.erl
[bt22d@fog erlang]$ erl -noshell -s hello start -s init stop
Hello world
[bt22d@fog erlang]$
-noshell : ์ธํฐ๋ ํฐ๋ธ ์ ธ ์์ด ์ผ๋ญ ์์ -s hello start : hello:start() ํจ์ ์คํ (์ปดํ์ผ๋์ด ์์ด์ผ ํจ) -s init stop : init:stop() ์คํ (-s ... ๋ช ๋ น์ apply๋ฌธ๊ณผ ํจ๊ป ์ํ๋๋ฉฐ ์๋ฃ ์ ๊ทธ ๋ค์ ๋ช ๋ น์ด ์ํ๋๋ค)
#!/usr/bin/env escript
main(_) ->
io:format("Hello world\n").
[bt22d@fog erlang]$ chmod u+x hello
[bt22d@fog erlang]$ ./hello
Hello world
[bt22d@fog erlang]$
-module(fac1).
-export([main/1]).
main([A]) ->
I = list_to_integer(atom_to_list(A)),
F = fac(I),
io:format("factorial ~w = ~w~n",[I, F]),
init:stop().
fac(0) -> 1;
fac(N) -> N*fac(N-1).
# leave these lines alone
.SUFFIXES: .erl .beam .yrl
.erl.beam:
erlc -W $<
.yrl.erl:
erlc -W $<
ERL = erl -boot start_clean
# ์ปดํ์ผ ํ๋ ค๋ ์ผ๋ญ ๋ชจ๋๋ค์ ๋ชฉ๋ก
# If the modules don't fit onto one line add a \ character
# to the end of the line and continue on the next line
# Edit the lines below
MODS = module1 module2 \
module3 ... special1 ...\
...
moduleN
# The first target in any makefile is the default target.
# If you just type "make" then "make all" is assumed (because
# "all" is the first target in this makefile)
all: compile
compile: ${MODS:%=%.beam} subdirs
## special compilation requirements are added here
special1.beam: special1.erl
${ERL} -Dflag1 -W0 special1.erl
## run an application from the makefile
application1: compile
${ERL} -pa Dir1 -s application1 start Arg1 Arg2
# the subdirs target compiles any code in
# sub-directories
subdirs:
cd dir1; make
cd dir2; make
...
# remove all the code
clean:
rm -rf *.beam erl_crash.dump
cd dir1; make clean
cd dir2; make clean
| ^A | ์ค์ ์์ | | ^E | ์ค์ ๋ | | ^F | ํฌ์๋ ๋ฌธ์ | | ^B | ๋ฐฑ์๋ ๋ฌธ์ | | ^P | ์ด์ ์ค | | ^N | ๋ค์ ์ค | | ^T | ๋ง์ง๋ง ๋ ๋ฌธ์ ๊ต์ฒด | | Tab | ํ์ฌ์ ๋ชจ๋ ๋๋ ํจ์ ์ด๋ฆ์ ํผ์นจ์ ์๋ |
- ์ ธ์ด ์๋ตํ์ง ์๋๋ค.
- ^C ํธ๋ค๋ฌ๊ฐ ๋นํ์ฑํ
- -detached ํ๋๊ทธ๋ก ์ผ๋ญ์ ์์ํ ๊ฒฝ์ฐ
- -heart Cmd ์ต์ ์ผ๋ก ์ผ๋ญ์ ์์ํ ๊ฒฝ์ฐ
- ์ข๋น ์ผ๋ญ ํ๋ก์ธ์ค
[bt22d@fog:/user1/bt22d 49 ] erl -pa "/user1/bt22d/STUDY/erlang"
Erlang (BEAM) emulator version 5.6.3 [source] [smp:4] [async-threads:0] [hipe] [kernel-poll:false]
Running Erlang
Eshell V5.6.3 (abort with ^G)
1> code:clash().
** /user1/bt22d/STUDY/erlang/a.beam hides ./a.beam
** Found 1 name clashes in code paths
ok
2>
์ฌ๋ฌ ๊ฐ์ ์๋ํ๋ ์ ธ์ ๋๊ณ ์ํ๋ ๋ช ๋ น์ ๋ด๋ฆด ์ ์๋ค.
-
๋ฌดํํ ๊ธฐ๋ค๋ฆฌ๋ ์ ธ์ ์ค๋จ์ํค๊ธฐ
1> receive foo -> true end. User switch command --> h c [nn] - connect to job i [nn] - interrupt job k [nn] - kill job j - list all jobs s - start local shell r [node] - start remote shell q - quit erlang ? | h - this message --> j 1* {shell,start,[init]} --> s --> j 1 {shell,start,[init]} 2* {shell,start,[]} --> c 2 Eshell V5.6.3 (abort with ^G) 1> init:stop(). ok 2> [bt22d@fog:/user1/bt22d/STUDY/erlang 27 ] [bt22d@fog:/user1/bt22d/STUDY/erlang 27 ]
-
์ ๋์ค ์์คํ ์์ ๋์๋ง ๋ณด๊ธฐ
$ erl -man erl ... -
๊ฐ๋ณ ๋ชจ๋ ๋์๋ง
$ erl -man lists ... -
Windows์์๋ ๊ธฐ๋ณธ ์ค์น, Unix ์์คํ ์์๋ ์ค์น ํ์
์ผ๋ญ ์ ธ์ ๋ด์ฅ๋ ๋ช ๋ น๋ค์ ์ ธ ๋ช ๋ น help()๋ฅผ ์ด์ฉํด์ ๋ณผ ์ ์๋ค. ์ด ๋ด์ฅ ๋ช ๋ น๋ค์ shell_default ๋ชจ๋์ ์ ์๋์ด ์๋ค.
2> help().
** shell internal commands **
b() -- display all variable bindings
e(N) -- repeat the expression in query <N>
f() -- forget all variable bindings
f(X) -- forget the binding of variable X
h() -- history
...
-
user_default ๋ชจ๋์ ๋ง๋ค๋ฉด ์ฌ์ฉ์ ๋ด์ฅ ๋ช ๋ น์ ์ ์ํ ์ ์๋ค. user_default.beam์ด ๋ก๋ ๊ฒฝ๋ก ์ด๋๊ฐ ์์นํ๋ค๋ฉด ๋ชจ๋ ์ด๋ฆ ์์ด ํธ์ถ ๊ฐ๋ฅ
%%------------------ %% user_default.erl %%------------------ -module(user_default). -compile(export_all). hello() -> "Hello Joe how are you?". away(Time) -> io:format("Joe is away and will be back in ~w minutes~n", [Time]).
-
erl_crash.dump
-module(test). -export([crash/0]). crash() -> 1000000 * crash(). -
์น ๊ธฐ๋ฐ์ ํฌ๋์ ๋ถ์๊ธฐ
1> webtool:start(). WebTool is available at http://localhost:8888/ Or http://127.0.0.1:8888/ {ok,<0.34.0>}