मूल सूत्र (MoolSutra)
transliteration: MoolSutra, meaning: Native functions
मूल सूत्र (MoolSutra) are the core native functions of Vedic. Here we will learn how to utilize them in your programs.
1. कुल (kul)
transliteration: kul, meaning: count
The कुल
function in Vedic is used to count the size of a given data type. It is a fundamental native function that helps in determining the number of elements or the length of a data structure. To use the कुल
function, you need to pass the data type or structure as an argument, and it will return the count or size value.
सूचि (list) Example:
मान mySuchi = [1, 2, 3, 4, 5];
मान count = कुल(mySuchi);
वद("The count is:",count);
Output:
The count is: ६
In the above example, we have an array
myArray
, and we use theकुल
function to determine its size. The result is then printed using theवद
function.
वाक्य (string) Example:
मान myString = "QWERTY";
मान count = कुल(myString);
वद("The count is:",count);
Output:
The count is: ५
In the above example, we have an string
myString
, and we use theकुल
function to determine its length. The result is then printed using theवद
function.
2. अंक (ank)
transliteration: ank, meaning: to convert a string to a number
The अंक
function in Vedic is used to convert a string representation of a number into its numerical equivalent. It is helpful when you need to perform mathematical operations or comparisons on user input, which is typically in string format. To use the अंक
function, simply pass the string as an argument, and it will return the corresponding number.
Example:
मान numString = "42";
मान number = अंक(numString);
वद("The converted number is:", number);
Output:
The converted number is: ४२
In the above example, we have a string
numString
containing the number "42" Theअंक
function converts it into the numerical value42
, which is then printed using theवद
function.
3. लभ्यते (labhyate)
transliteration: labhyate, meaning: to check if the second string is a substring of the first string
The लभ्यते
function in Vedic is used to check whether the second string is a substring of the first string. It returns a Boolean value (true
or false
) indicating the result of the substring check. To use the लभ्यते
function, provide the two strings as arguments, and it will return true
if the second string is found within the first string.
Example:
मान mainString = "Hello, World!";
मान substring = "World";
मान isSubstring = लभ्यते(mainString, substring);
वद("Is it a substring? =>",isSubstring);
Output:
Is it a substring? => सत्य
In the above example, we have a main string
mainString
and a substringsubstring
. Theलभ्यते
function checks whethersubstring
is present withinmainString
and returnstrue
. The result is then printed using theवद
function.
4. निर्गम (nirgam)
transliteration: nirgam, meaning: exit
The निर्गम
function in Vedic is used to exit the program with a given exit code. It allows you to terminate the program execution gracefully when certain conditions are met. To use the निर्गम
function, provide the exit code as an argument, and the program will terminate with that exit code.
Example:
निर्गम(०); # Exit Function
In the above example, the
निर्गम
function is called with the exit code०
. This will cause the program to terminate immediately with an exit code of0
.
5. पठन (pathana)
transliteration: pathana, meaning: read
The पठन
function in Vedic is used to read a line from the standard input (stdin). It allows you to accept user input during program execution. To use the पठन
function, simply call it, and it will wait for user input. The entered line is then returned as a string.
Example:
वद("Enter your name:");
मान name = पठन();
वद("Hello, ",name);
Output:
Hello, Prashant
In the above example, the
पठन
function is used to read the user's name from the standard input. The entered name is then printed with a greeting message using theवद
function.
6. प्रकार (prakaar)
transliteration: prakaar, meaning: type
The प्रकार
function in Vedic is used to determine the type of a given value. It returns a string representing the type, which can be useful for debugging and validation purposes. The possible types it can return include अंक
(number), वाक्य
(string), तर्क
(boolean), and others.
Example:
वद(प्रकार(सत्य)); # expect: तर्क
वद(प्रकार(१.०)); # expect: अंक
वद(प्रकार(१.०*१.०)); # expect: अंक
वद(प्रकार(१) == "अंक"); # expect: सत्य
वद(प्रकार("some random string")); # expect: वाक्य
7. समय (samay)
transliteration: samay, meaning: time
The समय
function in Vedic returns the current time in milliseconds. It is useful for measuring time intervals, logging, and other time-related operations.
Example:
वद(समय()); # current time in milliseconds
8. शब्द (shabd)
transliteration: shabd, meaning: word
The शब्द
function in Vedic is used to convert a given value into a string. This can be helpful when you need to ensure a value is in string format, such as for concatenation or display purposes.
Example:
मान a = १२३;
वद(प्रकार(a)); # expect: अंक
# convert to string
a = शब्द(a);
वद(प्रकार(a)); # expect: वाक्य
9. त्रुटि (truti)
transliteration: truti, meaning: error
The त्रुटि
function in Vedic is used to throw a runtime error with a custom message. It allows you to handle exceptional conditions gracefully by providing descriptive error messages.
Example:
त्रुटि("Custome error message"); # this will throw a custom runtime error with the message "Custome error message"
Output:
# अनुष्ठान-काले-दोषः :
# File "tests/mool/truti.ved", line 1, column 32
# दोषः : त्रुटि : Custome error message
10. वद (vad)
transliteration: vad, meaning: speak/print
The वद
function in Vedic is used to print the given strings or values to the standard output. It is similar to the print
function in other programming languages and is essential for displaying messages and debugging information.
Example:
वद("Hello world"); # expect: Hello world
वद("Hello world", "Hello world"); # expect: Hello world Hello world
By understanding and utilizing these native functions of Vedic, you can start building powerful and culturally inspired programs. Experiment with the language and explore its unique features to unlock its full potential. Happy coding with Vedic!