List of built-in functions
Note
In this page, type of parameters are noted using the param: type syntax (type can eventually be Any), and optional parameters are noted between <> and their default value are specified with =.
Also, *args tells that this function can take any number of arguments.
Input/Output
Note
The end optional argument of all these functions was added in 1.3.0.
print
Usage: print(str: str, <end: str>).
Prints str in console. Returns None. Example: print("hello, world!").
Prints the optional argument end after str (default: \n).
print_ret
Usage: print_ret(str: str).
Prints str in console and returns it. Example: print_ret("hello, world!").
print_in_red
Usage: print_in_red(str: str, <end: str>).
Prints str in red in console. Returns None. Example: print_in_red("Error: this error is RED").
Prints the optional argument end after str (default: \n).
print_in_red_ret
Usage: print_in_red_ret(str: str).
Prints str in red in console and returns it. Example: print_in_red_ret("Error: this error is RED and returned")
print_in_green
Usage: print_in_green(str: str, <end: str>).
Prints str in green in console. Returns None. Example: print_in_green("Info: this info is GREEN").
Prints the optional argument end after str (default: \n).
print_in_green_ret
Usage: print_in_green_ret(str: str).
Prints str in green in console and returns it. Example: print_in_green_ret("Info: this info is GREEN and returned")
input
Usage: input(<text_to_display: str = "">).
Inputs a str. If text_to_display is specified, it is printed as a prompt.
input_int
Usage: input_int(<text_to_display: str = "">).
Inputs an int. If text_to_display is specified, it is printed as a prompt.
input_num
Usage: input_num(<text_to_display: str = "">).
Inputs an int or a float. If text_to_display is specified, it is printed as a prompt.
Types
Note
Python isinstance() returns True if value is an object of the given type.
type
Usage: type(value: Any)
Returns a str of the internal type of the value. It can be str, int, float, list, func, module, ...
is_int
Usage: is_int(value: Any)
Returns True if value is an integer, False if it is not. Corresponds to isinstance(value, int).
is_float
Usage: is_float(value: Any)
Returns True if value is a float, False if it is not. Corresponds to isinstance(value, float).
is_num
Usage: is_num(value: Any)
Returns True if value is a number, False if it is not. Corresponds to isinstance(value, float) or isinstance(value, int).
is_str
Usage: is_str(value: Any)
Returns True if value is a string, False if it is not. Corresponds to isinstance(value, str).
is_list
Usage: is_list(value: Any)
Returns True if value is a list, False if it is not. Corresponds to isinstance(value, list).
is_func
Usage: is_func(value: Any)
Returns True if value is a function, False if it is not. Corresponds to isinstance(value, BaseFunction) where BaseFunction is function, method and builtin function.
is_module
Usage: is_module(value: Any)
Returns True if value is a module, False if it is not. Corresponds to isinstance(value, module). Example: import math; is_module(math) will be True, but is_module(3.2) will be False.
is_none
Usage: is_none(value: Any)
Returns True if value is None, False if it is not. Corresponds to isinstance(value, NoneValue) or value is None.
is_constructor
Added in 0.20.0-beta
Usage: is_constructor(value: Any)
Returns True if value is a constructor, False if it is not. Corresponds to isinstance(value, Constructor).
is_object
Added in 0.20.0-beta
Usage: is_object(value: Any)
Returns True if value is an object, False if it is not. Corresponds to isinstance(value, object). Note: in Nougaro, everything is not an object!
Type conversions
str
Usage: str(value: Any)
Converts value to string (may return an error).
int
Usage: int(value: Any)
Converts value to int (may return an error).
float
Usage: float(value: Any)
Converts value to float (may return an error).
Note that float("inf") is infinity and float("nan") is not a number.
list
Usage: list(value: Any)
Converts value to list (may return an error).
String and lists operators
all
Note
New in 1.3.0
Usage: all(value: list)
Return True if every value of the list is true, False otherwise.
any
Note
New in 1.3.0
Usage: any(value: list)
Return True if one of the values in the list is true, False otherwise.
upper
Usage: upper(value: str)
Returns upper-cased string. Example: upper('nougaro') returns 'NOUGARO'.
lower
Usage: lower(value: str)
Returns lower-cased string. Example: lower('NOUGARO') returns 'nougaro'.
split
Usage: split(value: str, <char: str = " ">)
Returns splitted string. For example, split('a b c') returns ['a', 'b', 'c'] ; split('a b c', 'b') returns ['a ', ' c'].
startswith
Usage: startswith(value: str, substring: str)
Returns True if value starts with substring. Example: "nougaro" starts with "noug", but "canal du midi" does not start with "minimes".
endswith
Usage: endswith(value: str, substring: str)
Returns True if value ends with substring. Example: "nougaro" ends with "garo", but "canal du midi" does not end with "minimes".
len
Usage: len(value: list | str)
Returns the number of elements in a list (i.e. its length), or the number of chars in a str.
reverse
Usage: reverse(value: list | str)
Reverses list or string value by reference and returns the result. Example: reverse([1, 2, 3]) is [3, 2, 1].
append
Usage: append(list: list, value: Any)
Appends value at the end of the list. Returns a list. If the list is a variable, edits the variable.
pop
Usage: pop(list: list, <index: int = -1>):
Deletes value at given index. Returns the popped element. If the list is a variable, edits the variable. If index is not given, the last element of the list is popped.
insert
Usage: insert(list: list, value: Any, <index: int = -1>)
Inserts value at the given index in the list.
replace
Usage: replace(list: list, index: int, value: Any)
Replaces value at the given index in the list.
extend
Usage: extend(list1: list, list2: list, <remove_duplicates: int = False>)
Appends to list1 the elements of list2. Returns list1. If list1 is a variable, edits the variable. If remove_duplicates is True, removes the list2 elements already in list1 before extending.
get
Usage: get(list: list, index: int)
Returns the element of the list at the given index.
max
Usage: max(list: list, <ignore_not_num: int = False>)
Returns the maximum element of the list. Ignores elements that are not numbers if ignore_not_num is True, otherwise crashes if such element exists.
min
Usage: min(list: list, <ignore_not_num: int = False>)
Returns the minimum element of the list. Ignores elements that are not numbers if ignore_not_num is True, otherwise crashes if such element exists.
sort
Usage: sort(value: list, <mode: str = "timsort">)
Note
- Slowsort and bogosort were added in 1.2.0
Sorts list value according to mode mode. Lefts the original list unchanged
and returns a new list.
Available modes are: timsort (default), bogo, miracle, panic, sleep,
slow and stalin.
timsortis Python’s default algorithmbogosort randomly shuffles the list until it is sorted. May take an infinite amount of time!miraclesort literally waits for a miracle. It checks if the list is sorted, and if it is not, it checks again. If a cosmic ray (or another miracle) flips the right bits in your RAM so the list is sorted, miraclesort will return the sorted list.panicsort checks if the list is sorted. If so, it returns it. If the list is not sorted, this causes an illegal hardware instruction (Unix and GNU/Linux) or a segfault (Windows).sleepsort take only a list of positive integers. It starts as many threads as elements in the list, and each thread waits for as much seconds as the element. For instance, when the list[5, 2, 3, 0]is passed in sleepsort, it starts by launching 4 threads that wait for 5, 2, 3 and 0 seconds. When a thread finishes to wait, it append its element to the list. Use the modesleep-verboseto see what’s happening.slowsort really sorts the list, but is very slow (even the best case is worst than bubble sort). See the wikipedia page about slowsort.stalinsends to gulag values that are not sorted (i.e. pop them from the list). Example:[1, 4, 3, 7, 6, 10, 2, 5, 23]will be sorted as[1, 4, 7, 10, 23].
Number operators
round
Usage: round(number: int | float, <n_digits: int = 0>)
Rounds number to the closest number with n_digits decimals. n_digits may be 0 or negative, in which case the returned type is int.
Changed in 0.22.0-beta
The round built-in function previously returned int only when n_digits was 0 (now it is the case when n_digits ⩽ 0)
Characters and Unicode
Note
There’s more in the unicodedata module.
ord
Usage: ord(c: str)
Returns an integer representing the Unicode code point of that c. c is a string with only one character. Ex: ord('a') returns 97 and ord('€') returns 8364.
chr
Usage: chr(i: int)
Returns the string representing the character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', and chr(8364) returns the string '€'.
License
__gpl__
Usage: __gpl__(<print_in_term: int = False>)
If print_in_term is True, prints the General Public License 3.0 in the terminal. Otherwise, it opens the GPL in the default system program.
Files
__path_exists__
Usage: path_exists(path: str)
Returns True (1) if the path exists, False (0) otherwise.
Technical
exit
Usage: exit(<stop_code: int | str = 0>)
Just quits the interpreter.
clear
Usage: clear()
Clears the screen. Returns None.
void
Usage: void(*args)
Does nothing. Returns None.
run
Usage: run(file_name: str)
Executes the code in the file file_name.
example
Usage: example(<example_name: str | None = None>, <return_example_value: int = False>)
Executes the code in the file examples/(example_name).noug. If example_name is None, executes the code in the file example.noug.
If return_example_value is True, returns the list value from the example execution.
system_call
Warning
This function may be dangerous, because any system command can be executed.
Usage: system_call(cmd: str)
Calls cmd. Prints the result of the command and returnt the stop code as str.
__python__
Warning
This function may be dangerous, because any Python code can be executed.
Usage: __python__(source: str)
Runs Python’s eval(source).
__is_keyword__
Usage: __is_keyword__(word: str)
Check if word is a valid Nougaro keyword.
__is_valid_token_type__
Usage: __is_valid_token_type__(tok_type: str)
Checks if tok_type is a valid Nougaro token type, such as 'EE' or 'BITWISENOT'.
__test__
Usage: __test__(<should_print_ok: int = False>, <should_i_return: int = False>)
Executes the test file for the Nougaro interpreter. If should_print_ok is True, prints “OK” each times a test was succesful. If should_i_return is true, returns the value of the interpreted file.
__py_type__
Usage: __py_type__(value)
Returns the string of Python’s type(value). For instance, __py_type__(__py_type__) is "<class 'src.runtime.values.functions.builtin_function.BuiltInFunction'>"
__how_many_lines_of_code__
Usage: __how_many_lines_of_code__(<print_details: Any = True>)
Lets you know how many lines of code there are in Nougaro. If print_details is True, details how many lines of code they are in each file.
Mathematical functions
Please refer to Math module.