Put spaces around symbolic operators.
total = left + right
count += 1
Moth uses words for equality and logic:
same = left is right
different = left is not right
ready = loaded and valid
retry = timed_out or disconnected
blocked = not ready
Division has two forms:
real_result = 5 / 2
whole_result = 5 // 2
/ produces a real Float result. // performs integer division and produces an Int.
Use templates to join text:
greeting = ["Hello, ", "Priya"]
Templates handle all string joining and interpolation. + is for numbers only.
Moth keeps equality and logical operators readable.
same = left is right
different = left is not right
ready = has_input and is_valid
should_retry = timed_out or disconnected
blocked = not ready
and and or require Bool operands.not requires one Bool operand.- Symbolic equality and symbolic logical-not forms are not language operators.
Arithmetic results
Int, Int with +, -, *, %, ^, // produces IntInt, Int with / produces FloatFloat, Float with +, -, *, /, %, ^ produces Float- mixed
Int and Float with +, -, *, /, %, ^ produces Float
// is integer division and is valid only for two Int operands.
Comparisons
Int and Float support equality and ordering, including mixed numeric comparisons.Char supports equality and ordering.Bool supports equality only.String supports is and is not. It does not support ordering operators.- Choices and options have additional equality rules in their own references.
+ is a numeric operator only. Source string concatenation uses templates. See Strings and characters for the canonical concatenation form.
Precedence and associativity
From highest to lowest:
- level 6: unary
not, unary - - level 5:
^ - level 4:
*, /, //, % - level 3:
+, - - level 2:
is, is not, <, <=, >, >= - level 1:
and - level 0:
or
^ is right-associative. Other binary operators are left-associative.
Parentheses override normal precedence.
Spacing
Symbolic binary operators require spaces on both sides. Assignment = follows the same outer-spacing rule, but it is not a binary operator.
total = left + right
count = 1
These forms are invalid:
total=left+right
count=1
Compound assignments follow the same rule:
count += 1
count //= 2
count+=1, count +=1 and count+= 1 are invalid.
The mutable declaration spelling ~= stays adjacent. It needs whitespace before ~ and after =:
count ~= 1
count~= 1, count ~=1 and count ~ = 1 are invalid.
Operator overloading is outside Moth's language design. Operators remain compiler-owned and predictable.