package ppx_defer

  1. Overview
  2. Docs
A syntax extension to provide a somewhat Go-like defer

Install

Dune Dependency

Authors

Maintainers

Sources

v0.2.0.tar.gz
md5=a9505957d567684a753f661c583c2b8a

Description

[%defer e1]; e2 or [%defer.lwt e1]; e2 will defer the evaluation of e1 until after e2 is evaluated.

Tags

syntax

Published: 10 Mar 2016

README

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.

If you are using Lwt you can use [%defer.lwt expr1]; expr2.

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

See the examples/ directory for more examples.

Dependencies (4)

  1. ocamlbuild build
  2. ocamlfind build
  3. ppx_tools >= "0.99.3"
  4. ocaml >= "4.02.3"

Dev Dependencies

None

Used by

None

Conflicts

None