Specification

August 14, 2021 · View on GitHub

Operators

This table presents all operators available in Pyxell, sorted by precedence, from highest to lowest. Operators in the same row have equal precedence.

OperatorsDescriptionArityAssociativity
., ?.attribute accessbinaryleft
[], ?[]element accessbinaryleft
()function callmultiaryleft
!non-null assertionunaryleft
^, ^^exponentiation, integer exponentiationbinaryright
+, -unary plus and minusunaryright
/divisionbinaryleft
//, %, *, &floor division, modulo, multiplication, set intersectionbinaryleft
+, -addition, subtractionbinaryleft
%%divisibilitybinaryleft
??null coalescingbinaryleft
.., ...inclusive and exclusive rangebinaryleft
...infinite rangeunaryleft
byiteration stepbinaryleft
...spreadunaryright
==, !=, <, <=, >, >=comparisons (chainable)binaryright
notlogical negationbinaryright
andlogical conjunction (short-circuiting)binaryright
orlogical disjunction (short-circuiting)binaryright
? :conditional operatorternaryright

Associativity of unary operators determines on which side the expression should be, e.g.: a! (left), -a (right).

Types

This section describes all data types available in Pyxell, together with their properties and methods.

Fundamental types

Type nameDescriptionExample valueDefault value
Voidno value (for functions returning nothing)
Int64-bit signed integer number420
Ratarbitrary-precision rational number1.50r
Floatdouble-precision floating-point number3.14f0f
Boolboolean valuetruefalse
Charsingle-byte character'A''\0'
Stringarbitrary-length string of characters"example"""

Compound types

Type name patternsDescriptionExample valuesDefault value
[Type]array[1, 2][]
{Type}set{"abc", ""}{}
{Key:Value}dictionary{'x': false}{:}
Type?nullable valuenullnull
Type1*Type2tupletrue, 4.6tuple of default values
Type...generator objectempty sequence
Arg1->Arg2->Result, ()->Resultfunction_+_, lambda: 0function returning the default value
custom class nameclass objectnone (uninitialized object is invalid)

Int properties

Property nameTypeDescription
charCharcharacter corresponding to the integer code (in ASCII)

Rat properties and methods

Property nameTypeDescription
fractionRat*Ratnumerator and denominator of the number, in the reduced form
Method headerDescription
toInt(): Intreturns the number converted to Int (conversion may be lossy)

Float methods

Method headerDescription
toInt(): Intreturns the number converted to Int (conversion may be lossy)

Char properties

Property nameTypeDescription
codeIntinteger code of the character (in ASCII)

String properties and methods

Property nameTypeDescription
emptyBoolwhether the string is empty
lengthIntnumber of characters in the string
Method headerDescription
all(f: Char->Bool): Booldetermines whether all characters in the string satisfy a condition
any(f: Char->Bool): Booldetermines whether any character in the string satisfies a condition
count(c: Char): Intreturns the number of occurrences of a character within the string
ends(s: String): Booldetermines whether the string ends with a given string
filter(f: Char->Bool): Stringreturns a string with only those characters from the original string that satisfy a condition
find(s: String, start: Int = 0): Int?returns the index of the first occurrence of a string within the string, or null if it is not found
fold<B>(f: Char->B->B, r: B): Bapplies an accumulator function over the string, with a given initial accumulator value
get(p: Int): Char?returns the character under a given index in the string, or null if the index is out of bounds
has(s: String): Booldetermines whether the string contains a given substring
map(f: Char->Char): Stringreturns a string with characters from the original string transformed by a mapping function
reduce(f: Char->Char->Char): Charapplies an accumulator function over the string, with the first character as the initial value
split(sep: String): [String]splits the string into substrings delimited by a given separator
starts(s: String): Booldetermines whether the string starts with a given string
toInt(): Intreturns the string's content converted to Int (conversion may fail)
toFloat(): Floatreturns the string's content converted to Float (conversion may fail)
toRat(): Ratreturns the string's content converted to Rat (conversion may fail)

[A] (array) properties and methods

Property nameTypeDescription
emptyBoolwhether the array is empty
lengthIntnumber of elements in the array
Method headerDescription
all(f: A->Bool = _): Booldetermines whether all elements in the array satisfy a condition
any(f: A->Bool = _): Booldetermines whether any element in the array satisfies a condition
clear(): Voidremoves all elements from the array
copy(): [A]returns a shallow copy of the array
count(x: A): Intreturns the number of occurrences of an element within the array
erase(p: Int, count: Int = 1): Voidremoves elements from the array at a given position
extend(a: [A]): Voidappends all elements in a given array to the array
filter(f: A->Bool): [A]returns an array with only those elements from the original array that satisfy a condition
find(x: A, start: Int = 0): Int?returns the index of the first occurrence of an element within the array, or null if it is not found
fold<B>(f: A->B->B, r: B): Bapplies an accumulator function over the array, with a given initial accumulator value
get(p: Int): A?returns the element under a given index in the array, or null if the index is out of bounds
has(x: A): Booldetermines whether the array contains a given element
insert(p: Int, x: A): Voidinserts a new element at a given position of the array
join(sep: String = ""): Stringreturns a string consisting of elements from the array (characters or strings) delimited by a given separator
map<B>(f: A->B): [B]returns an array with elements from the original array transformed by a mapping function
pop(): Aremoves the last element from the array and returns it (will fail if the array is empty)
push(x: A): Voidappends a given element to the end of the array
reduce(f: A->A->A): Aapplies an accumulator function over the array, with the first element as the initial value
reverse(): [A]reverses the order of elements in the array in place, and returns the reversed array
sort<K>(reverse: Bool = false, key: A->K = _): [A]sorts the array in place, stably, using a function to extract comparison keys, and returns the sorted array

