To get started with yorlang, download and install the node runtime here
Then install the yorlang package with the following command:
Terminal
npm install -g yorlang
HELLO WORLD
Create a yl file e.g test.yl and write your first yorlang statement
yorlang
sọpé "báwo ni ayé";
Run yorl test.yl in your cli
OUTPUT
bawo ni aye
You can also download the vs code extension here
For more command line usage, run yorl --help
You can watch the intoductory video to yorlang here
Variables can be declared in yorlang using
Yorlang: jẹ́kí
Variables in yorlang must be initialized at the point of declaration. The keyword (jẹ́kí) must be used when initializing and re-assigning a variable. Strings in yorlang must be enclosed with double quotes. Yorlang variables can hold many data types such as strings, integers, arrays and booleans
Note:
Use the # symbol for single line comments. There's no multiline comments like /** */
A semi colon must be used at the end of every statement in yorlang
Yorlang is not accent mark sensitive but it is case sensitive.
Only english/yoruba alphabet can be used for variable names.
Boolean values are - true: òótọ́ false: irọ́
Operators in Yorlang include;
plus: "+" , minus: "-", multiply: "*", divide: "/" ,
Remainder: "%", Less_than: " < ", greater_than: ">", greater_than_or_equal: ">=",
less_than_or_equal: "<=", not_equal: "!=", equal: "==", assign: "=",
not_operator: "!", or: "||", and: "&&"
yorlang
jẹ́kí oruko = "damilola";
jẹ́kí odun = 5 ;
sọpé oruko + " " + "is" + " " + odun + " " + "years old" ;
OUTPUT
damilola is 5 years old
Re-assign variable example:
yorlang
jẹ́kí orúkọ = "dammy";
jẹ́kí orúkọ = "tunde" ;
sọpé "oruko mi ni" + " " + orúkọ ;
OUTPUT
oruko mi ni tunde
Conditionals such as if, else, else if and switch statements can also be used in yorlang
if: ṣé else: tàbí else if: tàbí ṣé
yorlang
jẹ́kí ago = 15;
ṣé
( ago < 12 ) {
jẹ́kí
ìkíni = "e kaaro" ;
} tàbí ṣé ( ago > 12
&& ago < 17 ) {
jẹ́kí ìkíni = "e kaasan" ;
} tàbí {
jẹ́kí ìkíni = "e kaale" ;
}
sọpé ìkíni + " " + "aye" ;
OUTPUT
e kaasan aye
The Switch Condition:
The switch expression is evaluated once.
The value of the expression is compared with the values of each case.
If there is a match, the associated block of code is executed and then it escapes the switch block without the need for a break (kúrò) statement.
The use of the break statement(kúrò) in yorlang yí(switch) condition results in an error.
The default(padàsí) block runs when there's no matched case.
Switch: yí
Case: irú
Default: padàsí
yorlang
jẹ́kí age = (2 * 5) + 8 ;
yí
( age ) {
irú 12 :
sọpé "omode ni e" ;
irú 18 :
sọpé "ọ̀dọ́ ni e" ;
irú 22 :
sọpé "agbalagba ni e" ;
padàsí:
sọpé "arugbo ni e ooooo" ;
}
OUTPUT
ọ̀dọ́ ni e
Loops such as for and while are also supported in Yorlang
For: fún while: nígbàtí break: kúrò
Note:
increments such as i++ in yorlang is invalid instead use jẹ́kí i = i + 1
decrements such as i-- in yorlang is invalid instead use jẹ́kí i = i - 1
yorlang
fún ( jẹ́kí i = 0 ; i < 5 ; jẹ́kí i = i + 1 ) {
ṣé
( i == 3 ) {
kúrò;
}
sọpé "iwọ ni" + " " + i ;
}
OUTPUT
iwọ ni 0
iwọ ni 1
iwọ ni 2
The While( nígbàtí) Loop:
The while ( nígbàtí) loop is executed as long as the condition in parentheses is true
yorlang
jẹ́kí onka = [1, 2, 3, 4, 5 ];
jẹ́kí i = 0;
nígbàtí ( onka [ i ] < 3) {
sọpé "o kere si aarun";
jẹ́kí i = i + 1;
}
OUTPUT
o kere si aarun
o kere si aarun
Function: iṣẹ́ return: padà
yorlang
iṣẹ́ isiro ( a, b)
{
padà a * b ;
}
jẹ́kí X = isiro( 5, 6);
sọpé X ;
OUTPUT
30
Variable Scope
The scope of a variable is the context within which it is defined. All inner functions(iṣẹ́) have access to variables in their outer functions(iṣẹ́). However, outer functions(iṣẹ́) do not have access to the variables in their inner functions(iṣẹ́). This scope spans imported(gbewọlé) files as well. For example:
yorlang
jẹ́kí a = 3;
gbewọlé "sample.yl";
Here the a variable will be available within the imported sample.yl script. An inner function can only read the value of the outer variable but it can’t change it. An attempt to change it will simply create a local variable within the inner function. For example:
yorlang
jẹ́kí a = 3;
iṣẹ́ àpẹrẹ ()
{
jẹ́kí a = a + 1;
sọpé a;
}
àpẹrẹ();
sọpé a;
OUTPUT
4
3
To mutate the value of outer variables within an inner function, you must declare those variables with wòkè. The script below will output 4. By declaring counter and i with wòkè within the function incrementCounter, all references to the variables will refer to the outer version. There is no limit to the number of global variables that can be manipulated by a function.
yorlang
iṣẹ́ getCounter ()
{
jẹ́kí counter = 3;
jẹ́kí i = 1;
iṣẹ́ incrementCounter ()
{
wòkè `counter, i`;
jẹ́kí counter = counter + i;
}
incrementCounter();
padà counter ;
}
sọpé getCounter();
OUTPUT
4
One-dimensional array example
yorlang
jẹ́kí àwọnMọ́tọ̀ = ["G-Wagon", "S-class" ];
sọpé àwọnMọ́tọ̀ [0];
OUTPUT
G-Wagon
Multi-dimensional arrays are also supported in Yorlang
yorlang
jẹ́kí àwọnMọ́tọ̀ = [ ["corolla", "camry"], ["G-Wagon", "S-class" ], ["Elantra", "sonata"] ];
sọpé àwọnMọ́tọ̀ [1][1];
OUTPUT
S-class
Add elements to the last position of an array by making the index empty
yorlang
jẹ́kí àwọnMọ́tọ̀ = [ ["corolla", "camry"], "benz" ];
jẹ́kí àwọnMọ́tọ̀[0][] = "S-class";
jẹ́kí àwọnMọ́tọ̀[] = "G-Wagon";
sọpé àwọnMọ́tọ̀ [0][2];
sọpé àwọnMọ́tọ̀ [2];
OUTPUT
S-class
G-Wagon
The import (gbewọlé) keyword is used to include the content of a yorlang file into another yorlang file.
This keyword is followed by a string which contains the path to the yorlang file to be imported. The file paths should be provided as a suffix to the project's absolute path
For example, suppose you have a project folder app with two sub folders : deploy & test . In the deploy folder is a file called deploy.yl and in the test folder is a file called test.yl . To import the test.yl file into the deploy.yl file, do the following.
yorlang
gbewọlé "/test/test.yl";
Here are some helper functions in Yorlang and their descriptions
ka :
This is used for counting the length of an array. Hence, it takes an array
as its parameter.
e.g. ka([26,78,75]) returns 3 as the length of the array.
síLẹ́tàŃlá :
This is used for converting strings to uppercase. síLẹ́tàŃlá
takes a string as its parameter.
For example, síLẹ́tàŃlá("KaYode"); returns "KAYODE"
síLẹ́tàKékeré :
This is used for converting strings to lowercase. síLẹ́tàkékeré
takes a string as its parameter.
For example, síLẹ́tàKékeré("KaYode"); returns "kayode"
tèSíbí :
This is used for reading user inputs. tèsíbí
takes a string as its parameter.
For example, tèSíbí("What is your name?"); returns user input
aago :
It is used for getting the current date.
For example, aago(); returns an array of the current date in the following order [ year, month, day, hours, minutes, seconds, milliseconds ]
fiRọ́pọ̀ :
It is used for replacing a substring with a new string.
For example, fiRọ́pọ̀("Yoruba da pupo", "pupo", "gidigan"); returns "Yoruba da gidigan"
waNínú :
It is used for checking if a string contains a substring.
For example, aago("Yoruba da pupo", "pupo"); returns boolean - ooto
yipo :
It is used for generating random numbers between an interval.
For example, yipo(1, 5); returns a number between 1 and 5,
yipo(5); returns a number between 0 and 5,
yipo(); returns a number between 0 and 1