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

Exact assertions & multi commodity balances #871

Closed
wants to merge 34 commits into from

Conversation

ag-eitilt
Copy link
Contributor

I'm not entirely sure how "lay the groundwork for #556" became "implement #183 and #861", especially since doing so was only a side effect of putting multiple commodities on a single line. That, at least, can be traced to what @simonmichael mentioned about halfway down #195, but that still begs the question of why I implemented exclusive balance assertions before what I actually set out to fix. Either way, it seems to work, unless I missed testing some strange interaction somewhere. And with minimal journalfile breakage, as well: commodities including parentheses need to be quoted now, but that might actually bring things more in line with ledger, depending on what its arithmetic expressions disallow.

If multiple amounts of the same commodity are included in a single
amount, they should be condensed to their sum; this has the side benefit
of allowing arithmetic in postings.
As commas are potential decimal separators, using them as amount
separators throws off the parsing with the current precedence
("10.25, 4" is read as "1025" with a precision of 0, before getting
confused at the "4") unless we force the slightly-unnatural syntax of
space-comma.  It is likely possible to work around that, but the parsing
that would be required is particularly complex, and the simplicity
doesn't outweigh the risk of bugs.

'+' was chosen over '/' to both reflect the behaviour when one commodity
is listed multiple times, as arithmetic is a more accurate conception
than alternatives, and to potentially allow '-' in the future to extend
the allowed math.
"brick" constraint is only arbitrary; should be revisited when someone
has time to focus on infrastructure.
@ag-eitilt
Copy link
Contributor Author

Ah, didn't notice that test suite. Not quite sure what happened to the rewrites, but I'll track that down next.

@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. journal The journal file format, and its features. needs:discussion To unblock: needs more discussion/review/exploration needs:impact-analysis To unblock: needs analysis of interactions with other features, users, ecosystem needs:testing To unblock: needs more developer testing or general usage needs:review To unblock: needs more code/docs/design review by someone labels Sep 22, 2018
@simonmichael
Copy link
Owner

Thanks for the PR! Tip: use make functest to run those functional tests locally. You'll need to install shelltestrunner.

This looks like a WIP branch, which might get cleaned up before merge, so I'll review with that in mind. For reviewers, can you summarise the effect of this PR, eg: "it allows posting amounts and balance assertion amounts to be written as arithmetic expressions" ?

@simonmichael
Copy link
Owner

simonmichael commented Sep 22, 2018

I think I'm right in saying the impact of these commits is:

Adds amount expressions:

  1. amounts (in postings, balance assertions, balance assignments) can be written as addition/subtraction expressions of multiple amounts: $10 - $0.25 + EUR 5.
    This means that a single posting can describe a multi-commodity change (a MixedAmount, not just an Amount). And balance assertions/balance assignments can check/set more than one commodity at once.

  2. parentheses can be used to enclose these amount expressions (making them Ledger-compatible) and to enclose subexpressions: ($10 - ($0.25 + EUR 5)).
    This means that commodity symbols containing parentheses will need to be double-quoted.

Adds exact multi-commodity assertions:

  1. balance assertions can be written with == to assert that no commodities other than the ones written are present: == $10.25 + EUR 5 means the balance contains no other commodities.
    Assertions still ignore subaccounts and cleared status.

Doesn't actually do anything yet, but is less heavy-handed than the
other method I was trying.
`$6.10 + £4.35 * 0.8 €` -> `$6.10 + 3.48 €`
`($6.10 + £4.35) * 0.8 €` -> `8.36 €`
`$6.10 * (£0.2 + 0.8 €)` -> `£1.22 + 4.88 €`

Copy link
Owner

Choose a reason for hiding this comment

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

I think folks will immediately want division (/) as well, can you add that ? We'll need to handle division by zero in some reasonable manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding it won't be hard at all, except for divide-by-zero; the operation parser wound up being amazingly extensible. I'm tempted to just make it silently fail, but it's probably better to work through the error reporting system to ensure sanity. I've not looked at that yet, though, so I might put division off until the end of the refactor, if you think that's all right.

