QuantumC

Built-in Functions

Back to Home

Quantum C has various built in functions, which are functions that are hard coded in the language, instead of you needing to manualy write them All QuantumC intrinsics begin with a backtick (`). The backtick is omitted from signatures in this table for readability.

Function Use Signature Example call
`qout printing text to console. Text is not followed by a newline void qout(string text, ...args); qout("Hello, World!\n");
`random generating random numbers. If you pass no arguments, it returns a number from 0.00… (inclusive) to 1.00… (exclusive). If you pass a single integer argument, it returns a number from 0 (inclusive) to that number (exclusive). If you pass 2 integer arguments, it returns a number from number 1 (inclusive) to num 2 (exclusive) double random(); / int random(int max); / int random(int min, int max); random(123, 314);
`seed changes the currently used seed for random, to give different more random results void seed(int arg); seed(1234);
`time returns the current timestamp as a integer. Mainly used to get a ever changing seed because otherwise random would always generate the same numbers. int time(); seed(time());
`typeof returns the data type of the value passed into the function Unrepresentable int a = 0; qout("%s", typeof(a));
`to_(type) there are several to_? functions, e.g. to_bool. They take compatible arguments and convert them to the target type. Unrepresentable int n = to_int(true);
`len Returns the length of a string int len(string arg) len("Hello, World!"); // 13
`to_lower Returns a string in all lowercase string to_lower(string arg) to_lower("Hello, WORLD"); // hello, world
`to_upper Returns a string in all-caps string to_upper(string arg) to_upper("i spent 48 hours debugging namespaces"); // I SPENT 48 HOURS DEBUGGING NAMESPACES
`substring Returns a part of a string string substring(string arg, int start, int stop) substring("Hello, World", 0, 5);// Hello
`split Returns a list of strings of a string split at a delimiter string[] split(string arg, string delim) split("Hello, World!", ","); // ["Hello", " World"]
`join Returns a string that is a list of strings joined, and you pass a delimiter which is what the strings are joined with string join(list<string> splitstr, string delim) join(split("a b c", " "), "-"); // a-b-c
`contains Returns true if arg 1 contains arg 2 bool contains(string arg1, string arg2) contains("Hello, World", "Hello"); // true
`startswith Returns true if arg 1 starts with arg 2 bool startswith(string arg1, string arg2) startswith("Hello, World", "Hello"); // true
`endswith Returns true if arg 1 ends with arg 2 bool endswith(string arg1, string arg2) endswith("Hello, World", "Hello"); // false
`trim Returns a string trimed of whitespace on both sides string trim(string arg) trim(" this will be trimed \n\t"); // this will be trimed
`replace Returns a string with all occurences of arg2 replaced with arg3 string replace(string arg1, string arg2, string arg3) replace("this\nis\na\nstring", "\n", " "); // this is a string
`open Takes a filepath and permission string, returns a file descriptor. int open(string filename, string permission) int myFile = open("/home/me/.bashrc", "r"); // whatever file descriptor that would be
`close Takes a file descriptor and closes it. void close(int fd) close(myFile)
`write Takes a file descriptor and data and writes to it. void write(int fd, string data) write(myFile, "Hello")
`read Takes a file descriptor and the amount of bytes to read and returns that many. string read(int fd, long int size) read(myFile, 5) // Hello, because of above write
`ternary Takes a bool and 2 args of same type. Returns left if true and right if false. Unrepresentable ternary(1 < 2, "Ok", "Huh?") // Ok