Logical Operations
Learn how to use logical operations in your programs.
Reference
| Name | Operation | Description | |
| Equals | = | ( a b — c ) | Pops the last 2 items from the stack and pushes true if they are equal, or false otherwise. Works with both numbers and strings. |
| Less Than | < | ( a b — c ) | Pops the last 2 numbers from the stack and pushes true if the first is less than the second, or false otherwise. |
| Greater Than | > | ( a b — c ) | Pops the last 2 numbers from the stack and pushes true if the first is greater than the second, or false otherwise. |
| Greater Than or Equal To | >= | ( a b — c ) | Pops the last 2 numbers from the stack and pushes true if the first is greater than or equal to the second, or false otherwise. |
| Less Than or Equal To | <= | ( a b — c ) | Pops the last 2 numbers from the stack and pushes true if the first is less than or equal to the second, or false otherwise. |
| Not Equals | != | ( a b — c ) | Pops the last 2 items from the stack and pushes true if they are not equal, or false otherwise. Works with both numbers and strings. |
| Is Nil | ? | ( a — c ) | Pops the last item on the stack and pushes true if the item in question is nil, otherwise false. |
Usage
Use logical operations to evaluate conditions in your programs. Here are a few examples:
# Checking equality between numbers
10 10 = # The stack now contains: 1
# Comparing strings
"hello" "world" != # The stack now contains: 1
# Using greater than comparison
15 10 > # The stack now contains `true`