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.

ParameterTypeOptionalDescription
Addend AFloat or Integer or StringThe first addend
Addend BFloat or Integer or StringThe second addend
SumVariableThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
IndexIntegerThe index of the string
StopIntegerThe index of the string
OutputVariableThe 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.

ParameterTypeOptionalDescription
Value(s)Float or IntegerThe value that will be decremented
OutputVariableThe decremented value

Returns: Float or Integer

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).

ParameterTypeOptionalDescription
DividendFloat or IntegerThe value that is being divided
Divisor(s)Float or IntegerThe value that is dividing the dividend
QuotientVariableThe quotient of the dividend and the divisor

Returns: Float or Integer

Example:

div 10 5 ?quotient
prt quotient
:: 2

Evaluate

evl <code>

Evaluate and execute Python code.

ParameterTypeOptionalDescription
CodeStringThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
OutputVariableThe 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.

ParameterTypeOptionalDescription
ObjectDictThe source object
KeyAnyThe key to retrieve
OutputVariableThe 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.

ParameterTypeOptionalDescription
Expression 1ExpressionThe first expression
Branch 1StringStatement to execute if first branch is true
Expression NExpressionThe nth expression
Branch NStringStatement to execute if nth branch is true
Else BranchStringStatement 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.

ParameterTypeOptionalDescription
Package / FileStringThe path of package or file you want to import
NameStringThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
SubstringStringThe substring of the target string
OutputVariableThe 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.

ParameterTypeOptionalDescription
Value(s)Float or IntegerThe value that will be incremented
OutputVariableThe incremented value

Returns: Float or Integer

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).

ParameterTypeOptionalDescription
SectionSectionThe target section
...Arguments...AnyThe arguments passed to the target section
...OutputsVariableThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
OutputVariableThe 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.

ParameterTypeOptionalDescription
PathStringThe path of the file
OutputVariableThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
OutputVariableThe lowercased string

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.

ParameterTypeOptionalDescription
Factor 1Float or Integer or StringThe first factor
Factor 2Float or IntegerThe second factor
Factor NFloat or IntegerThe nth factor
ProductVariableThe 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.

ParameterTypeOptionalDescription
TypeString'list' or 'dict'
OutputVariableThe new object

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.

ParameterTypeOptionalDescription
StringStringThe target string
OutputVariableThe converted number value

Returns: Integer

Example:

int "5" ?myInteger
prt myInteger
:: 5

Print

prt [...value]

Prints value(s) into the terminal.

ParameterTypeOptionalDescription
ValueAnyThe target value(s)

Returns: Null

Example:

prt "Hello, world!"

Pop

pop <list> [?output]

Removes the last item from a list and returns it.

ParameterTypeOptionalDescription
ListListThe list to use
OutputVariableThe 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.

ParameterTypeOptionalDescription
Exponent 1Float or Integer or StringThe first exponent
Exponent 2Float or IntegerThe second exponent
Exponent NFloat or IntegerThe nth exponent
ResultVariableThe result

Returns: Float or Integer

Example:

pow 2 2 ?result
prt result
:: 4

Push

psh <list> <value>

Pushes an item into a list's stack.

ParameterTypeOptionalDescription
ListListThe list to use
ValueAnyThe item to push

Returns: Null

Example:

new "list" ?list
psh list 5
prt list
:: [5]

Read

read [prompt] [?output]

Gets input from the user.

ParameterTypeOptionalDescription
PromptAnyThe prompt outputted in the terminal
OutputAnyThe 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.

ParameterTypeOptionalDescription
MinimumIntegerThe minimum range
MaximumIntegerThe maximum range
OutputVariableThe randomized integer within the range

Returns: Integer

Example:

rng 0 5 ?myInteger
prt myInteger

Remove

rem <variable>

Deletes a variable from memory.

ParameterTypeOptionalDescription
VariableVariableThe 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.

ParameterTypeOptionalDescription
AmountIntegerThe amount of times the statement will be executed
StatementStringThe 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.

ParameterTypeOptionalDescription
ValueanyThe 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.

ParameterTypeOptionalDescription
NumberFloat or IntegerThe number to round
PrecisionIntegerThe precision to round to
OutputIntegerThe rounded number

Returns: Float or Integer

Example:

var myInteger 5.5
rnd myInteger
prt myInteger
:: 6

Save

save <path> <value> [encoding]

Writes the content into a file.

ParameterTypeOptionalDescription
PathStringThe path of the file
ValueStringThe content of the file
EncodingStringThe 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.

ParameterTypeOptionalDescription
DictDictThe dict to update
KeyAnyThe key to use
ValueAnyThe 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.

ParameterTypeOptionalDescription
ValueAnyThe target string
OutputVariableThe 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.

ParameterTypeOptionalDescription
Term 1Float or IntegerThe first value
Term 2Float or IntegerThe second value
Term NFloat or IntegerThe nth value
ResultVariableThe difference of all given terms

Returns: Float or Integer

Example:

sub 10 5 ?difference
prt difference
:: 5

Throw

thrw [message]

Throws an error message and exits the process.

ParameterTypeOptionalDescription
MessageAnyThe 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.

ParameterTypeOptionalDescription
StatementStringThe statement in string form that will be executed
Error StatementStringThe 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.

ParameterTypeOptionalDescription
StringStringThe target string
OutputVariableThe uppercased string

Returns: String

Example:

upr "Hello, world!" ?output
prt output

Wait

wait <seconds>

Waits a certain number of seconds before executing the next statement.

ParameterTypeOptionalDescription
SecondsIntegerThe 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.

ParameterTypeOptionalDescription
ExpressionExpressionThe target expression
StatementStringThe 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.

ParameterTypeOptionalDescription
ValueAnyThe value that will be stored in the variable
VariableVariableThe target variable

Returns: Null

Example:

var 5 myInteger
prt myInteger

Last Updated: March 9th, 2024 by iiPython

↑ Go To Top