Learn LAML v3.4.0

Master the enhanced LAML language with comprehensive data types, array support, and powerful new features. From basics to advanced concepts, this interactive guide has everything you need.

1 Setup & Syntax
→
2 Data Types
→
3 Arrays & Functions
→
4 Advanced Features

šŸš€ Installation & Setup

Get LAML v3.4.0 installed on your system with our one-click installers:

Windows

iwr -useb https://github.com/NaveenSingh9999/LAML/raw/refs/heads/main/installers/windows/install.ps1 | iex

Linux/macOS

curl -fsSL https://github.com/NaveenSingh9999/LAML/raw/refs/heads/main/installers/linux/install.sh | bash

šŸ’” Tip

After installation, verify everything works by running laml --version in your terminal.

šŸ‘‹ Your First Program

Let's start with the classic "Hello, World!" program in LAML:

hello.lm
bring xcs.class34;

func main() {
    say "Hello, LAML v3.3.0!";
}
Output:
Hello, LAML v3.3.0!

Code Breakdown:

  • bring xcs.class34; - Import the core LAML module
  • func main() { ... } - Define the main function (entry point)
  • say "text"; - Print text to the console

šŸŽÆ Try It Yourself

Modify the program to say hello to yourself. Save it as greeting.lm and run with:

laml run greeting.lm

šŸ“Š Enhanced Data Types

LAML v3.3.0 introduces a comprehensive type system with five core data types:

int

Whole numbers

let age: int = 25;

float

Decimal numbers

let height: float = 5.9;

string

Text data

let name: string = "Alice";

bool

True/false values

let isActive: bool = true;

array

Collections of data

let scores: array = [95, 87, 92];
types_demo.lm
bring xcs.class34;

func main() {
    // Explicit type declarations
    let age: int = 25;
    let height: float = 5.9;
    let name: string = "Alice";
    let isStudent: bool = true;
    let grades: array = [95, 87, 92, 88];
    
    say "Name: " + name;
    say "Age: " + age;
    say "Height: " + height;
    say "Is Student: " + isStudent;
    say "Grades: " + grades;
}
Output:
Name: Alice
Age: 25
Height: 5.9
Is Student: true
Grades: [95, 87, 92, 88]

šŸ“‹ Working with Arrays

Arrays in LAML v3.3.0 are powerful and flexible, supporting various operations:

arrays_demo.lm
bring xcs.class34;

func main() {
    // Creating arrays
    let numbers: array = [1, 2, 3, 4, 5];
    let names: array = ["Alice", "Bob", "Charlie"];
    let mixed: array = [1, "hello", true, 3.14];
    
    say "Numbers: " + numbers;
    say "Names: " + names;
    say "Mixed: " + mixed;
    
    // Array operations
    let doubled: array = [];
    loop num in numbers {
        doubled.push(num * 2);
    }
    
    say "Doubled: " + doubled;
    
    // Array indexing
    say "First number: " + numbers[0];
    say "Last name: " + names[2];
}
Output:
Numbers: [1, 2, 3, 4, 5]
Names: ["Alice", "Bob", "Charlie"]
Mixed: [1, "hello", true, 3.14]
Doubled: [2, 4, 6, 8, 10]
First number: 1
Last name: Charlie

šŸ”€ Control Flow

LAML provides intuitive conditional statements and loops for program logic control:

control_flow.lm
~ LAML Control Flow Structures
bring xcs.class34;

func main() {
    say "=== LAML Control Flow Demo ===";
    
    {~ 
       If/Else Conditional Logic
       Testing different conditions and responses
    ~}
    say "=== Conditional Logic ===";
    
    let score = 85;
    let grade = "";
    
    ~ Multiple if-else conditions (nested structure)
    if score >= 90 {
        grade = "A";
    } else {
        if score >= 80 {
            grade = "B";
        } else {
            if score >= 70 {
                grade = "C";
            } else {
                if score >= 60 {
                    grade = "D";
                } else {
                    grade = "F";
                }
            }
        }
    }
    
    say "Score: " + score + " - Grade: " + grade;
    
    ~ Boolean logic
    let isValid = true;
    let isActive = false;
    
    if isValid && !isActive {
        say "System is valid but inactive";
    }
    
    {~ 
       Loop Structures
       Different types of loops for iteration
    ~}
    say "";
    say "=== Loop Structures ===";
    
    ~ C-style for loop
    say "Counting from 1 to 5:";
    for val i = 1; i <= 5; i++ {
        say "Count: " + i;
    }
    
    ~ While loop
    say "";
    say "Countdown from 3:";
    let countdown = 3;
    while countdown > 0 {
        say "T-minus " + countdown;
        countdown--;
    }
    say "Blast off! šŸš€";
    
    ~ Array iteration (manual indexing)
    say "";
    say "=== Array Processing ===";
    let fruits = ["apple", "banana", "orange", "grape"];
    let i = 0;
    
    say "Fruits in our basket:";
    while i < 4 {
        say "- " + fruits[i];
        i++;
    }
}
Output:
=== LAML Control Flow Demo ===
=== Conditional Logic ===
Score: 85 - Grade: B
System is valid but inactive

