This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(json). | |
-export([json_to_term/2]). | |
%% extract the encoding from the options to pass to the parser, using auto if no encoding is | |
%% specified | |
json_to_term(JSON, Opts) -> | |
Encoding = proplists:get_value(encoding, Opts, auto), | |
P = jsx:parser([{encoding, Encoding}]), | |
collect(P(JSON), none, Opts). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(jsx_ex). | |
-export([simple_decode/1]). | |
simple_decode(JSON) when is_binary(JSON) -> | |
P = jsx:parser(), | |
decode(P(JSON), []). | |
decode({event, end_json, _Next}, Acc) -> | |
lists:reverse(Acc); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application:start({application, a, [{mod, {gen_app, [a]}}]}). | |
{"Kernel pid terminated",application_controller,{{badmatch,false},[{application_controller,handle_application_started,3},{gen_server,handle_msg,5}]}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case X of | |
one -> 1 | |
; two -> 2 | |
; _ -> more | |
end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lists:foldl(fun add_to_record/2, #record{}, List). | |
add_to_record({first_name, Value}, Rec) -> | |
Rec#record{first_name = Value}; | |
add_to_record({last_name, Value}, Rec) -> | |
Rec#record{last_name = Value}; | |
add_to_record({age, Value}, Rec) -> | |
Rec#record{age = Value}; | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(...) -> | |
SomeVariable = value(), | |
AnotherVariable = another_value(), | |
X = x(), | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5> 9007199254740991 / 404804506614621236704990693437834614099113299528284236713802716054860679135990693783920767402874248990374155728633623822779617474771586953734026799881477019843034848553132722728933815484186432682479535356945490137124014966849385397236206711298319112681620113024717539104666829230461005064372655017292012526615415482186989568. | |
** exception error: bad argument in an arithmetic expression | |
in operator '/'/2 | |
called as 9007199254740991 / 404804506614621236704990693437834614099113299528284236713802716054860679135990693783920767402874248990374155728633623822779617474771586953734026799881477019843034848553132722728933815484186432682479535356945490137124014966849385397236206711298319112681620113024717539104666829230461005064372655017292012526615415482186989568 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
json_to_term(JSON) -> | |
try json_to_term(JSON, []) | |
catch Type:Error -> erlang:Type(Error) | |
end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15> Z = fun(X) -> X = true end. | |
#Fun<erl_eval.6.13229925> | |
16> Z(false). | |
** exception error: no match of right hand side value true | |
17> try Z(false) catch error:badmatch -> ok end. | |
** exception error: no match of right hand side value true | |
18> try Z(false) catch error:Type -> Type end. | |
{badmatch,true} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loop([end_json], Acc) -> lists:reverse(Acc); | |
loop([Event|Events], Acc) -> loop(Events, [Event] ++ Acc); | |
loop(_, _) -> {error, badjson}. |
OlderNewer