Special syntax for increase_by/decrease_by percentage-calculation functions
Now that the increase_by / decrease_by percentage-calculation functions have been added, it would be great to have an easy and quick syntax to do those kinds of calculations. The following syntax was proposed in the discussion of #494:
1000 -% 20
1000 +% 20
Seeing as syntax like 72 € - 15% can't be supported, the proposed syntax (above) is the next best thing, and has the advantage of being quick to type and easier to remember.
So, instead of 72 € - 15%, we would use: 72 € -% 15
Maybe I'm being unnecessarily picky but I think it is not ideal that the proposed operator dictates the unit of the second operand, in my opinion the new "increase-by" and "decrease-by" operators should work for any scalar second operand.
So 1000 <decrease-by> 20%, 1000 <decrease-by> 0.2, 1000 <decrease-by> 200‰ should all result in 800.
So
1000 <decrease-by> 20%,1000 <decrease-by> 0.2,1000 <decrease-by> 200‰should all result in800.
I think the operator notation is fine but I agree it should work the way you describe here.
Would syntax for percent_change maybe be useful too? I’m thinking something like >% and <% to denote the order of arguments. This way the problem: "how many percent increase is 50 kg to 75 kg?"
Could be written as:
50 kg >% 75 kg
I’m not quite sure if the greater than less than characters are ideal, but I think the concept might be useful.
Maybe I'm being unnecessarily picky but I think it is not ideal that the proposed operator dictates the unit of the second operand, in my opinion the new "increase-by" and "decrease-by" operators should work for any scalar second operand.
Oh yes, definitely.
So
1000 <decrease-by> 20%,1000 <decrease-by> 0.2,1000 <decrease-by> 200‰should all result in800.
Yes.
The only question is, would -% be a confusing syntax, as it suggests the right hand side would have to be a percentage? If so, what would be some alternatives?
Somewhat related: I think it would be nice if Numbat had a set of binary (any maybe unary) operators that the user would have available for their own use. Similar to how this works in Haskell-style languages:
fn append(lhs, rhs) = …
infixr 5 append as <>