=== Loop Structures ===
Counting from 1 to 5:
Count: 1
Count: 2
Count: 3
Count: 4
Count: 5

Countdown from 3:
T-minus 3
T-minus 2
T-minus 1
Blast off! šŸš€

=== Array Processing ===
Fruits in our basket:
- apple
- banana
- orange
- grape

šŸŽÆ Key Control Flow Features

  • Nested If-Else: LAML uses nested structure instead of "else if"
  • Boolean Operators: Use && (AND), || (OR), ! (NOT) for complex conditions
  • For Loops: C-style loops with initialization, condition, and increment
  • While Loops: Condition-based iteration for dynamic control
  • Array Iteration: Manual indexing with bounds checking for arrays

šŸ”„ Advanced Loop Patterns

LAML supports various loop patterns for different iteration needs:

advanced_loops.lm
~ Advanced Loop Patterns in LAML
bring xcs.class34;

func main() {
    say "=== Advanced Loop Patterns ===";
    
    {~ 
       Nested loops for patterns and matrices
    ~}
    say "Pattern Generation:";
    for val row = 1; row <= 4; row++ {
        let line = "";
        for val col = 1; col <= row; col++ {
            line = line + "* ";
        }
        say line;
    }
    
    say "";
    say "Multiplication Table (3x3):";
    for val i = 1; i <= 3; i++ {
        for val j = 1; j <= 3; j++ {
            let result = i * j;
            say i + " x " + j + " = " + result;
        }
        say "---";
    }
    
    {~ 
       Array processing with conditions
    ~}
    say "";
    say "=== Conditional Array Processing ===";
    let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    let i = 0;
    
    say "Even numbers:";
    while i < 10 {
        if numbers[i] % 2 == 0 {
            say "- " + numbers[i];
        }
        i++;
    }
    
    ~ Finding maximum in array
    say "";
    say "Finding maximum:";
    let max = numbers[0];
    let idx = 1;
    while idx < 10 {
        if numbers[idx] > max {
            max = numbers[idx];
        }
        idx++;
    }
    say "Maximum value: " + max;
}
Output:
=== Advanced Loop Patterns ===
Pattern Generation:
* 
* * 
* * * 
* * * * 

Multiplication Table (3x3):
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
---
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
---
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
---

=== Conditional Array Processing ===
Even numbers:
- 2
- 4
- 6
- 8
- 10

Finding maximum:
Maximum value: 10

šŸ’” Loop Best Practices

Remember that LAML uses C-style for loops and while loops. Always ensure your loop conditions will eventually become false to avoid infinite loops!

āš™ļø Functions

Functions in LAML help organize code and enable reusability:

functions.lm
bring xcs.class34;

// Function to calculate area of rectangle
func calculateArea(length: float, width: float) {
    let area: float = length * width;
    return area;
}

// Function to greet a person
func greet(name: string, age: int) {
    say "Hello, " + name + "! You are " + age + " years old.";
}

// Function to find maximum in array
func findMax(numbers: array) {
    let max: int = numbers[0];
    loop num in numbers {
        if num > max {
            max = num;
        }
    }
    return max;
}

func main() {
    // Using functions
    let length: float = 5.5;
    let width: float = 3.2;
    let area: float = calculateArea(length, width);
    say "Area: " + area;
    
    greet("Alice", 25);
    
    let scores: array = [85, 92, 78, 96, 88];
    let highest: int = findMax(scores);
    say "Highest score: " + highest;
}
Output:
Area: 17.6
Hello, Alice! You are 25 years old.
Highest score: 96

🧩 Format Specifiers & Escape Sequences

LAML v3.4.0 introduces C-style format specifiers and escape sequences for powerful string formatting and output control:

šŸ“ Format Specifier Syntax

