Miscellaneous functions
SRON provides these 15 functions :
beep()
cliTextColor()
cliBgColor()
copy()
exit()
getExecTime()
len()
randInt()
randDouble()
randRange()
setPrecision()
sizeof()
sleep()
sronCmd()
sysCmd()
throwException()
typeof()
version()
1. beep():
This function is used to make a beep sound. It requires two 'Int' type arguments frequency and duration.
2. cliTextColor():
This function returns a Cli color escape sequenced string to color the text using RGB values.
3. cliBgColor():
This function returns a Cli color escape sequenced string to set the background color using RGB values.
4. copy():
This function creates a copy of the value passed to it. So, the changes made to the original value does not affect the new value.
OUTPUT:
abcd abc
5. exit():
This function exits the program and suddenly stops it. It takes a 'Int' value as argument.
exit(exit_code)
This exit code tells why program halted. Read more about it from Exit codes.
6. getExecTime():
This function returns the time taken by program to execute the code (in milliseconds).
OUTPUT:
Time Taken = 1 milli-seconds.
7. len():
This function returns the length of any String/List values.
OUTPUT:
8 10
8. randInt():
This function returns a random 'Int' type value. Takes no arguments.
OUTPUT:
5251570147017362282
9. randDouble():
This function returns a random 'Double' type value. Takes no arguments.
OUTPUT:
0.947
10. randRange():
This function returns a random number between a particular range. It takes two arguments start_point and end_point. If you pass two 'Int' values, then it will generate a 'Int' type random value between them. And if you pass two 'Double' values, then it will generate a random 'Double' type value between them.
OUTPUT:
6 9.890
11. setPrecision():
This function sets the number of decimal digits to be printed by 'print()' and 'println()' function. setPrecision(num_of_precision) If num_of_precision must be more than 0 and less than 10, otherwise by default 5 decimal digits will be set as the precision.
OUTPUT:
123.123 123.12345
12. sizeof():
This function returns the size of the data in bytes. You can use it to find how much memory, your variable is taking.
OUTPUT:
8 16 16 16 16 40 40 48 40 24
13. sleep():
This function is used to pause the execution for some given time. It expects an integer type value as argument. It pauses the code for given milliseconds.
14. sronCmd():
This function can be used to get information about internal components of SRON's interpreter and perform operations on them too. Know more from here.
15. sysCmd():
This function is used to execute a command in the host operating system's command processor. It takes a 'String' type value as argument. If the command is executed, then it returns a 'Void' value otherwise displays an exception.
16. typeof():
This function returns a 'String' value specifying the type of the passed value.
OUTPUT:
Int Double Char Bool LiteralString List
17. throwException()
This function is used to display error message during runtime. It takes a String type input.
OUTPUT:
Enter the index :- 5
IndexNotWithinRangeException caught:
> Reason 1: Index is more than or equal to the length of List or String.
> Reason 2: Index is less than 0.
||> Solution : Check the index value if it is less than zero or more than or equal to length of the list and then pass the value to the function.
18. version():
This function returns the version of SRON installed in your system.
OUTPUT:
2.300
Last updated