package ppx_defer

  1. Overview
  2. Docs
Go-like `[%defer later]; now` syntax.

Install

Dune Dependency

Authors

Maintainers

Sources

ppx_defer-0.3.0.tbz
sha256=c2fe82c787f43650ab5daf82e8ecd2d41a1e6444bd54ec82453cfbb34a4007eb
md5=ce43604abdf98806c2321481ecf6e75b

Description

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.

Published: 30 May 2017

README

ppx_defer - Go-like [%defer later]; now syntax.

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. ppx_tools_versioned
  2. ocaml-migrate-parsetree < "2.0.0"
  3. jbuilder >= "1.0+beta9"
  4. ocaml >= "4.02.3"

Dev Dependencies

None

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.