Difference between revisions of "Operators"

From MiniScript Wiki
Jump to navigation Jump to search
m
(About chained comparison)
Line 45: Line 45:
 
| A<c>.</c>B || [[Dot syntax|dot operator]]
 
| A<c>.</c>B || [[Dot syntax|dot operator]]
 
|}
 
|}
 +
 +
== Chained comparison ==
 +
 +
Operators <c>></c>, <c><</c>, <c>>=</c> and <c><=</c> support chaining:
 +
 +
<ms>
 +
x = 42
 +
if 13 < x <= 100 then  // same as if (13 < x) and (x <= 100) ...
 +
print "foo"
 +
end if
 +
</ms>
  
 
[[Category:Language]]
 
[[Category:Language]]

Revision as of 15:57, 5 October 2023

MiniScript defines the following operators (listed in order from lowest to highest precedence):

Operator Meaning
A = B assignment
A or B logical OR: true if either operand is true
A and B logical AND: true if both operands are true
not A logical negation: true if its operand is false, and vice versa
A isa B type checking
A == B equality comparison: true if operands are equal
A != B inequality comparison: true if operands are not equal
A > B greater-than comparison
A < B less-than comparison
A >= B greater-than or equal-to comparison
A <= B less-than or equal-to comparison
A + B addition or concatenation
A - B subtraction or string trimming
A * B multiplication or replication
A / B division or reduction
-A unary minus (numeric negation)
new A instantiation
@A address-of (reference function without invoking it)
A ^ B power: A raised to the power of B
A.B dot operator

Chained comparison

Operators >, <, >= and <= support chaining:

x = 42
if 13 < x <= 100 then  // same as if (13 < x) and (x <= 100) ...
	print "foo"
end if