Erlang列表反转

-module(helloworld). 
-export([tail_reverse/2,start/0]). 

tail_reverse(L) -> tail_reverse(L,[]).

tail_reverse([],Acc) -> Acc; 
tail_reverse([H|T],Acc) -> tail_reverse(T, [H|Acc]).

start() -> 
   X = [1,2,3,4], 
   Y = tail_reverse(X), 
   io:fwrite(~w,[Y]).

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


-module(helloworld). -export([start/0]). start() -> A = 5, B = 6, if A == B -> io:fwrite("True");
-module(helloworld). -export([start/0]). start() -> A = 5, B = 6, if A == B -> io:fwrite("A is equal to B");
-module(helloworld). -export([start/0]). start() -> A = 4, B = 6, if A < B -> if A > 5 ->
-module(helloworld). -export([start/0]). start() -> A = 5, case A of 5 -> io:fwrite("The value of A is 5");
-module(helloworld). -export([add/2,start/0]). add(X,Y) -> Z = X+Y, io:fwrite("~w~n",[Z]).
% Erlang整数 -module(helloworld). -export([start/0]). start() -> io:fwrite("~w",[1+1]).
-module(helloworld). -export([tail_reverse/2,start/0]). tail_reverse(L) -> tail_reverse(L,[]). tail_reverse([],Acc) -> Acc;
-module(helloworld). -export([duplicate/2,start/0]). duplicate(0,_) -> []; duplicate(N,Term) when N > 0 ->
-module(helloworld). -export([tail_len/1,tail_len/2,start/0]). tail_len(L) -> tail_len(L,0). tail_len([], Acc) -> Acc;
-module(helloworld). -export([len/1,start/0]). len([]) -> 0; len([_|T]) -> 1 + len(T). start() ->
-module(helloworld). -export([fac/1,start/0]). fac(N) when N == 0 -> 1; fac(N) when N > 0 -> N*fac(N-1).
-module(helloworld). -import(io,[fwrite/1]). -export([start/0]). start() -> fwrite("Hello, world!\\n").
-module(helloworld). -author("TutorialPoint"). -version("1.0"). -export([start/0]).
-module(helloworld). -author("TutorialPoint"). -version("1.0"). -export([start/0]).
% Erlang模块定义 - helloworld -module(helloworld). -export([start/0]). start() -> io:fwrite("Hello World").
-module(helloworld). -export([add/1,start/0]). add(X) when X>3 -> io:fwrite("~w~n",[X]).
-module(helloworld). -export([add/2,add/3,start/0]). add(X,Y) -> Z = X+Y, io:fwrite("~w~n",[Z]).
-module(helloworld). -export([start/0]). start() -> Fn = fun() -> io:fwrite("Anonymous Function") end,
% 关系运算符 -module(helloworld). -export([start/0]). start() -> io:fwrite("~w~n",[3==2]),
-module(helloworld). -export([start/0]). start() -> io:fwrite("~w~n",[true or false]), io:fwrite("~w~n",[true and false]),