erlang - version compare function, about special character -


i studying rabbitmq source code learning erlang technique.

the following rabbit_misc.erl file. purpose check application's minimum version. in 5th , 7th sub sentance of version_compare/n, there is special character, $0. don't know how happens? reason not happens in last sentance, after lists:splitwith/n, at1 , bt1 started "$.".

version_compare(a, b, lte) ->     case version_compare(a, b) of         eq -> true;         lt -> true;         gt -> false     end; version_compare(a, b, gte) ->     case version_compare(a, b) of         eq -> true;         gt -> true;         lt -> false     end; version_compare(a, b, result) ->     result =:= version_compare(a, b).  version_compare(a, a) ->     eq; version_compare([], [$0 | b]) ->     version_compare([], dropdot(b)); version_compare([], _) ->     lt; %% 2.3 < 2.3.1 version_compare([$0 | a], []) ->     version_compare(dropdot(a), []); version_compare(_, []) ->     gt; %% 2.3.1 > 2.3 version_compare(a,  b) ->     {astr, atl} = lists:splitwith(fun (x) -> x =/= $. end, a),     {bstr, btl} = lists:splitwith(fun (x) -> x =/= $. end, b),     anum = list_to_integer(astr),     bnum = list_to_integer(bstr),     if anum =:= bnum -> version_compare(dropdot(atl), dropdot(btl));        anum < bnum   -> lt;        anum > bnum   -> gt     end. 

$0 not special character -- 0 string: "0".

versions may complex: 0.1.22.333 , splitwith/2 splits head , tail ("0" , ".1.22.333").

i imagine handling $0 cases "1.0.0" , "1"

{"1",".0.0"} vs {"1",[]} 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -