tags:

views:

126

answers:

1

Hi,

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?

Thanks

Paul

+4  A: 

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

sepp2k
actually there is nothing to enforce them "not actually used" the _ just tells the compiler not to complain about them not being used.
fuzzy lollipop
@fuzzylollipop: Right, but by putting the _ there you're basically saying "I don't intend to use this variable - I only named it for clarity"
sepp2k