say("Hello %s, your score is %d", name, score);
format_basics.lm
~ LAML Format Specifiers Demo
bring xcs.class34;

func main() {
    ~ Basic format specifiers
    let name = "Naveen";
    let age = 25;
    let score = 98.7654;
    let isActive = true;
    
    say("Hello %s, you are %d years old", name, age);
    say("Your score is %f (default precision)", score);
    say("Your score is %.2f (2 decimal places)", score);
    say("Status: %b", isActive);
}
Output:
Hello Naveen, you are 25 years old
Your score is 98.765400 (default precision)
Your score is 98.77 (2 decimal places)
Status: true

šŸ“Š Format Specifiers Table

Specifier Type Example Input Example Output
%s String "naveen" naveen
%d Integer 69 69
%f Float (6dp) 98.7654 98.765400
%.2f Float (2dp) 98.7654 98.77
%c Character 'N' N
%b Boolean true true
escape_sequences.lm
~ Escape Sequences Demo
bring xcs.class34;

func main() {
    say "=== Escape Sequences Demo ===";
    
    ~ Line breaks and tabs
    say("Line 1\nLine 2\nLine 3");
    say("Tabbed\ttext\there");
    
    ~ Quotes and special characters
    say("Quote: \"Hello World\"");
    say("Apostrophe: \'LAML\'");
    say("Backslash: \\path\\to\\file");
    
    ~ Control characters
    say("Bell sound: \a(if supported)");
    say("Carriage return:\rOverwritten text");
    say("Backspace: ABC\b\b123");
}
Output:
=== Escape Sequences Demo ===
Line 1
Line 2
Line 3
Tabbed	text	here
Quote: "Hello World"
Apostrophe: 'LAML'
Backslash: \path\to\file
Bell sound: (if supported)
Overwritten text
Backspace: A123

šŸ”„ Escape Sequences Table

Sequence Meaning Output Effect
\n New Line Moves to next line
\t Tab Space Inserts tab space
\\ Backslash Prints \
\' Single Quote Prints '
\" Double Quote Prints "
\a Bell Beep sound (if supported)
\b Backspace Deletes previous char
\r Carriage Return Returns to line start
advanced_formatting.lm
~ Advanced Formatting Examples
bring xcs.class34;

func main() {
    say "=== Advanced Formatting Examples ===";
    
    {~ 
       Combining format specifiers with escape sequences
    ~}
    let player = "Lamgerr";
    let marks = 97.45;
    say("Player: %s\nScore: %.2f\nResult: %s", player, marks, "PASS");
    
    say "";
    
    ~ Precision control with floats
    let pi = 3.14159265359;
    say("Pi with different precisions:");
    say("Default: %f", pi);
    say("2 decimal: %.2f", pi);
    say("4 decimal: %.4f", pi);
    
    say "";
    
    ~ Character and boolean formatting
    let firstChar = 'L';
    let isComplete = true;
    say("First letter: %c, Complete: %b", firstChar, isComplete);
    
    ~ Arrays and mixed types
    let numbers = [1, 2, 3, 4, 5];
    say("Numbers array: %s", numbers);
    
    ~ Backward compatibility - old syntax still works
    say "Old syntax: This still works with escape sequences!\nSee the newline?";
}
Output:
=== Advanced Formatting Examples ===
Player: Lamgerr
Score: 97.45
Result: PASS

Pi with different precisions:
Default: 3.141593
2 decimal: 3.14
4 decimal: 3.1416

First letter: L, Complete: true
Numbers array: [1, 2, 3, 4, 5]
Old syntax: This still works with escape sequences!
See the newline?

āš ļø Error Handling & Validation

LAML automatically validates that the number of format specifiers matches the number of arguments:

say("Hello %s %d", "World"); // Error: Missing argument for %d
say("Hello %s", "World", 42); // Error: Too many arguments

šŸ’” Best Practices

  • Precision Control: Use %.nf for precise float formatting
  • Type Safety: LAML automatically converts compatible types
  • Backward Compatibility: Old say "string" syntax still works
  • Escape Sequences: Work in both new and old syntax styles
  • Array Formatting: Arrays are automatically converted to readable strings

šŸŽÆ Try It Yourself

Create a program that displays a formatted report with:

  • Student name using %s
  • Age using %d
  • GPA using %.2f
  • Enrollment status using %b
  • Tab-separated columns using \t
  • Multiple lines using \n

🧠 Type Inference

LAML v3.4.0 features smart type inference, allowing you to omit type annotations in many cases:

inference.lm
bring xcs.class34;

