Skip to content

Instantly share code, notes, and snippets.

@russelldb

russelldb/f.erl Secret

Created April 23, 2015 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save russelldb/4f8fe205bd5a5a1cd136 to your computer and use it in GitHub Desktop.
Save russelldb/4f8fe205bd5a5a1cd136 to your computer and use it in GitHub Desktop.
Run `f:loop(20).` on pre-r17 erlang, and be fine, run it on r17+ and be sad.
module(f).
-compile([export_all]).
loop(0) ->
done;
loop(N) ->
io:format("N ~p~n", [N]),
Fname = "rdb.file",
Bin = crypto:rand_bytes(8),
Term = [{name, Bin}],
IOLIst = io_lib:format("~p.", [Term]),
ok = write_file(Fname, IOLIst),
{ok, [Term]} = file:consult(Fname),
loop(N-1).
write_file(FN, Data) ->
case file:open(FN, [write, raw]) of
{ok, FH} ->
try
ok = file:write(FH, Data),
ok = file:sync(FH),
ok = file:close(FH),
ok
catch _:Err ->
{error, Err}
end;
Err ->
Err
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment