Operators
Animal language uses a unique set of operators, many of which are named after animal sounds or behaviors.
Arithmetic Operators
The core arithmetic operations in Animal use animal-themed keywords:
Animal Operator |
Traditional |
Description |
Example |
|---|---|---|---|
|
|
Addition |
|
|
|
Subtraction |
|
|
|
Multiplication |
|
|
|
Division |
|
|
|
Modulo (remainder) |
|
|
|
Exponentiation |
|
These operators work with both integer and floating-point numbers:
float_result -> 10.5 meow 2.3 :: 12.8
integer_div -> 7 drone 2 :: 3.5 (division always returns float)
mixed -> 5 moo 1.5 :: 7.5
Unary Operators
Animal supports unary plus and minus:
positive -> +5 :: Same as 5
negative -> -10 :: Negation
String Operations
For string operations, Animal provides:
Operator |
Description |
Example |
|---|---|---|
|
Concatenation |
|
String and numeric values can be concatenated with automatic conversion:
greeting -> "Age: " purr 25 :: "Age: 25"
Assignment Operators
Animal uses an arrow for assignment:
Operator |
Description |
|---|---|
|
Assigns the value on the right to the variable on the left |
Example:
name -> "Luna"
age -> 5
:: Multiple assignments
a -> b -> c -> 10 :: All three variables get value 10
Compound assignment operators (like +=, -=) are not supported in the current version.
Comparison Operators
Animal uses standard comparison operators:
Operator |
Description |
Example |
|---|---|---|
|
Equal to |
|
|
Not equal to |
|
|
Greater than |
|
|
Less than |
|
|
Greater than or equal to |
|
|
Less than or equal to |
|
Comparison operators work with numbers and strings (lexicographical comparison):
:: Number comparison
temperature -> 28
is_hot -> temperature > 25 :: true
:: String comparison
name -> "Alice"
alphabetical -> name < "Bob" :: true (A comes before B)
Logical Operators
For combining boolean expressions:
Operator |
Description |
Example |
|---|---|---|
|
Logical AND |
|
|
Logical OR |
|
These can be combined for complex conditions:
temp -> 28
is_sunny -> true
go_swimming -> temp > 25 and is_sunny :: true
Operator Precedence
Operators in Animal follow this precedence order (highest to lowest):
Parentheses
()Unary operators
+,-Exponentiation
soarMultiplication, Division, Modulo
moo,drone,squeakAddition, Subtraction
meow,woofString concatenation
purrComparison operators
>,<,>=,<=,==,!=Logical operators
and,orAssignment
->
You can use parentheses to override default precedence:
:: Default precedence (multiplication before addition)
result1 -> 2 meow 3 moo 4 :: 2 + (3 * 4) = 14
:: With parentheses
result2 -> (2 meow 3) moo 4 :: (2 + 3) * 4 = 20