7 / 2 = 3.5 everywhere — say idiv when you mean the integer quotient
Pitfall 19 of writing Soma, the programming language: a habit from another language, or a rule that surprises, with what the Soma compiler answers and the form to write.
/ on two Ints is 3.5 (an Int only when exact) in the interpreter AND in [native] handlers. Native code is statically typed, so where the quotient must be an Int it is checked instead of truncated:
on mid(lo: Int, hi: Int) [native] {
let m = lo
m = (lo + hi) / 2 // m is an Int slot
return m
}
// mid(1, 2) → error: Int / Int is not exact here, and this spot can only
// hold an Int (7 / 2 is 3.5) — write idiv(a, b) ...on mid(lo: Int, hi: Int) [native] { return idiv(lo + hi, 2) } // 1, everywheresoma check warns on Int / Int in native handlers; soma fix f.cell --native-idiv rewrites them (for code written when native / truncated). A [native] division by zero is an ordinary, try-catchable runtime error.