# 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**.

```js
{
    name : Main
    @ the beep sound is made for 1000 milliseconds(1 second)
    beep(500, 1000)
}
```

***

### **2. cliTextColor():**

This function returns a Cli color escape sequenced string to color the text using RGB values.

```js
{
    name : Main
    
    String color = cliTextColor(2, 214, 214)

    console : ( color, "Hello SRON", CLI_DESIGN_RESET)
}
```

***

### **3. cliBgColor():**

This function returns a Cli color escape sequenced string to set the background color using RGB values.

```js
{
    name : Main
    
    String color = cliBgColor(41, 44, 84)

    console : (color, "Hello SRON", CLI_DESIGN_RESET)
}
```

***

### **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.

```js
{
    name : Main
     String a = "abc"
     String b = copy(a)

     push(a, 'd')
     println(a, '\n' , b)
}
```

#### **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](/docs/exit-codes.md).

```js
{
    name : Main
    exit(0)
}
```

***

### **6. getExecTime():**

This function returns the time taken by program to execute the code (in milliseconds).

```js
{
    name : Main
    Int a = 0
    for : {
        range : (Int i=1, 1000)
        a += i
    }
     println("Time Taken = ", getExecTime(), " milli-seconds.")
    
}
```

#### **OUTPUT:**

> Time Taken = 1 milli-seconds.

***

### **7. len():**

This function returns the length of any String/List values.

```js
{
    name : Main

    @  length of a 'String' value
     Any length = len("ABCDEFGH")
     println(length)

    @  length of a 'List' value
     length = len([1,2,3,4,5,6,7,8,9,0])
     println(length)
    
}
```

#### **OUTPUT:**

> 8\
> 10

***

### **8. randInt():**

This function returns a random 'Int' type value. Takes no arguments.

```js
{
    name : Main
    
     Int random_num = randInt()
     println(random_num)
}
```

#### **OUTPUT:**

> 5251570147017362282

***

### **9. randDouble():**

This function returns a random 'Double' type value. Takes no arguments.

```js
{
    name : Main
    
     Double random_num = randDouble()
     println(random_num)
}
```

#### **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.

```js
{
    name : Main
    
     Int random_num = randRange(0,10)
     println(random_num)

     random_num = randRange(0.0, 10.0)
     println(random_num)
}
```

#### **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.

```js
{
    name : Main
    
     Double num = 123.123456789
     println(num)

     setPrecision(5)
     println(num)
}
```

#### **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.

```js
{
    name : Main

    @ getting the size of 'Void' value...
    Any size = sizeof(Void)
    println(size)
    
    @  getting the size of 'Int' value...
     size = sizeof(27062003)
     println(size)

    @  getting the size of 'Double' value...
     size = sizeof(2706.2003)
     println(size)

    @  getting the size of 'Char' value...
     size = sizeof('S')
     println(size)

    @  getting the size of 'Bool' value...
     size = sizeof(false)
     println(size)

    @  getting the size of 'String' value...
     size = sizeof(toString("Hello, SRON!"))
     println(size)

    @  getting the size of 'List' value...
     size = sizeof([1,2,3,4,5,6])
     println(size)

    @ getting the size of 'FileReader' value...
    size = sizeof(freader("file.txt"))
    println(size)

    @ getting the size of 'FileWriter' value...
    size = sizeof(fwriter("file.txt", true))
    println(size)

    @ getting the size of 'LiteralString' value...
    size = sizeof("HELLO, SRON!")
    println(size)

}
```

#### **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.

```js
{
    name : Main

    println("Sleeping")

    sleep(1000)

    @ the code will be paused for 1 seconds (1000 milliseconds)
    println("Waking")
}
```

### **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**](https://github.com/saksham-joshi/SRON-Docs/blob/main/special-codes-of-sronCmd.md)**.**

```javascript
{
    name : Main 

    OBUFFER += "Hello there! Saksham Joshi"

    sronCmd(SRON_CMD_OBUFFER_CLEAR)

    console : ( '>' , OBUFFER , '<') @ Output: ><
}
```

***

### **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.

```js
{
    name : Main

     sysCmd("sron-docs")
     @ official docs of Sron will open in your browser
}
```

***

### **16. typeof():**

This function returns a 'String' value specifying the type of the passed value.

```js
{
    name : Main

     println(typeof(1234)) 

     println(typeof(1234.9973))

     println(typeof('S'))

     println(typeof(false))

     println(typeof("SRON"))
    
     println(typeof([1,2,3,4]))
}
```

#### **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.

```js
{
    name : Main
    List lst = [1,2,3,4,5]
    Int inp = inputInt("Enter the index :- ")

    if : {
        condition : ${ inp < 0 || inp >= len(lst) }
        throwException(IndexNotWithinRangeException)
    }

    println(at(lst, inp))
}
```

#### **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.

```js
{
    name : Main
    println(version())
}
```

#### **OUTPUT:**

> 2.300

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sron.gitbook.io/docs/functions-in-sron/miscellaneous-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
