Variables
var
Variable declaration with value assignment.
var x = 10;
var name = "John";
var isActive = true;
var count = 0;
x = 20; // Reassignment
Primitive Types
number
Integer or floating-point numbers.
var integer = 42;
var float = 3.14159;
var negative = -10;
string
Text values enclosed in double quotes.
var greeting = "Hello, World!";
var name = "Lotus";
var message = "Welcome to Lotus programming!";
boolean
Logical values: true or false.
var isActive = true;
var isComplete = false;
var hasPermission = true;
null
Represents the absence of a value.
var empty = null;
var result = null;
var data = null;
Array
array
Ordered collection of values with indexed access.
// Array literal
var numbers = [1, 2, 3, 4, 5];
var names = ["Alice", "Bob", "Charlie"];
var mixed = [1, "two", true, [4, 5]];
// Index access
var first = numbers[0]; // 1
var second = numbers[1]; // 2
var name = names[2]; // "Charlie"
numbers[0] = 10; // Modify element
Struct
struct
Defines a structure with named fields. Access and modify fields using dot notation.
// Struct literal
var user = struct { name: "Ana", age: 30 };
var point = struct { x: 10, y: 20 };
var book = struct { title: "Lotus", pages: 200, published: true };
// Member access
var userName = user.name; // "Ana"
var userAge = user.age; // 30
var pointX = point.x; // 10
// Field assignment
user.age = 31;
user.name = "Ana Silva";
point.x = 15;
point.y = 25;
Conditionals
if / else
Conditional structure that executes a block if the condition is true.
if (x < y) {
print("x is smaller");
} else {
print("y is smaller or equal");
}
var max = if (a > b) { a; } else { b; };
if (age >= 18) {
print("Adult");
} else {
print("Minor");
}
Loops
for
Loop structure with initialization, condition, and increment.
for (var i = 0; i < 10; i = i + 1) {
print(i);
}
for (var j = 0; j < len(arr); j = j + 1) {
print(arr[j]);
}
while
Loop structure that repeats while the condition is true.
var i = 10;
while (i > 0) {
print(i);
i = i - 1;
}
var count = 5;
while (count > 0) {
print(count);
count = count - 1;
}
Functions
function
Define and call functions to encapsulate reusable code.
// Define functions
var add = function(x, y) {
return x + y;
};
var greet = function(name) {
return "Hello, " + name + "!";
};
var incrementAge = function(user) {
user.age = user.age + 1;
};
// Call functions
var sum = add(5, 3); // 8
var message = greet("Alice"); // "Hello, Alice!"
var person = struct { name: "John", age: 25 };
incrementAge(person); // person.age is now 26
Built-in Functions
len
Returns the size of a string or array.
var strLength = len("hello"); // 5
var arrLength = len([1, 2, 3, 4, 5]); // 5
var emptyLength = len([]); // 0
first
Returns the first element of an array.
var firstNum = first([1, 2, 3]); // 1
var firstName = first(["Alice", "Bob", "Charlie"]); // "Alice"
last
Returns the last element of an array.
var lastNum = last([1, 2, 3]); // 3
var lastName = last(["Alice", "Bob", "Charlie"]); // "Charlie"
push
Adds an element to the end of an array.
var arr = [1, 2];
var newArr = push(arr, 3); // [1, 2, 3]
var names = ["Alice", "Bob"];
var updated = push(names, "Charlie"); // ["Alice", "Bob", "Charlie"]
print
Prints values to the console.
print "hello world";
print "The result is: " + result;
print 42;
print [1, 2, 3];
Comments
//
Comments.
// This is a comment
var x = 10; // Inline comment
// Comments are ignored by the interpreter
// They are useful for documentation