Binary Logic
Truthiness
Every possible value in Rockstar evaluates to either true or false – this is known as truthiness. The only things in Rockstar which are falsy are:
false
null
mysterious
- the empty string
""
- the number
0
Everything else is truthy, which means if you put in in a Boolean context (such as the condition of an if
statement) it’ll be ‘true’.
Unary Not
Unary not in Rockstar uses the keywords not
and non-
:
Print not true (prints: false)
Print not false (prints: true)
Print non-true (prints: false)
Print non-non-non-non-non true (prints: false)
Print not 0 (prints: true)
Print not 1 (prints: false)
Print not "" (prints: true)
Print not "false" (prints: false)
Heinous is wrong!
Say Heinous (prints: false)
Bill is non heinous! Say Bill (prints: true)
Bill is non-non heinous! Say Bill (prints: false)
Bill is non-non-NON heinous! Say Bill (prints: true)
Binary Logic
Rockstar supports binary logic expressions using the keywords and
, or
, and nor
.
Print false nor false (prints: true)
Print true nor false (prints: false)
Print false nor true (prints: false)
Print true nor true (prints: false)
Print true and true (prints: true)
Print true and false (prints: false)
Print false and true (prints: false)
Print false and false (prints: false)
Print true or true (prints: true)
Print true or false (prints: true)
Print false or true (prints: true)
Print false or false (prints: false)
Print true and not true (prints: false)
Print true and not false (prints: true)
Print false or not true (prints: false)
Print false or not false (prints: true)
not
has the highest precedence, then and
, then or
, then nor
:
Print not true and true (prints: false)
Print not true or true (prints: true)
Print not false and false (prints: false)
Print not false or false (prints: true)
Print true and true or false (prints: true)
Print false and true or false (prints: false)
Print false and false or true (prints: true)
Print true or true and false (prints: true)
Print false nor false or false (prints: true)
Print false or false nor false (prints: true)
Print false nor false or true (prints: true)
Print true nor true or true (prints: true)
print true nor true and false (prints: false)
Binary Logic for Non-Boolean Types
Binary logic applied to strings and numbers in Rockstar doesn’t necessarily return a Boolean result: it returns whichever of the operands resolves the logical constraint of the expression:#
Print "one" or "two" (prints: one)
Print "hello" and 0 (prints: 0)
Print "foo" and "bar" (prints: bar)
Print false or "rock!" (prints: rock!)
Print 0 or null (prints: null)
Print true and "rock!" (prints: rock!)
The and
and or
operators in Rockstar will short-circuit:
X or Y
: evaluateX
. If the result is truthy, return it, otherwise evaluateY
and return that.- If
X
is truthy,Y
is never evaluated.
- If
X and Y
: evaluateX
. If the result is falsy, return it, otherwise evaluateY
and return that.- If
X
is falsy,Y
is never evaluated.
- If
In the following examples, short-circuiting means the division by zero is never evaluated:
Print true or 1/0 (prints: true)
Print false and 1/0 (prints: false)
Print true nor 1/0 (prints: false)
Equality and Comparison
Equality in Rockstar uses the is
, was
, are
and were
keywords. Equality is determined as follows:
- If one operand is a Boolean, compare it to the truthiness of the other operand:
- All non-zero numbers and non-empty strings are equal to
true
- Otherwise, if one operand is a string, compare it with the string representation of the other argument
- Otherwise, the values of the two operands are compared.
- All non-zero numbers and non-empty strings are equal to
Print 1 is 1 (prints: true)
Your memories are 1. My dreams are 1.
Say your memories are my dreams (prints: true)
It's with 3.
Say your memories are my dreams (prints: false)
Print "rock" is "roll" (prints: false)
Print 0 is true (prints: false)
Print 0 is false (prints: true)
Print 1 is true (prints: true)
Print 2 is true (prints: true)
Print 123 is "123" (prints: true)
Print "yeah!" is true (prints: true)
Inequality
Inequality uses the isn't
and ain't
keywords.
Watch out for
is not
:not
is the unary negation operator, soa is not b
will work as expected whenb
is a Boolean, but whenb
is a number or a string, it’ll comparea
with the logicalnot
of the truthiness ofb
Print 1 ain't 1 (prints: false)
Print 1 isn't 2 (prints: true)
Print 1 ain't 2 (prints: true)
Print false is not true (prints: true)
Print 1 is not 2 (prints: false)
Print "rock" ain't "roll" (prints: true)
Print 123 ain't "123" (prints: false)
Print "yeah!" is true (prints: true)
Strict Equality
To compare values without performing any type coercion, use the exactly
keyword, or its aliases really
, actually
or totally
:
Print 1 is 1 (prints: true)
Print 1 is "1" (prints: true)
Print 1 is totally "1" (prints: false)
Print "true" is true (prints: true)
Print "true" is totally true (prints: false)
Print 1 + 1 is totally 2 (prints: true)
Print 1 - 1 is false (prints: true)
Print 1 - 1 is really false (prints: false)
Print 1 + 2 is "3" (prints: true)
Print 1 + 2 is exactly "3" (prints: false)
Heinous is wrong
Bill is right
Say Bill is totally non-non-non-non-NON heinous (prints: true)
Comparison
Rockstar supports the following comparison operators:
is higher/greater/bigger/stronger than
to denote ‘greater than’is lower/less/smaller/weaker than
to denote ‘less than’is as high/great/big/strong as
to denote ‘greater than or equal to’is as low/little/small/weak as
to denote ‘less than or equal to’
By default, comparison use type coercion:
- If either operand is a string, it’s compared to the string representation of the other value
- This means that
10 < "2"
, because10
is coerced to the string10
, which is alphanumerically less than the string2
- This means that
- Otherwise, the numeric values of the operands are compared (
true
is1
,null
andfalse
are 0)
Say "a" is greater than "b" (prints: false)
Say "a" is greater than true (prints: false)
Say "z" is greater than true (prints: true)
Say true is greater than "a" (prints: true)
Say true is greater than "z" (prints: false)
Say "123" is greater than 456 (prints: false)
Say "789" is greater than 456 (prints: true)
Say "2" is greater than 10 (prints: true)
Say 10 is greater than "2" (prints: false)
Say 1 is as great as "1" (prints: true)
Say 1 is as great as 2 (prints: false)