x++ / Documents / Operators
Table of Contents
Catalog
A
C
D
E
F
G
I
J
L
M
N
P
R
S
T
U
V
W
About
Operators are keywords that process arguments.
A statement is a line of code that tells the interpreter what to do. They are always made up of two components: the operator
and the arguments
, and they are arranged like so:
<operator> [...arguments] [...?outputs]
For example:
prt "Hello, world!"
or:
add 1 2 ?sum
A statement can also be wrapped around parentheses (()
) to group them.
Some statements return values, which can be stored in a variable:
var sum (add 1 2)
Documentation
Add
add <addend A> <addend B> [?sum]
Adds two addends together or concatenates two strings together.
Parameter | Type | Optional | Description |
---|---|---|---|
Addend A | Float or Integer or String | The first addend | |
Addend B | Float or Integer or String | The second addend | |
Sum | Variable | ✓ | The sum of the two addend |
Returns: Float or Integer or String
Example:
add 5 10 ?sum
prt sum
Character
chr <string> <index> [stop] [?output]
Returns a substring of string
from index index
to stop
. If stop
is not provided, chr
will return the character at index
.
Parameter | Type | Optional | Description |
---|---|---|---|
String | String | The target string | |
Index | Integer | The index of the string | |
Stop | Integer | ✓ | The index of the string |
Output | Variable | ✓ | The resulting substring or character |
Returns: String
Example:
chr "Hello, world!" 3 5 ?output
chr "Hello, world!" 3 ?output2
prt output output2
:: "lo," "l"
Clear
cls
Clears the terminal.
Returns: Null
Example:
prt "Hello, world!"
cls
prt "Why hello there!"
Decrement
dec <value> <value_2> <...> [?output]
Decreases all given values by one.
If no output is given, the target value itself is decremented instead.
If output is specified, but multiple values are decremented. The result will be null.
Parameter | Type | Optional | Description |
---|---|---|---|
Value(s) | Float or Integer | The value that will be decremented | |
Output | Variable | ✓ | The decremented value |
Example:
var myInteger 5
dec myInteger
prt myInteger
:: 4
Divide
div <dividend> <divisor> <divisor_2> <...> [?quotient]
Divides the dividend by the divisor (in sequential order, if multiple given).
Parameter | Type | Optional | Description |
---|---|---|---|
Dividend | Float or Integer | The value that is being divided | |
Divisor(s) | Float or Integer | The value that is dividing the dividend | |
Quotient | Variable | ✓ | The quotient of the dividend and the divisor |
Example:
div 10 5 ?quotient
prt quotient
:: 2
Evaluate
evl <code>
Evaluate and execute Python code.
Parameter | Type | Optional | Description |
---|---|---|---|
Code | String | The Python code that is being evaluated |
Returns: Null
Example:
evl "print('Hello, world!')"
Exit
exit
Exits the process.
Returns: Null
Example:
prt "Hello, world!"
exit
prt "You'll never see me! Aha!"
Float
flt <string> <?output>
Converts a string into a float.
Output is not required, however the operator call will do nothing if no output is provided.
Parameter | Type | Optional | Description |
---|---|---|---|
String | String | The target string | |
Output | Variable | ✓ | The converted float value |
Returns: Float
Example:
flt "5" ?myFloat
prt myFloat
Get
get <object> <key> [?output]
Retrieves the specified key from the given object.
If object is a list, retrieve the value at index key
.
Parameter | Type | Optional | Description |
---|---|---|---|
Object | Dict | The source object | |
Key | Any | The key to retrieve | |
Output | Variable | ✓ | The retrieved value |
Returns: Any
Example:
flt "5" ?myFloat
prt myFloat
If
if <expr1> <branch1> [expr_n] [branch_n] [...] [else_branch]
Creates a branch based on whether or not the given expression(s) are true.
Parameter | Type | Optional | Description |
---|---|---|---|
Expression 1 | Expression | The first expression | |
Branch 1 | String | Statement to execute if first branch is true | |
Expression N | Expression | ✓ | The nth expression |
Branch N | String | ✓ | Statement to execute if nth branch is true |
Else Branch | String | ✓ | Statement to execute if all expressions were false |
Returns: Null
Example:
if (5 == 5) "jmp istrue" "jmp isfalse"
:istrue
prt "5 is equal to 5"
:isfalse
prt "5 is not equal to 5 somehow"
Import
imp <package/file/python file> [as <name>]
Imports a package, file, or Python script.
If no name is given, the package or file name is used instead. For example, imp "extras"
will require you to use jmp extras.section
; but imp "extras" as "hi"
will allow you to use jmp hi.section
instead.
If path
does not begin with ./
, the path will be assumed to be pkgs/<module>/<module>.xpp
if there isn't a .xconfig
file in the module directory stating another file to load.
Parameter | Type | Optional | Description |
---|---|---|---|
Package / File | String | The path of package or file you want to import | |
Name | String | ✓ | The name of the imported package of file |
Returns: Null
Example:
imp "myFile.xpp" as "myPackage"
Index
idx <string> <substring> [?output]
Converts a string into a float.
Parameter | Type | Optional | Description |
---|---|---|---|
String | String | The target string | |
Substring | String | The substring of the target string | |
Output | Variable | ✓ | The index of the substring in the target string |
Returns: Integer
Example:
idx "Hello, world!" "ello" ?output
prt output
:: 1
Increment
inc <value> <value_2> <...> [?output]
Increases all given values by one.
If no output is given, the target value itself is incremented instead.
If output is specified, but multiple values are incremented. The result will be null.
Parameter | Type | Optional | Description |
---|---|---|---|
Value(s) | Float or Integer | The value that will be incremented | |
Output | Variable | ✓ | The incremented value |
Example:
var myInteger 5
inc myInteger
prt myInteger
:: 6
Jump
jmp <section> [...arguments] [?output1] [?output_n] [?...]
Jumps to a section, provides it with arguments, and stores the output(s) in a variable (or multiple, depending on how many the section returns).
Parameter | Type | Optional | Description |
---|---|---|---|
Section | Section | The target section | |
...Arguments | ...Any | ✓ | The arguments passed to the target section |
...Outputs | Variable | ✓ | The output(s) of the section |
Returns: Any
Example:
:mySection a b
add a b ?sum
ret ?sum
jmp mySection 5 10 ?output
prt output
:: 15
Length
len <string> [?output]
Returns the length of the string.
Parameter | Type | Optional | Description |
---|---|---|---|
String | String | The target string | |
Output | Variable | ✓ | The length of the target string |
Returns: Integer
Example:
len "Hello, world!" ?output
prt output
:: 13
Load
load <path> <output>
Retrieves the content of a file.
Parameter | Type | Optional | Description |
---|---|---|---|
Path | String | The path of the file | |
Output | Variable | The content of the file |
Returns: String
Example:
In file.xpp
:
:mySection
prt "Hello, world!"
In main.xpp
:
load "file.xpp" ?output
prt output
:: :mySection
:: prt "Hello, world!"
Lowercase
lwr <string> [?output]
Lowercases all the characters in a string.
If no output is given, the target value itself is lowercased instead.
Returns: String
Example:
lwr "Hello, world!" ?output
prt output
:: hello, world!
Multiply
mul <factor_1> <factor_2> <factor_n> <...> [product]
Multiples all given factors together in sequential order.
Parameter | Type | Optional | Description |
---|---|---|---|
Factor 1 | Float or Integer or String | The first factor | |
Factor 2 | Float or Integer | The second factor | |
Factor N | Float or Integer | ✓ | The nth factor |
Product | Variable | ✓ | The product of the factors |
Returns: Float or Integer or String
Example:
mul 5 10 ?product
prt product
:: 50
New
new <type> [?output]
Creates a new object of the specified type, returning it.
Returns: List or Dict
Example:
new "list" ?list
prt list
:: []
Integer
int <string> [?output]
Converts a string into an integer.
If no output is given, the target string itself is converted instead.
Parameter | Type | Optional | Description |
---|---|---|---|
String | String | The target string | |
Output | Variable | ✓ | The converted number value |
Returns: Integer
Example:
int "5" ?myInteger
prt myInteger
:: 5
prt [...value]
Prints value(s) into the terminal.
Parameter | Type | Optional | Description |
---|---|---|---|
Value | Any | ✓ | The target value(s) |
Returns: Null
Example:
prt "Hello, world!"
Pop
pop <list> [?output]
Removes the last item from a list and returns it.
Parameter | Type | Optional | Description |
---|---|---|---|
List | List | The list to use | |
Output | Variable | ✓ | The last item |
Returns: Any
Example:
new "list" ?list
psh list 5
pop list ?result
prt result list
:: 5 []
Power
pow <exp_1> <exp_2> <exp_n> <...> [result]
Takes all given exponents and powers them together in sequential order.
Parameter | Type | Optional | Description |
---|---|---|---|
Exponent 1 | Float or Integer or String | The first exponent | |
Exponent 2 | Float or Integer | The second exponent | |
Exponent N | Float or Integer | ✓ | The nth exponent |
Result | Variable | ✓ | The result |
Example:
pow 2 2 ?result
prt result
:: 4
Push
psh <list> <value>
Pushes an item into a list's stack.
Parameter | Type | Optional | Description |
---|---|---|---|
List | List | The list to use | |
Value | Any | The item to push |
Returns: Null
Example:
new "list" ?list
psh list 5
prt list
:: [5]
Read
read [prompt] [?output]
Gets input from the user.
Parameter | Type | Optional | Description |
---|---|---|---|
Prompt | Any | ✓ | The prompt outputted in the terminal |
Output | Any | ✓ | The user input |
Returns: Null
Example:
read "What is your name: " ?name
prt name
Random Number Generator
rng <minimum> <maximum> [?output]
Generates a random integer within the range. Both the minimum and maximum values are inclusive.
Parameter | Type | Optional | Description |
---|---|---|---|
Minimum | Integer | The minimum range | |
Maximum | Integer | The maximum range | |
Output | Variable | ✓ | The randomized integer within the range |
Returns: Integer
Example:
rng 0 5 ?myInteger
prt myInteger
Remove
rem <variable>
Deletes a variable from memory.
Parameter | Type | Optional | Description |
---|---|---|---|
Variable | Variable | The target variable |
Returns: Null
Example:
var 5 myInteger
prt myInteger
rem myInteger
prt myInteger
Repeat
rep <amount> <statement>
Executes a statement a set amount of times.
Parameter | Type | Optional | Description |
---|---|---|---|
Amount | Integer | The amount of times the statement will be executed | |
Statement | String | The statement in string form that will be executed |
Returns: Null
Example:
rep 5 "prt 'Hello, world!'"
Return
ret [value_1] [value_2] [value_n] [...]
Returns a value within a section.
Parameter | Type | Optional | Description |
---|---|---|---|
Value | any | The return value |
Returns: Null
Example:
:mySection
ret 5
Round
rnd <number> [precision] [?output]
Rounds a number to a certain decimal point.
If no precision is given, it is rounded to the nearest whole number instead.
Parameter | Type | Optional | Description |
---|---|---|---|
Number | Float or Integer | The number to round | |
Precision | Integer | ✓ | The precision to round to |
Output | Integer | ✓ | The rounded number |
Example:
var myInteger 5.5
rnd myInteger
prt myInteger
:: 6
Save
save <path> <value> [encoding]
Writes the content into a file.
Parameter | Type | Optional | Description |
---|---|---|---|
Path | String | The path of the file | |
Value | String | The content of the file | |
Encoding | String | ✓ | The file encoding (utf8 is the default) |
Returns: Null
Example:
save "file.xpp" "Hello, world!" "utf8"
Set
set <dict> <key> <value>
Sets a key-value pair inside the given dictionary.
Parameter | Type | Optional | Description |
---|---|---|---|
Dict | Dict | The dict to update | |
Key | Any | The key to use | |
Value | Any | The value of the key |
Returns: Null
Example:
new "dict" ?dict
set dict "x" "Hello, world!"
prt (get dict "x")
:: Hello, world!
prt dict
:: { "x": "Hello, world!" }
String
str <value> [?output]
Converts a value into a string.
If no output is given, the target value itself is converted instead.
Parameter | Type | Optional | Description |
---|---|---|---|
Value | Any | The target string | |
Output | Variable | ✓ | The converted string value |
Returns: String
Example:
str 5 ?myString
prt myString
:: "5"
Subtract
sub <term_1> <term_2> <term_n> <...> [?result]
Subtracts all given terms from eachother in order.
Parameter | Type | Optional | Description |
---|---|---|---|
Term 1 | Float or Integer | The first value | |
Term 2 | Float or Integer | The second value | |
Term N | Float or Integer | ✓ | The nth value |
Result | Variable | ✓ | The difference of all given terms |
Example:
sub 10 5 ?difference
prt difference
:: 5
Throw
thrw [message]
Throws an error message and exits the process.
Parameter | Type | Optional | Description |
---|---|---|---|
Message | Any | ✓ | The message of the error |
Returns: Null
Example:
prt "Hello, world!"
thrw "Error message!"
prt "Haha! Can't see me!"
Try
try <statement> [error statement]
Executes the statement. If an error is thrown, the exception statement is executed instead.
Parameter | Type | Optional | Description |
---|---|---|---|
Statement | String | The statement in string form that will be executed | |
Error Statement | String | ✓ | The statement in string form that will be executed if an error is thrown |
Returns: Null
Example:
try "thrw 'Error message!'" "prt 'An error has occurred'"
:: An error has occured
Uppercase
upr <string> [?output]
Uppercases all the characters in a string.
If no output is given, the target value itself is uppercased instead.
Returns: String
Example:
upr "Hello, world!" ?output
prt output
Wait
wait <seconds>
Waits a certain number of seconds before executing the next statement.
Parameter | Type | Optional | Description |
---|---|---|---|
Seconds | Integer | The number of seconds to wait |
Returns: Null
Example:
prt "Hello, world!"
wait 5
prt "Hello, world!"
While
whl <expression> <statement>
Executes the statement until the expression is false.
Parameter | Type | Optional | Description |
---|---|---|---|
Expression | Expression | The target expression | |
Statement | String | The statement in string form that will be executed while the expression is true |
Returns: Null
Example:
:mySection a
out a
inc a
ret a
var myInteger 0
whl (myInteger < 5) "jmp mySection myInteger ?myInteger"
:: 0
:: 1
:: 2
:: 3
:: 4
Variable
var <value> <variable>
Defines a variable.
Parameter | Type | Optional | Description |
---|---|---|---|
Value | Any | The value that will be stored in the variable | |
Variable | Variable | The target variable |
Returns: Null
Example:
var 5 myInteger
prt myInteger
Last Updated: March 9th, 2024 by iiPython