erlang 语法练习

-export([qsort/1]).
-export([sum/1]).


qsort([]) -> [];
qsort([Pivot|T]) ->
	qsort([X || X <- T, X < Pivot])
	++[Pivot]++
	qsort([X || X <- T, X >= Pivot]).

sum([]) -> 0;
sum([Head|Tail]) -> Head + sum(Tail).


show(X) -> X.
for( F, N, N ) -> [ F(N) ];
for( F, I, Max ) -> [ F(I)|for(F,I+1,Max) ].

(emacs@b51997ad18ca401)41> emath:for( fun(X) -> emath:show(X) end, 1, 3 ).
[1,2,3]


perms([]) -> [[]];
perms(L) -> [ [H|T] || H <- L, T <- perms( L--[H] ) ].



你可能感兴趣的:(erlang 语法练习)