-
Notifications
You must be signed in to change notification settings - Fork 1
Built in functions
Jean Dubois edited this page Jun 5, 2024
·
53 revisions
-
print(str): prints str in console. Returns None. Example:print("hello, world!"). -
print_ret(str): prints str in console and returns it. Example:print_ret("hello, world!") -
print_in_red(str): prints str in red in console. Returns None. Example:print_in_red("Error: this error is RED"). -
print_in_red_ret(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(str): prints str in green in console. Returns None. Example:print_in_green("Info: this info is GREEN"). -
print_in_green_ret(str): prints str in green in console and returns it. Example:print_in_green_ret("Info: this info is GREEN and returned") -
input(text_to_display): inputs a str.text_to_displayis optional. -
input_int(text_to_display): inputs an int.text_to_displayis optional. -
input_num(text_to_display): inputs an int or a float.text_to_displayis optional.
Note: Python isinstance() returns True if value is an object of the given type.
-
type(value): returns a str of the type of the value. It can bestr,int,float,list,func,built-in func,module, ... -
is_int(value): returnsTrueifvalueis an integer,Falseif it is not. Corresponds toisinstance(value, int). -
is_float(value): returnsTrueifvalueis a float,Falseif it is not. Corresponds toisinstance(value, float). -
is_num(value): returnsTrueifvalueis a float or an integer,Falseif it is not. Corresponds toisinstance(value, float) or isinstance(value, int). -
is_str(value): returnsTrueifvalueis a str,Falseif it is not. Corresponds toisinstance(value, str). -
is_list(value): returnsTrueifvalueis a list,Falseif it is not. Corresponds toisinstance(value, list). -
is_func(value): returnsTrueifvalueis a function,Falseif it is not. Corresponds toisinstance(value, BaseFunction)whereBaseFunctionis function and builtin function. -
is_module(value): returnsTrueifvalueis a module,Falseif it is not. Corresponds toisinstance(value, module). Example:import math; is_module(math)will beTrue, butis_module(3.2)will beFalse. -
is_none(value): returnsTrueifvalueis None,Falseif it is not. Corresponds toisinstance(value, NoneValue)orvalue is None. -
is_constructor(value)(new in 0.20.0): returnsTrueifvalueis a constructor,Falseif it is not. Corresponds toisinstance(value, Constructor). -
is_object(value)(new in 0.20.0): returnsTrueifvalueis an object,Falseif it is not. Corresponds toisinstance(value, object). Note: in Nougaro, everything is not an object!
-
str(value): value to string -
int(value): value to integer -
float(value): value to float -
list(value): value to list
-
upper(value): Return upper-cased string. e.g.upper('nougaro')returns'NOUGARO'. -
lower(value): Return lower-cased string. e.g.lower('NOUGARO')returns'nougaro'. -
split(value, char): Return splitted string. e.g.split('a b c')returns['a', 'b', 'c'];split('a b c', 'b')returns['a ', ' c'].charis optional. -
len(value): returns the number of elements in (the lenght of) a list, or the number of chars in a str. -
startswith(value, substring): returns True ifvaluestarts withsubstring. Example:"nougaro"starts with"noug", but"canal du midi"does not start with"minimes" -
endswith(value, substring): returns True ifvalueends withsubstring. Example:"nougaro"ends with"garo", but"canal du midi"does not end with"minimes"
-
round(number, n_digits): Returnnumberwithn_digitsdecimals.n_digitsis optional (default: returnint(number)) and may be negative.
-
ord(c): Return an integer representing the Unicode code point of thatc.cis a string with only one character. Ex:ord('a')returns97andord('€')returns8364 -
chr(i): Return the string representing a character whose Unicode code point is the integeri. For example,chr(97)returns the string'a', andchr(8364)returns the string'€'.
-
append(list, value): append value at the end of the list. Returns a list. If the list is a variable, modify the variable. -
pop(list, index): delete value at given index. Returns the popped element. If the list is a variable, modify the variable. Ifindexis not given, the last element of the list is popped. -
insert(list, value, index): append value at the given index in the list.indexis optional. -
replace(list, index, value): replace value at the given index in the list. -
extend(list1, list2, remove_duplicates): append to list1 the elements of list2. Returns list1. If list1 is a variable, modify the variable. Ifremove_duplicatesis True, removes the list2 elements already in list1 before extending.remove_duplicatesis an optional argument, but must be a number. -
get(list, index): returns the element of the list at the given index -
max(list, ignore_not_num): returns the maximum element of the list. Ignore other than numbers ifignore_not_numisTrue.ignore_not_numis optional (default:False) -
min(list, ignore_not_num): returns the minimum element of the list. Ignore other than numbers ifignore_not_numisTrue.ignore_not_numis optional (default:False) -
len(value): returns the number of elements in (the lenght of) a list, or the number of chars in a str. -
reverse(value): reverse list or stringvalueby reference and returns the result. Example:reverse([1, 2, 3])is[3, 2, 1]. -
sort(value, mode): sorts listvalueaccording to modemode. Available modes are:timsort(default),stalin,sleep,miracleandpanic.modeis optional (default:"timsort")-
timsortis Python’s default algorithm -
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]. -
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. -
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 a segfault.
-
-
__gpl__(print_in_term): ifprint_in_termisTrue, prints the General Public License 3.0 in the terminal. Otherwise, it opens the GPL in the default system program.print_in_termis optional (default:False)
-
path_exists(path): returnTrue(1) if the path exists,False(0) otherwise.
-
exit(stop_code): just quits the interpreter.stop_codeis optional. -
clear(): clears the screen. Returns None. -
void(): do nothing. Returns None. -
run(file_name): execute the code in the filefile_name.file_nameis astr. -
example(example_name, return_example_value): execute the code in the fileexamples/(example_name).noug.example_nameis astr.return_example_valueis anint(it returns the list value from the example execution if it isTrue).example_nameis optional (default isexample.nougin Nougaro parent directory).return_example_valueis optional (defaultFalse(0)). -
system_call(cmd): callscmd. Print the result of the command and return the stop code as str. -
__python__(sourcce): runs python’seval(source).sourceis a str. -
__is_keyword__(word): check ifwordis a valid Nougaro keyword, such as 'import' or 'int'.wordis astr. -
__is_valid_token_type__(tok_type): check iftok_typeis a valid Nougaro token type, such as 'EE' or 'BITWISENOT'.tok_typeis astr. -
__test__(should_print_ok, should_i_return): executes the test file for the nougaro interpreter.should_print_okis optional (prints "OK" each times a test was succesful).should_i_returnis optional (return the value of the interpreted file). -
__py_type__(value): returns python string for python’stype(value). As boring as it sounds. -
__how_many_lines_of_code__()let you know how many lines of code there are in Nougaro. Pass0as argument to see only the number.
Please refer to Math module.