开发者

Erlang code explained

I am having a bit of trouble getting my head around the following erlang code

-module(threesix).  
-export([quicksort/1]).  

quicksort(Pivot, Left, Right, []=_Src) ->  
     {Left, Pivot, Right};  
quicksort(Pivot, Left, Right, [H|T]=_Src) when H < Pivot ->  
     quicksort(Pivot, [H|Left], Right, T);  
quicksort(Pivot, Left, Right, [H|T]=_Src) ->  
     quicksort(Pivot, Left, [H|Right], T).  

quicksort([]) ->  
     [];  
quicksort([H|T]=_List) ->  
     {Left, Pivot, Right} = quicksort(H, [], [], T),  
     quicksort(Left) ++ [Pivot] ++ quicksort(Right). 

I am specifically talking about the use of _Src and _List in the parameters.

A开发者_运维技巧re these simply for documentation as I cannot see why they are used?


Yes, they're only for documentation. They're not actually used (as signified by the leading underscore).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