Operator Methods

From Adam Colton
Revision as of 17:27, 17 September 2019 by Adamcolton (talk | contribs) (Created page with "Types can have operator methods. Operators always follow the same precedence and must be immutable. Operators * Add (+Add) * Positive (+Positive) * Concat (+Concat) * Subtrac...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Types can have operator methods. Operators always follow the same precedence and must be immutable.

Operators

  • Add (+Add)
  • Positive (+Positive)
  • Concat (+Concat)
  • Subtract (-Sub)
  • Negate (-Neg)
  • Index ([])
  • logical/bitwise (and, or, not, xor, nor)
  • bit (<< >>)

One type cannot define both Concat and Add/Positive.

I'm not sure about type enforcement. It would be clean to say that both inputs to an operator must be the same time (what V does). But that doesn't always work, for instance, you can't add two points. So it might make more sense to have Mathematical compliance. So you must have the following consistency

  • A+B=C
  • B=C-A
  • A=C-B

And probably more into multiplication and exponentiation.

For many of these types, function can return two values. For instance on +, the second value is an ok that will return false if the addition overflowed the type.