Trait in prelude::ops auto-imported

Sub

trait Sub<T>
Source: compiler/src/builtin_docs/prelude/ops.hy

The subtraction operator -.

a - b on a type with a Sub instance calls sub(a, b). int and float have builtin instances.

Required methods#

NameDescription
subReturns a - b.

Examples#

use tests::assert;
class V2 {
    pub x: int,
    pub y: int,
}

impl Sub for V2 {
    pub fn sub(V2 a, V2 b) -> V2 {
        return new V2(a.x - b.x, a.y - b.y);
    }
}

fn main() {
    let d = new V2(5, 5) - new V2(1, 2);
    assert!(d.x == 4);
    assert!(d.y == 3);
}

See also#

  • int
  • float
  • Add: The addition operator +.
  • Mul: The multiplication operator *.
  • Div: The division operator /.
  • Neg: The unary negation operator -x.
  • Rem: The remainder operator %.
  • Pow: The exponentiation operator **.
↑ ↓ navigate ↵ open