ErrorsStandard library · rule
syntax.percent_ambiguous
A number, % and a value with no spaces could be a percentage or a remainder.
Area 19, Standard library; not declinable; the next step is usually the agent's.
A number touching % is a percentage, 20%, and the remainder (area 3)
is written with spaces, 20 % 3, as the formatter writes every binary
operator. With a number or a name touching the % on both sides, either
could be meant, so neither is guessed.
type BoxCount = Int {}/// The cakes left over when twenty are packed in boxes of three.function twenty_in_threes() -> BoxCount { return BoxCount(20%3)}
error 20%3 could be 20% 3 or 20 % 3
--> main.jadpo:5:21
|5 | return BoxCount(20%3) | ^^^^ a percentage or a remainder
- reason
- A number touching
%is a percentage,20%, and the remainder is written with spaces,20 % 3, as the formatter writes every binary operator; with3touching the%too, either could be meant. - next
- Write
20 % 3for the remainder, or put the percentage20%apart from what follows it (agent) - rule
- syntax.
percent_ ambiguous - help
- https://jadpo.
dev/docs/errors/syntax. percent_ ambiguous
Adding a percentage to money doesn't compile either, by area 3's
type.arithmetic_operand, since it could mean the price raised by a
fifth or a fifth of something else; the fix writes both:
type CakePrice = Money { currency: Currency.gbp}/// A cake's price with VAT added.function with_vat(price: CakePrice) -> CakePrice { return CakePrice(price + 20%)}
error CakePrice and a percentage can't be added: it could mean two things
--> main.jadpo:7:22
|7 | return CakePrice(price + 20%) | ^^^^^^^^^^^ an amount and a percentage
- reason
price + 20%could mean the amount raised by 20% of itself, or 20% of some other amount; the standard operator table refuses it rather than guess. A percentage scales money by*.- next
- Write
price * 120%, orprice + price * 20%, whichever is meant (agent) - rule
- type.
arithmetic_ operand - help
- https://jadpo.
dev/docs/errors/type. arithmetic_ operand
Markdown for agents: /docs/errors/syntax.percent_ambiguous.md.Built from Jadpo main at aee2e8f.