Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format.pp_update_geometry: formatter -> (geometry -> geometry) -> unit #9237

Merged
merged 3 commits into from Jan 15, 2020

Conversation

gasche
Copy link
Member

@gasche gasche commented Jan 10, 2020

This lets users write code that is robust to the addition of new
geometry fields.

Format.(pp_update_geometry ppf (fun geo -> {geo with ...}))

Today the only way to set the geometry is

Format.pp_set_geometry ppf ~margin ~max_indent

we cannot add optional parameters after the [ppf] argument, and adding
new labeled parameters would break user code.

(Also: it's often convenient to work with the record directly, for
example to reset a previous geometry saved with [pp_get_geometry];
this is indirectly provided by [pp_update_geometry].)

@gasche
Copy link
Member Author

gasche commented Jan 10, 2020

(cc @Octachron and any other benevolent reviewer)

There are two small refactoring commits in this PR, so it is best reviewed commit-by-commit.

Copy link
Contributor

@jberdine jberdine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM: Using the new update api looks functionally equivalent to the existing get/set api.

stdlib/format.ml Outdated Show resolved Hide resolved
stdlib/format.mli Outdated Show resolved Hide resolved
@gasche gasche force-pushed the format-update-geometry branch 2 times, most recently from 43eef20 to 5cf7790 Compare January 10, 2020 15:04
Copy link
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me too. I have some minor nitpicking remarks that can be safely ignored:

stdlib/format.mli Outdated Show resolved Hide resolved

let pp_get_margin state () = state.pp_margin

let pp_set_full_geometry state {margin; max_indent} =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if full is the right adjective here: maybe unsafe? Or an adverb directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it as-is: this is not exposed in the public API, and the _full prefix will become self-evident after we start adding extra record fields, while pp_set_geometry is left partial due to backward-compatibility constraints.

This lets users write code that is robust to the addition of new
geometry fields.

    Format.(pp_update_geometry ppf (fun geo -> {geo with ...}))

Today the only way to set the geometry is

    Format.pp_set_geometry ppf ~margin ~max_indent

we cannot add optional parameters after the [ppf] argument, and adding
new labeled parameters would break user code.

(Also: it's often convenient to work with the record directly, for
example to reset a previous geometry saved with [pp_get_geometry];
this is indirectly provided by [pp_update_geometry].)
@gasche
Copy link
Member Author

gasche commented Jan 15, 2020

(The CI failure on AppVeyor appears to be due to memprof, and thus unrelated.)

@gasche gasche merged commit 82d7971 into ocaml:trunk Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants