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

Separate multiplier from Amount #913

Closed
wants to merge 1 commit into from

Conversation

ag-eitilt
Copy link
Contributor

In one of the several discussions in #871, @simonmichael said:

I'd rather enforce that the multiplier is a commodityless number for now. Quietly discarding information from one side of an expression is something we should avoid.

This then is that enforcement. However, as there are indeed some tests relying on the old behaviour (misc/rewrite.test:3 and :4), we likely need input from others on whether this is the direction to go ---in which case I'll finish the polish of this, including docs--- or whether we do want to allow changing the commodity ---and whether we want to make the syntax more explicit so information isn't discarded accidently.

@ag-eitilt ag-eitilt force-pushed the separate-multiplier branch 2 times, most recently from be1b413 to 818290c Compare October 19, 2018 21:09
@simonmichael simonmichael added needs:discussion To unblock: needs more discussion/review/exploration needs:review To unblock: needs more code/docs/design review by someone labels Oct 22, 2018
@simonmichael
Copy link
Owner

@ag-eitilt now I see what you were saying: auto-generated postings do allow replacing the matched amount's commodity, as seen in rewrite.test. I've added more tests in tests/print/auto.tests describing this (f583301).

I agree with you that this can be useful in auto posting rules, and we should still allow it there for now (and ensure adequate docs). This (prefix) star in auto posting rules is different from the (infix) star in the proposed new amount expressions, currently at least.

I still think the latter (amount expressions) should not allow mixed-commodity multiplication/division, but I could reconsider that if we find compelling use cases.

@simonmichael simonmichael removed the needs:review To unblock: needs more code/docs/design review by someone label Oct 22, 2018
@simonmichael
Copy link
Owner

PS if you work more on this PR, let's replace the commits with a new one based on latest master.

@simonmichael simonmichael added needs:changes To unblock: needs some changes made, in line with recommendations and removed needs:discussion To unblock: needs more discussion/review/exploration labels Oct 30, 2018
@simonmichael
Copy link
Owner

Checking in. IIRC the status of this is needs changes, ie we want to disallow overriding the left hand commodity in general amount expressions, but not in transaction modifier posting amount rules.

@simonmichael
Copy link
Owner

Also:

  • needs rebase against master
  • this seems to be just a small refactoring step which I think needs a little more motivation, we could enlarge this PR a bit (eg add the amount expressions), or start a new one if easier.

@sorsasampo
Copy link

@simonmichael I think it would be nice if there was a separate issue for expression amounts that people could subscribe to.

I followed #183 / #923 -> #871 comments here.

@simonmichael
Copy link
Owner

@sorsampo: reopened #183

@ag-eitilt ag-eitilt force-pushed the separate-multiplier branch 2 times, most recently from d572254 to 603918b Compare November 16, 2018 21:34
@ag-eitilt
Copy link
Contributor Author

Finally got back to this; sorry it took so long! Anyway, as you noted, the previous status was simply more or less a request for comment (and should probably have been named as such). This now is where I'd consider it motivated; for the PR reviewers, the major change is:

  • Prevent standard transactions from using the transaction modifier multiplier syntax: (b) *2

In service of that, it also introduces the minor changes of:

  • Amount no longer has the field amultiplier; instead, that role is moved to Posting as the new field pmultiplier
  • multiplierp (previously internal to Hledger.Read.Common, simply checking the next character was *) now instead reads a complete Amount preceded by a *, and is exported
  • Some parse functions internal to their modules (amountwithoutpricep, postingsp, and postingp) have an additional Bool parameter indicating whether they've been called as part of a transaction modifier/posting multiplier

This hasn't yet been added to the docs; for now, your TODO in Hledger.Data.TransactionModifier should still work as a reminder until one or the other of us (probably me) gets around to writing it up.

@simonmichael simonmichael added needs:review To unblock: needs more code/docs/design review by someone needs:docs To unblock: needs corresponding documentation or doc updates and removed needs:changes To unblock: needs some changes made, in line with recommendations labels Nov 16, 2018
@simonmichael
Copy link
Owner

Thanks! Please add the docs changes when you get the chance.

@@ -47,7 +47,7 @@ import Hledger.Utils.Debug
-- 0000/01/01
Copy link
Owner

Choose a reason for hiding this comment

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

"Restore ability..." - makes me wonder when they lost that ability. Was it in the previous commit, & so should this be merged with that ? Or was it an older one we already merged ?

@ag-eitilt
Copy link
Contributor Author

ag-eitilt commented Nov 20, 2018 via email

This does break journals with standard transactions including
multipliers (shouldn't be used in reality).
@simonmichael
Copy link
Owner

Sorry @ag-eitilt, but I'm confused. Is this PR intended to be merged ? I thought it was.

@simonmichael
Copy link
Owner

I've reread the original description, but I don't remember enough context to be clear. You mentioned doc changes - if those are appropriate, please add them to the PR, that will help me understand.

@simonmichael
Copy link
Owner

And now I've reread the new description. This makes it sound like (and the the commit looks) like an internal refactoring that shouldn't affect anything users have been doing up to this point. Is that accurate ?

@@ -256,6 +254,7 @@ data Posting = Posting {
pcomment :: Text, -- ^ this posting's comment lines, as a single non-indented multi-line string
ptype :: PostingType,
ptags :: [Tag], -- ^ tag names and values, extracted from the comment
pmultiplier :: Maybe Amount, -- ^ optional: the proportion of the base value to use in a 'TransactionModifier'
Copy link
Owner

Choose a reason for hiding this comment

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

Old way: the amultiplier boolean flag turns a standard Amount into something else (a transaction modifier posting's amount-or-amount-multiplier). New way: the pmultipler amount turns a standard posting into something else (a transaction modifier posting with amount or amount multiplier).

I agree the old way is inelegant. Is the new way better ? It seems to me "even more wrong" semantically. Eg now you could have a Posting with both a multipler amount and a regular amount, which has no connection to the journal syntax.

@ag-eitilt
Copy link
Contributor Author

ag-eitilt commented Nov 20, 2018 via email

@simonmichael
Copy link
Owner

I see that

2018/1/1
  (a)   *$1

is parsed successfully by hledger (eg 1.10, 1.11) as you say. The star seems to be just ignored, and it doesn't seem like a bug anybody would have hit. Good catch, but it probably isn't something that needs to be mentioned in docs. (Release notes maybe).

@ag-eitilt
Copy link
Contributor Author

ag-eitilt commented Nov 20, 2018 via email

@simonmichael
Copy link
Owner

simonmichael commented Nov 20, 2018 via email

@simonmichael simonmichael added needs:changes To unblock: needs some changes made, in line with recommendations and removed needs:docs To unblock: needs corresponding documentation or doc updates needs:review To unblock: needs more code/docs/design review by someone labels Dec 4, 2018
@ag-eitilt
Copy link
Contributor Author

Closed in favor of #934.

@ag-eitilt ag-eitilt closed this Dec 7, 2018
@simonmichael simonmichael removed the needs:changes To unblock: needs some changes made, in line with recommendations label Feb 13, 2019
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.

3 participants