type.arithmetic_operand
A sum, difference or division mixes two different named types, or uses a value that isn't a number.
Area 3, Logic; not declinable; the next step is usually the agent's.
Why Jadpo refuses it
A named type such as Stock or Quantity is a unit. Multiplying a pack
size by a number of packs means something, so * may mix types. Adding
them doesn't: the sum of a stock level and a quantity is neither, and
usually means the code reads the wrong value. So + and - need the same
named type on both sides, or a literal, and / needs the same type too.
What it looks like
main.jadpo:
type Stock = Int { min: 0}type Quantity = Int { min: 1}function wrong_total(per_pack: Stock, packs: Quantity) -> Stock { return Stock(per_pack + packs)}
error Stock and Quantity can't be added
--> main.jadpo:10:18
|10 | return Stock(per_pack + packs) | ^^^^^^^^^^^^^^^^ different types
- reason
+and-need the same named type on both sides, or a literal, becauseStockandQuantityare different units;*and%may mix types.- next
- Use two values of the same type (agent)
- rule
- type.
arithmetic_ operand - help
- https://jadpo.
dev/docs/errors/type. arithmetic_ operand
(agent) at the end of the next: line means your coding agent can make
the fix itself.
Dividing one named type by another is the same error. / divides two
values of one type, and dropping the remainder is only one way to round:
main.jadpo:
type Stock = Int { min: 0}type Boxes = Int { min: 1}function per_box(items: Stock, boxes: Boxes) -> Stock { return Stock(items / boxes)}
error Stock and Boxes can't be divided
--> main.jadpo:10:18
|10 | return Stock(items / boxes) | ^^^^^^^^^^^^^ different types
- reason
/divides two values of the same named type; dividingStockbyBoxes, or rounding another way, isinteger.divideordecimal.divide.- next
- Divide with
integer.divideordecimal.divide(agent) - rule
- type.
arithmetic_ operand - help
- https://jadpo.
dev/docs/errors/type. arithmetic_ operand
A value that may be none is the error too, since none has no number.
Its next: line says to match on the value and use it inside
some(...), as in type.ordering_operand.
How to fix it
The question is what the code means to work out.
If the two values are the same unit, build one side as the other's type with its constructor, so both sides match:
return Stock(per_pack + Stock(packs))Stock(packs) checks the quantity against Stock's rules. A quantity is
at least 1, so it is always a valid Stock, and building it can't fail.
If you meant the stock for that many packs, multiply, which may mix types:
return Stock(per_pack * packs)The result is the pack size times the number of packs.
If you are dividing two different types, use integer.divide, or
decimal.divide for decimals, and name how to round:
return Stock(integer.divide(items, boxes, rounding: Rounding.down))Rounding.down drops the remainder, rounding toward zero.
Rounding.half_even, half_up and up round the other ways
(Numbers).
Related
Markdown for agents: /docs/errors/type.arithmetic_operand.md.Built from Jadpo main at aee2e8f.