dagda1
dagda1

Reputation: 28920

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.

Are these simply for documentation as I cannot see why they are used?

Upvotes: 1

Views: 433

Answers (1)

sepp2k
sepp2k

Reputation: 370445

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

Upvotes: 6

Related Questions