{A} (set) properties and methods

Property nameTypeDescription
emptyBoolwhether the set is empty
lengthIntnumber of elements in the set
Method headerDescription
add(x: A): Voidadds a given element to the set
all(f: A->Bool = _): Booldetermines whether all elements in the set satisfy a condition
any(f: A->Bool = _): Booldetermines whether any element in the set satisfies a condition
clear(): Voidremoves all elements from the set
copy(): {A}returns a shallow copy of the set
filter(f: A->Bool): {A}returns a set with only those elements from the original set that satisfy a condition
fold<B>(f: A->B->B, r: B): Bapplies an accumulator function over the set, with a given initial accumulator value
has(x: A): Booldetermines whether the set contains a given element
intersect(s: {A}): Voidremoves all elements not present in a given set from the set
map<B>(f: A->B): {B}returns a set with elements from the original set transformed by a mapping function
pop(): Aremoves the last element from the set and returns it (will fail if the set is empty)
reduce(f: A->A->A): Aapplies an accumulator function over the set, with the first element as the initial value
remove(x: A): Voidremoves a given element from the set
subtract(s: {A}): Voidremoves all elements in a given set from the set
union(s: {A}): Voidadds all elements in a given set to the set

{A:B} (dictionary) properties and methods

Property nameTypeDescription
emptyBoolwhether the dictionary is empty
lengthIntnumber of elements in the dictionary
Method headerDescription
all(f: A*B->Bool): Booldetermines whether all key-value pairs in the dictionary satisfy a condition
any(f: A*B->Bool): Booldetermines whether any key-value pair in the dictionary satisfies a condition
clear(): Voidremoves all elements from the dictionary
copy(): {A:B}returns a shallow copy of the dictionary
filter(f: A*B->Bool): {A:B}returns a dictionary with only those key-value pairs from the original dictionary that satisfy a condition
fold<C>(f: A*B->C->C, r: C): Capplies an accumulator function over the dictionary, with a given initial accumulator value
get(x: A): B?returns the value under a given key in the dictionary, or null if the key is not present
has(x: A): Booldetermines whether the dictionary contains a given key
map<C,D>(f: A*B->C*D): {C:D}returns a dictionary with key-value pairs from the original dictionary transformed by a mapping function
pop(): A*Bremoves the last key-value pair from the dictionary and returns it (will fail if the dictionary is empty)
reduce(f: A*B->A*B->A*B): A*Bapplies an accumulator function over the dictionary, with the first key-value pair as the initial value
remove(x: A): Voidremoves a given key from the dictionary
update(d: {A:B}): Voidupdates the dictionary with keys and values from a given dictionary

Tuple properties

Property nameTypeDescription
letter azanycorresponding element of the tuple

A... (generator) methods

Method headerDescription
next(): Aruns the generator and returns the yielded value

Common methods

Method headerDescription
toString(): Stringreturns the string representation of the value

Standard library

This section describes the built-in functions in Pyxell, as well as constants and functions within corresponding modules.

I/O functions

Function headerDescription
read(): Stringreads a string from the standard input, to the first whitespace character
readChar(): Charreads a single character from the standard input
readFloat(): Floatreads a floating-point number from the standard input
readInt(): Intreads an integer number from the standard input
readLine(): Stringreads a string from the standard input, to the first newline character
readRat(): Ratreads a rational number from the standard input
write(s: String): Voidwrites a string to the standard output

Bitwise functions

Function headerDescription
bitAnd(x: Int, y: Int): Intreturns the bitwise AND of x and y
bitNot(x: Int): Intreturns the bitwise NOT of x
bitOr(x: Int, y: Int): Intreturns the bitwise OR of x and y
bitShift(x: Int, y: Int): Intreturns the bitwise shift of x: left for positive y, right for negative y
bitXor(x: Int, y: Int): Intreturns the bitwise XOR of x and y

Arithmetic functions

Function headerDescription
abs<T>(x: T): Treturns the absolute value of x
clamp<T>(x: T, a: T, b: T): Treturns x clamped to the interval [a, b]
max<T>(x: T, y: T): Treturns the maximum of x and y
min<T>(x: T, y: T): Treturns the minimum of x and y
sign<T>(x: T): Treturns the sign of x (-1, 0, or 1)

math module

Constant nameTypeValue
EFloatapproximation of the number e: 2.718281828459045f
INFFloatfloating-point positive infinity
PIFloatapproximation of the number π: 3.141592653589793f
Function headerDescription
acos(x: Float): Floatreturns the angle (in radians) whose cosine is x
asin(x: Float): Floatreturns the angle (in radians) whose sine is x
atan(x: Float): Floatreturns the angle (in radians) whose tangent is x
ceil(x: Float): Floatreturns the smallest integral value greater than or equal to x
cos(x: Float): Floatreturns the cosine of x (in radians)
exp(x: Float): Floatreturns e raised to the power of x
floor(x: Float): Floatreturns the largest integral value less than or equal to x
log(x: Float): Floatreturns the natural logarithm of x
log10(x: Float): Floatreturns the base 10 logarithm of x
round(x: Float, p: Int = 0): Floatreturns x rounded to p fractional digits
sin(x: Float): Floatreturns the sine of x (in radians)
sqrt(x: Float): Floatreturns the square root of x
tan(x: Float): Floatreturns the tangent of x (in radians)
trunc(x: Float): Floatreturns the integral part of x (x rounded towards 0)

random module

Function headerDescription
randFloat(r: Float = 1): Floatreturns a random floating-point number from the interval [0, r)
randInt(r: Int = 2): Floatreturns a random integer number from the interval [0, r)
seed(x: Int): Floatinitializes the pseudo-random number generator with a given seed