Orca is a neat little programming language that offers a blend of object-oriented and functional programming. Below is a brief overview of its core concepts, illustrated by examples.
In Orca, comments begin with //.
// This is a comment
Variables can be declared using the var keyword. They can hold both string and number values.
var name = "Erlich Bachman"; // string variable
var age = 99; // number variable
To define a function, use the fun keyword. Function parameters are passed in parentheses, and the function body is enclosed within curly braces.
fun printCommentAboutAge(name, age) {
...
}
Functions can also return values using the return keyword. If no value is returned, the function returns null by default.
fun add(a, b) {
return a + b;
}
Orca provides an if-else structure for conditional statements.
if (age > 80) {
...
} else {
...
}
Orca supports object-oriented programming through classes. Use the class keyword to define a class.
The constructor method is named init. It gets called automatically when an instance of the class is created.
class Human {
init(name, age, occupation) {
this.name = name;
this.age = age;
this.occupation = occupation;
}
...
}
Methods can be defined within classes. The this keyword refers to the instance itself.
setName(newName) {
this.name = name;
}
getName() {
return this.name;
}
To create an instance of a class:
var erlich = Human(name, age, "Former child");
The while loop keeps executing as long as the condition remains true.
while (erlich.age > 80) {
...
}
The for loop is structured with an initializer, condition, and iterator.
for (var i = 0; i < 100; i = i + 1) {
...
}
In Orca, object properties can be accessed and assigned using the dot notation. You can also add new properties to an existing object.
erlich.isOld = erlich.age > 80;
The print keyword is used to output values to the console.
print "Erlich is now young.";
An array can be defined and accessed as follows:
var names = ["George", "James", "Harry", "William"];
You can also specify the initial array's length. The provided initializer will be filled with nil values to meet the length specifier requirements.
var numbers[10] = [1,2,3];
var people[100] = []; // An empty array of size 100.
Orca is a versatile language with features from both object-oriented and functional paradigms. This documentation provides a brief introduction to its main concepts, making it easy for developers to get started.