binary - Convert bitstring to tuple -


i'm trying find out how convert erlang bitstring tuple, far without luck.

what want example <<"{1,2}">> tuple {1,2}.

you can use modules erl_scan , erl_parse, in this answer. since erl_scan:string requires string, not binary, have convert value binary_to_list first:

> {ok, scanned, _} = erl_scan:string(binary_to_list(<<"{1,2}">>)). {ok,[{'{',1},{integer,1,1},{',',1},{integer,1,2},{'}',1}],1} 

then, you'd use erl_parse:parse_term actual term. however, function expects term end dot, have add explicitly:

> {ok, parsed} = erl_parse:parse_term(scanned ++ [{dot,0}]). {ok,{1,2}} 

now variable parsed contains result:

> parsed. {1,2} 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -