일부 코드를 이해하려고 할 때 디버거를 사용할 수 있습니다. 특히 이와 같은 코드는 매우 작습니다. ERL 또는 werl : 얼랑 쉘을 시작
-module (test1).
-compile(export_all).
odds_and_evens_acc(L) ->
odds_and_evens_acc(L, [], []).
odds_and_evens_acc([H|T], Odds, Evens) ->
case (H rem 2) of
1 -> odds_and_evens_acc(T, [H|Odds], Evens);
0 -> odds_and_evens_acc(T, Odds, [H|Evens])
end;
odds_and_evens_acc([], Odds, Evens) ->
{Odds, Evens}.
같은 디렉토리에 :
라는 파일 test1.erl를 작성합니다.
1> %% compile the code for debug
1> c(test1,[debug_info]).
{ok,test1}
2> %% create a list of integer for test
2> L=lists:seq(1,8).
[1,2,3,4,5,6,7,8]
3> %% start the debugger
3> debugger:start().
{ok,<0.38.0>}
4> %% in the menu Module, select interpret... and then the file test1.erl
4> %% then check the box Auto attach on break
4> %% double click on module name test1
4> %% put a break point on the first line of code
4> %% start the function
4> test1:odds_and_evens_acc(L).
이 창에 도착해야합니다
다음 단계 단추를 사용하여 값 패널을 살펴보고 프로그램의 진화를 볼 수 있습니다. 트레이스 패널을 열면 실행 추적을 볼 수 있습니다 : Options/Trace Window/Trace Area
%%. never less를 피하면 대답이 더욱 아름답습니다. –