package ppx_defer
A syntax extension to provide a somewhat Go-like defer
Install
Dune Dependency
Authors
Maintainers
Sources
v0.1.0.tar.gz
sha256=b87ca804d9cb97bb2a7832dc891b5d3617ea7f5e16cee4c158e63b77e4babae3
md5=010ce32e79ef4ff23025fc2aac4ce721
README.md.html
ppx_defer
This is an OCaml language extension implementing a somewhat Go-ish [%defer expr1]; expr2
which will defer the evaluation of expr1
until after expr2
. expr1
will still be evaluated if expr2
raises an exception.
The implementation is based purely on moving syntax around so ppx_defer is not as powerful or safe as Go's defer
.
Thanks to Drup for guidance in figuring out ppx details!
Using ppx_defer
let () =
let ic = open_in_bin "some_file" in
[%defer close_in ic];
let length = in_channel_length ic in
let bytes = really_input_string ic length in
print_endline bytes
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>