Copy link

Choose a reason for hiding this comment

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

division can be a problem too... What would be the amount for $0.05 / 3 ?

Copy link
Owner

Choose a reason for hiding this comment

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

1.6666666666666666...

Copy link
Owner

Choose a reason for hiding this comment

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

I meant: 0.016666666666666666...

Copy link
Owner

@simonmichael simonmichael left a comment

Choose a reason for hiding this comment

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

Nice docs and examples.

site/doc/1.11/journal.md Show resolved Hide resolved
applied to the posting value).

Any postings in real transactions which attempt to use this
multiplication-headed form will ignore the value instead.
Copy link
Owner

@simonmichael simonmichael Oct 5, 2018

Choose a reason for hiding this comment

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

I didn't understand "headed by" onward exactly. Shall we simplify again, deleting those lines ? Ie we will accept an amount, an amount expression, or a numeric multiplier (*N). (There'll probably be desire for \N, +N, -N, arbitrary arithmetic functions, referencing other parts of the transaction etc., but those can wait)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Blame a couple years of linguistics. That's the passage that was primary in the "first draft" naming of the commit. I'll revisit this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the "those can wait", I might actually put the first step of the PR together without multiplication entirely. Addition and subtraction are a much more contained change, and seem to generate much less discussion (while being more frequently requested). We should definitely keep working out the questions around multiplication, but splitting things further like that means there's less pressure to resolve it so we can find something we're all happier with.

@simonmichael simonmichael added needs:discussion To unblock: needs more discussion/review/exploration needs:history-cleanup To unblock: needs commit history cleanup/clarifying needs:value-proposition To unblock: needs clearer justification, review of benefits vs costs and removed needs:design To unblock: needs more thought/planning, leading to a spec/plan needs:docs To unblock: needs corresponding documentation or doc updates labels Oct 5, 2018
@ag-eitilt
Copy link
Contributor Author

ag-eitilt commented Oct 12, 2018

So, this week is going to be mostly focused on smaller refactoring as well, starting with splitting out the assertation portion. I'll leave this open for now to not lose the conversation, but once the amount expressions get cleaned up, I'll close this PR; that seems the best way to cut through the tangle.

[new PR: #902]

@cfellinger
Copy link
Collaborator

cfellinger commented Oct 12, 2018 via email

@simonmichael
Copy link
Owner

We don't currently support rounding strategies, that would be a separate discussion. We store arbitrary decimal numbers (up to 255 decimal places IIRC), and we display them with the number of decimal places inferred or specified for each commodity.

@simonmichael simonmichael removed needs:testing To unblock: needs more developer testing or general usage needs:discussion To unblock: needs more discussion/review/exploration labels Oct 12, 2018
@simonmichael simonmichael added needs:discussion To unblock: needs more discussion/review/exploration and removed needs:history-cleanup To unblock: needs commit history cleanup/clarifying labels Oct 22, 2018
@simonmichael
Copy link
Owner

Status: keeping this PR open as the parent, but the code is superseded by #902 and #913.

@simonmichael simonmichael added needs:other-task To unblock: needs some other issue/task/event, possibly outside our project needs:testing To unblock: needs more developer testing or general usage and removed needs:discussion To unblock: needs more discussion/review/exploration labels Oct 30, 2018
@simonmichael
Copy link
Owner

Actually I'm going to close this, for clarity. We can always follow the links back. The "exact multi-commodity assertions" part has been merged as #902, and the "amount expressions and multi-commodity postings" part is still WIP, currently at #913.

@simonmichael simonmichael removed needs:other-task To unblock: needs some other issue/task/event, possibly outside our project needs:impact-analysis To unblock: needs analysis of interactions with other features, users, ecosystem needs:testing To unblock: needs more developer testing or general usage needs:value-proposition To unblock: needs clearer justification, review of benefits vs costs labels Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. journal The journal file format, and its features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants