Documentations - SRON
  • SRON's Official Documentation
  • Installation
  • Syntax of SRON
  • Executing a SRON code
  • Keywords in SRON
  • Comments in SRON
  • Datatypes in SRON
  • Variables in SRON
  • Memory Ownership Model
  • Operators in SRON
  • Math block
  • if elif else in SRON
  • Loops in SRON
    • For Loop
    • While Loop
    • Foreach Loop
  • Break & Continue
  • Functions in SRON
    • Print functions
    • User Input Functions
    • Type Conversion functions
    • Type Checking functions
    • Math functions
    • Char Functions
    • String Functions
    • List Functions
    • Miscellaneous functions
  • Return in SRON
  • Command Line Arguments
  • Free
  • Rotate
  • Console
  • Sample codes
  • Coding Convention
  • Frequently Asked Questions
  • Credits
  • Contact
  • Donate
Powered by GitBook
On this page
  • SRON provides abundant amount of in-built functions to work on data efficiently and easily without explicitly code them.
  • Calling functions in sub-directories

Functions in SRON

Functions are the block of code which are used to perform a particular task. They make code more readable and easier to debug and understand. In SRON, this is how you can create your own function.

{
    name : MAIN
}

SRON's functions are highly optimized for great speed, efficiency and performance. If you ever think that you are repeating a particular line of code multiple times, then create a seperate function for it.

{
    name : function_name
    args : (Any value)

    @ the 'name' attribute is used to name a function.
    @ the 'args' attribute is used to declare the arguments of the function.
}

You can also set the argument types for the function, like this:

{
    name : char_value
    args : (Int __val)
    type : Int
    return __val
}

{
    name : Main
    
    @ the passed argument 'A' is automatically converted to
    @ integer in char_value() function
    println(char_value('A'))  @ Output: 65
}

What if you want strict type checking such that if the passed argument is not same as the specified type, then code will not run. For this, SRON provides strict argument keywords:

{
    name : char_value
    args : (Int_s __val)
    type : Int
    return __val
}

{
    name : Main

    println(char_value('A'))  @ Error
}

SRON provides 6 strict argument keywords:

Int_s Double_s Char_s Bool_s String_s List_s

These keywords ensures that the argument being passed to the function is of the specified type otherwise error will rise.


SRON provides abundant amount of in-built functions to work on data efficiently and easily without explicitly code them.

  • Print functions

  • User input functions

  • Type conversions functions

  • Type check functions

  • Math functions

  • Char functions

  • List functions

  • Miscellaneous functions

Calling functions in sub-directories

Suppose this is your directory tree:

- Main
  |
  |----Main.srb
  |
  |----assets
       |
       |------ square.srb
       |------ cube.srb
       |
       |------ codes
               |
               |------ square_root.srb
               |------ cube_root.srb

Now, if you want to call square.srb and cube.srb from Main.srb, then you have to use access operator '.' (dot), here is sample code :

Syntax: 
    folder_name.bytecode_file.srb()
{
    name : Main

    Any val = input_int("\n Enter the number :- ")

    Any square = assets.square(val)
    Any cube = assets.cube(val)
    Any square_root = assets.codes.square_root(val)
    Any cube_root = assets.codes.cube_root(val)

    println("Square = " , square)
    println("Cube = " , cube)
    println("Square root = ",square_root)
    println("Cube root = ", cube_root)
}
PreviousBreak & ContinueNextPrint functions

Last updated 6 months ago