-
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_display
is optional. -
input_int(text_to_display)
: inputs an int.text_to_display
is optional. -
input_num(text_to_display)
: inputs an int or a float.text_to_display
is 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)
: returnsTrue
ifvalue
is an integer,False
if it is not. Corresponds toisinstance(value, int)
. -
is_float(value)
: returnsTrue
ifvalue
is a float,False
if it is not. Corresponds toisinstance(value, float)
. -
is_num(value)
: returnsTrue
ifvalue
is a float or an integer,False
if it is not. Corresponds toisinstance(value, float) or isinstance(value, int)
. -
is_str(value)
: returnsTrue
ifvalue
is a str,False
if it is not. Corresponds toisinstance(value, str)
. -
is_list(value)
: returnsTrue
ifvalue
is a list,False
if it is not. Corresponds toisinstance(value, list)
. -
is_func(value)
: returnsTrue
ifvalue
is a function,False
if it is not. Corresponds toisinstance(value, BaseFunction)
whereBaseFunction
is function and builtin function. -
is_module(value)
: returnsTrue
ifvalue
is a module,False
if it is not. Corresponds toisinstance(value, module)
. Example:import math; is_module(math)
will beTrue
, butis_module(3.2)
will beFalse
. -
is_none(value)
: returnsTrue
ifvalue
is None,False
if it is not. Corresponds toisinstance(value, NoneValue)
orvalue is None
. -
is_constructor(value)
(new in 0.20.0): returnsTrue
ifvalue
is a constructor,False
if it is not. Corresponds toisinstance(value, Constructor)
. -
is_object(value)
(new in 0.20.0): returnsTrue
ifvalue
is an object,False
if 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']
.char
is 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 ifvalue
starts withsubstring
. Example:"nougaro"
starts with"noug"
, but"canal du midi"
does not start with"minimes"
-
endswith(value, substring)
: returns True ifvalue
ends withsubstring
. Example:"nougaro"
ends with"garo"
, but"canal du midi"
does not end with"minimes"
-
round(number, n_digits)
: Returnnumber
withn_digits
decimals.n_digits
is optional (default: returnint(number)
) and may be negative.
-
ord(c)
: Return an integer representing the Unicode code point of thatc
.c
is a string with only one character. Ex:ord('a')
returns97
andord('€')
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. Ifindex
is not given, the last element of the list is popped. -
insert(list, value, index)
: append value at the given index in the list.index
is 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_duplicates
is True, removes the list2 elements already in list1 before extending.remove_duplicates
is 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_num
isTrue
.ignore_not_num
is optional (default:False
) -
min(list, ignore_not_num)
: returns the minimum element of the list. Ignore other than numbers ifignore_not_num
isTrue
.ignore_not_num
is 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 stringvalue
by reference and returns the result. Example:reverse([1, 2, 3])
is[3, 2, 1]
. -
sort(value, mode)
: sorts listvalue
according to modemode
. Available modes are:timsort
(default),stalin
,sleep
,miracle
andpanic
.mode
is optional (default:"timsort"
)-
timsort
is Python’s default algorithm -
stalin
sends 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]
. -
sleep
sort 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-verbose
to see what’s happening. -
miracle
sort 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. -
panic
sort 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_term
isTrue
, prints the General Public License 3.0 in the terminal. Otherwise, it opens the GPL in the default system program.print_in_term
is optional (default:False
)
-
path_exists(path)
: returnTrue
(1
) if the path exists,False
(0
) otherwise.
-
exit(stop_code)
: just quits the interpreter.stop_code
is optional. -
clear()
: clears the screen. Returns None. -
void()
: do nothing. Returns None. -
run(file_name)
: execute the code in the filefile_name
.file_name
is astr
. -
example(example_name, return_example_value)
: execute the code in the fileexamples/(example_name).noug
.example_name
is astr
.return_example_value
is anint
(it returns the list value from the example execution if it isTrue
).example_name
is optional (default isexample.noug
in Nougaro parent directory).return_example_value
is 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)
.source
is a str. -
__is_keyword__(word)
: check ifword
is a valid Nougaro keyword, such as 'import' or 'int'.word
is astr
. -
__is_valid_token_type__(tok_type)
: check iftok_type
is a valid Nougaro token type, such as 'EE' or 'BITWISENOT'.tok_type
is astr
. -
__test__(should_print_ok, should_i_return)
: executes the test file for the nougaro interpreter.should_print_ok
is optional (prints "OK" each times a test was succesful).should_i_return
is 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. Pass0
as argument to see only the number.
Please refer to Math module.