func main() {
    // Type inference in action
    let count = 42;           // inferred as int
    let price = 19.99;        // inferred as float
    let message = "Hello";    // inferred as string
    let isReady = true;       // inferred as bool
    let items = [1, 2, 3];    // inferred as array
    
    say "Count: " + count + " (type: int)";
    say "Price: " + price + " (type: float)";
    say "Message: " + message + " (type: string)";
    say "Ready: " + isReady + " (type: bool)";
    say "Items: " + items + " (type: array)";
    
    // Mixing explicit and inferred types
    let explicitAge: int = 25;
    let inferredAge = 30;
    
    let totalAge = explicitAge + inferredAge;  // inferred as int
    say "Total age: " + totalAge;
}
Output:
Count: 42 (type: int)
Price: 19.99 (type: float)
Message: Hello (type: string)
Ready: true (type: bool)
Items: [1, 2, 3] (type: array)
Total age: 55

šŸŽØ Enhanced Compiler Features

LAML v3.4.0 includes enhanced compiler features for better development experience:

🌈 Colored Output

The compiler provides color-coded feedback for errors, warnings, and success messages, making debugging easier and more intuitive.

šŸ” Type Checking

Enhanced type checking catches errors at compile time, ensuring type safety and preventing runtime errors.

šŸ“ Better Error Messages

Improved error messages with precise locations and helpful suggestions for fixing common mistakes.

⚔ Fast Compilation

Optimized compilation process generates efficient bytecode for fast execution across all platforms.

šŸ’” Pro Tip

Use laml run filename.lm to compile and run your programs in one command. The compiler will show colored output to help you identify any issues quickly.

šŸš€ Real-world Example

Let's build a complete program that demonstrates multiple LAML v3.3.0 features:

student_grades.lm
bring xcs.class34;

// Function to calculate average grade
func calculateAverage(grades: array) {
    let sum: float = 0.0;
    let count: int = 0;
    
    loop grade in grades {
        sum = sum + grade;
        count = count + 1;
    }
    
    return sum / count;
}

// Function to determine letter grade
func getLetterGrade(average: float) {
    if average >= 90.0 {
        return "A";
    } else if average >= 80.0 {
        return "B";
    } else if average >= 70.0 {
        return "C";
    } else if average >= 60.0 {
        return "D";
    } else {
        return "F";
    }
}

// Function to find highest and lowest grades
func findExtremes(grades: array) {
    let highest = grades[0];
    let lowest = grades[0];
    
    loop grade in grades {
        if grade > highest {
            highest = grade;
        }
        if grade < lowest {
            lowest = grade;
        }
    }
    
    return [highest, lowest];
}

func main() {
    // Student data
    let studentName = "Alice Johnson";
    let grades: array = [88, 92, 85, 90, 87, 94, 89];
    
    say "Student Grade Report";
    say "===================";
    say "Student: " + studentName;
    say "Grades: " + grades;
    
    // Calculate statistics
    let average = calculateAverage(grades);
    let letterGrade = getLetterGrade(average);
    let extremes = findExtremes(grades);
    let highest = extremes[0];
    let lowest = extremes[1];
    
    // Display results
    say "\nGrade Statistics:";
    say "Average: " + average;
    say "Letter Grade: " + letterGrade;
    say "Highest Grade: " + highest;
    say "Lowest Grade: " + lowest;
    
    // Determine if passing
    let isPassing: bool = average >= 70.0;
    if isPassing {
        say "\nāœ… Student is passing!";
    } else {
        say "\nāŒ Student needs improvement.";
    }
}
Output:
Student Grade Report
===================
Student: Alice Johnson
Grades: [88, 92, 85, 90, 87, 94, 89]

Grade Statistics:
Average: 89.3
Letter Grade: B
Highest Grade: 94
Lowest Grade: 85

āœ… Student is passing!

šŸŽ“ What's Next?

Congratulations! You've learned the fundamentals of LAML v3.3.0. Here's what you can do next:

šŸ“‚ Explore Examples

Check out the example files in the LAML repository to see more advanced usage patterns and techniques.

View Examples

šŸ”§ Set Up VS Code

Install the LAML VS Code extension for syntax highlighting and better development experience.

Setup VS Code

🌟 Build Projects

Start building your own projects with LAML. The language is perfect for scripting, automation, and learning programming concepts.

See Features

šŸ¤ Join Community

Join the LAML community on GitHub to ask questions, share projects, and contribute to the language development.

Join Community