# New ELPL documentation with Type system

> If compiler is giving error, try code with explicit types if no types used.

```elpl
Array board be [
    [1,0,0,0, 0,0,0,2],
    [0,0,0,0, 3,0,0,0],
    [0,0,0,4, 0,0,0,0],
    [0,5,0,0, 0,6,0,0],
    [0,0,7,0, 0,0,4,0],
    [0,0,0,0, 5,0,0,0],
    [0,0,0,0, 0,8,0,0],
    [3,0,0,0, 0,0,0,1]
]

function isSafe( board,  row,  col,  num) {
    for c be 0 to 7 {
        if board[row][c] is equal to num then {
            return false
        }
    }

    for r be 0 to 7 {
        if board[r][col] is equal to num then {
            return false
        }
    }

    let startRow be row subtract (row mod 2)
    let startCol be col subtract (col mod 4)

    for r be 0 to 1 {
        for c be 0 to 3 {
            if board[startRow add r][startCol add c] is equal to num then {
                return false
            }
        }
    }

    return true
}

function solve( board) {
    for row be 0 to 7 {
        for col be 0 to 7 {
            if board[row][col] is equal to 0 then {
                for num be 1 to 8 {
                    if isSafe(board, row, col, num) is equal to true then {
                        board[row][col] be num

                        if solve(board) is equal to true then {
                            return true
                        }

                        board[row][col] be 0
                    }
                }
                return false
            }
        }
    }
    return true
}

function Print( board){
    for r be 0 to 7 {
        for c be 0 to 7 {
            print " " board[r][c]
        }
        printnl " "
    }

    return null
    
}

if solve(board) is equal to true then {
    Print(board)
} otherwise {
    print "No solution found."
} 
```

```elpl
Array<Array<Int>> board be [
    [1,0,0,0, 0,0,0,2],
    [0,0,0,0, 3,0,0,0],
    [0,0,0,4, 0,0,0,0],
    [0,5,0,0, 0,6,0,0],
    [0,0,7,0, 0,0,4,0],
    [0,0,0,0, 5,0,0,0],
    [0,0,0,0, 0,8,0,0],
    [3,0,0,0, 0,0,0,1]
]

function isSafe(Array<Array<Int>> board, Int row, Int col, Int num): Boolean {
    for c be 0 to 7 {
        if board[row][c] is equal to num then {
            return false
        }
    }

    for r be 0 to 7 {
        if board[r][col] is equal to num then {
            return false
        }
    }

    let startRow be row subtract (row mod 2)
    let startCol be col subtract (col mod 4)

    for r be 0 to 1 {
        for c be 0 to 3 {
            if board[startRow add r][startCol add c] is equal to num then {
                return false
            }
        }
    }

    return true
}

function solve(Array<Array<Int>> board): Boolean {
    for row be 0 to 7 {
        for col be 0 to 7 {
            if board[row][col] is equal to 0 then {
                for num be 1 to 8 {
                    if isSafe(board, row, col, num) is equal to true then {
                        board[row][col] be num

                        if solve(board) is equal to true then {
                            return true
                        }

                        board[row][col] be 0
                    }
                }
                return false
            }
        }
    }
    return true
}

function Print(Array<Array<Int>> board): Void {
    for r be 0 to 7 {
        for c be 0 to 7 {
            print " " board[r][c]
        }
        printnl " "
    }
}

if solve(board) is equal to true then {
    Print(board)
} otherwise {
    print "No solution found."
}
```
> 3

```elpl
Array nums be [2, 7, 11, 15]
let target be 9
let found be false

let sums be 0  // Declare the local variable once before loops

for i be 0 to length(nums){
    for j be i add 1 to length(nums){
        sums be nums[i] add nums[j]  // Reassignment without 'let'
        print "checking pair: " i j " sum: " sums
        if sums is equal to target then {
            print "indices: " i j
            let found be true
            stop
        } otherwise{
            print "pair no found"
        }
    }
    stop
}
```
> 4

```elpl

Array nums be [2, 7, 11, 15]
let target be 9
let found be false
Array result be [-1, -1]
let sums be 0

for i be 0 to length(nums) subtract 1 {
    for j be i add 1 to length(nums) subtract 1 {
         sums be nums[i] add nums[j]
        print "checking pair:" i j "sum:" sums

        if sums is equal to target then {
            let found be true
            let result[0] be i
            let result[1] be j
            stop
        }
    }
    if found is equal to true then {
        stop
    }
}

if found is equal to true then {
    print "indices: " result[0] result[1]
} otherwise {
    print "no pair found"
}
```

> 5

```elpl
Array nums be [3, 9, 12,11]
Array reversed be []

for i be 0 to length(nums){
    let reversed[i] be nums[length(nums) subtract 1 subtract i]
}

print reversed

```

> 6

```elpl

Array nums be [2, 7, 11, 15]
let n be length(nums)
let mid be n divide 2

for i be 0 to mid subtract 1 {
    let temp be nums[i]
    let nums[i] be nums[n subtract 1 subtract i]
    let nums[n subtract 1 subtract i] be temp
}

print nums
```

> 7

```elpl

function power(x, n) {
    if n is equal to 0 then {
        return 1
    }
    return x multiply power(x, n subtract 1)
}

 printnl power(2, 4) // should print 16
```

> 8

```elpl

Array nums be [-1, 0, 1, 2, -1, -4]


for i be 0 to length(nums) subtract 3 {
  for j be i add 1 to length(nums) subtract 2 {
    for k be j add 1 to length(nums){
      let sums be nums[i] add nums[j] add nums[k]
     print "checking triple: " i j k " sum: " sums
     if sums is equal to 0 then {
       print "FOUND triple at indices: " i j k " sum: " sums

  stop
}

       otherwise {
        print "not a valid triple"
      }
    }
stop
   
  }
stop
 
}
```

> 9

```elpl

Array nums be [-2, -1, 0, 1, 2, 3]
let target be 3


for i be 0 to length(nums) subtract 5 {
 for j be i add 1 to length(nums) subtract 4 {
  for k be j add 1 to length(nums) subtract 3 {
   for l be k add 1 to length(nums) subtract 2 {
    for m be l add 1 to length(nums){
     let sums be nums[i] add nums[j] add nums[k] add nums[l] add nums[m]
     print "checking quintuple: " i j k l m " sum: " sums
     if sums is equal to target then {
      print "FOUND quintuple at indices: " i j k l m " sum: " sums
    
      stop
     } otherwise {
     print "not found"
     } 
    }
    stop
   }
         // not found -> try to fix yourself
  }
  stop
 }
 stop
}
```

> 10


```elpl
function fib(n){
if n is less than or equal to 1 then {
return n
} otherwise {
 let a be fib(n subtract 1)
 let b be fib(n subtract 2)
 return a add b
}



}

for i be 0 to 30{
printnl fib(i)

}  
```

> 11

```elpl

function subsetSum(nums, index, target) {
    print"subsetSum called with index = " index ", target = " target

    if target is equal to 0 then {
        print"Target reached 0 — returning true"
        return true
    }

    if index is equal to length(nums) then {
        print"Reached end of array — returning false"
        return false
    }

    if nums[index] is less than or equal to target then {
        print"Trying including nums[" index "] = " nums[index]
        if subsetSum(nums, index add 1, target subtract nums[index]) then {
            print"Path including nums[" index "] worked — returning true"
            return true
        }
    }

    print"Trying excluding nums[" index "] = " nums[index]
    let result be subsetSum(nums, index add 1, target)
    print"Result after excluding nums[" index "]: " result
    return result
}

Array nums be [3, 4, 5, 2]
let target be 9
let result be subsetSum(nums, 0, target)
print"Final result: " result
```

> 12

```elpl

function isPalindrome(s, left, right) {
    if left is greater than or equal to right then {
        return true
    }

    if s[left] not equal to s[right] then {
        return false
    }

    return isPalindrome(s, left add 1, right subtract 1)
}

// Test case
Array word be ["r", "a", "c", "e", "c", "a", "r"]
let result be isPalindrome(word, 0, length(word) subtract 1)
print "Is Palindrome: " result

```

> 13

```elpl

function fib(n) {
    if n is equal to 0 then {
        return 0
    }
    if n is equal to 1 then {
        return 1
    }
    let a be fib(n subtract 1) 
    let b be fib(n subtract 2)
    return a add b
}

let result be fib(6)
print "Fib(6): " result

```

> 14

```elpl

function isPalindrome(s, left, right) {
    if left is greater than or equal to right then {
        return true
    }

    if s[left] not equal to s[right] then {
        return false
    }

    return isPalindrome(s, left add 1, right subtract 1)
}

// Test case
Array word be ["r", "a", "c", "e", "c", "a", "r"]
let result be isPalindrome(word, 0, length(word) subtract 1)
print "Is Palindrome: " result
```

> 15

```elpl

Array nums be [[0,2,3],[2,3,4]]

let total be 0

for i be 0 to length(nums){
  for j be 0 to length(nums[i]){
     total pels nums[i][j] 
  }
}

print total  // output: 14
```

> 16

```elpl

Map[key,value] mymap be {1: "a", 2: "b", 3: "c", 5: "v"}

foreach k,v : mymap{
   printnl "key: "k "value: " v
} 

```

> 16

```elpl

let name be scan("Enter your name: ")

print "Hello, "name    // Hello, <your entry>

```

> 17

```elpl

Map[key,value] m be {1:"a", 2:"b"}


m.put(3, "c")
print m.size() 
print m[3]        //  3 c   
                     
// this code contains error, resolve it yourself

Map[k,v] m be {1: "a", 2: "b"}
foreach k,v : m {             
   print k v
}
```

> 18

```elpl

Map[k,v] mymap be {1: "a", 2: "b"}

mymap.put(3, "c")       // add a new key-value
printnl mymap.size()       // 3

if mymap.has(2) then {
  printnl "key 2 exists"
}

mymap.delete(1)          // remove key 1
printnl mymap.has(1)       // false

mymap.clear()            // remove all entries
printnl mymap.size()       // 0

```

> 19

```elpl

function twoSum(nums, target){
Map[k,v] map be {} // initialize empty map
for i be 0 to length(nums){
let complement be target subtract nums[i]
// check if complement exists in map
if map.has(complement) then {
return [map.get(complement), i]
}
// store current number with its index in map
map.put(nums[i], i)
}
return [] // return empty array if no solution
}
// Example usage
Array nums be [2, 7, 11, 15]
let target be 9
let result be twoSum(nums, target)
printnl "Indices:" result

```

> 20


```elpl

Map[key,value] numsMap be {2: 0, 7: 1, 11: 2, 15: 3}
let target be 9

@java{
  // Use 'numsMap' and 'target' directly as injected parameters
  for (Map.Entry<Object, Object> entry : numsMap.entrySet()) {
    int num = (int) entry.getKey();
    int index = (int) entry.getValue();
    int complement = target - num;
    
    if (numsMap.containsKey(complement) && (int) numsMap.get(complement) != index) {
      System.out.println("Found Indices: " + index + ", " + numsMap.get(complement));
      break;
    }
  }
}

```

> 21

```elpl

try {
print "Before throw"
throw "Something went wrong"
print "After throw"
} catch e {
print "Caught: "e
}
```

> 22

```elpl

try {
printnl "Outer try"
try {
throw "Inner error"
} catch inner {
printnl "Caught inner: " inner
throw "Escalate"
}
} catch outer {
printnl "Caught outer: " outer
}

function riskyDivide(Int a, Int b): Int {
    if b is equal to 0 then{
    throw "Division by zero"
   }
  return a divide b
  }
try  {
   printnl riskyDivide(10, 0)
  } catch ex {
  printnl "Error caught: " ex
}

```

> 23

```elpl

List nums be [10, 20, 30]

// Heterogeneous types
List mixed be ["apple", true, 99]

// Nested lists
List matrix be [[1, 2], [3, 4], [5, 6]]



// Expressions inside
List calc be [2 add 2, 5 multiply 3, length([1,2,3])]

print matrix
print calc
print nums

```

> 24


```elpl

List nums be [10, 20, 30]
nums.insert(1, 15)       // inserts 15 at index 1
nums.append(50)      // adds 40 at end
nums.remove(2)        // removes 3rd element
print nums             

```

> 25


```elpl

use elpl.sys.io // Introducing standard library for I/O
//example use
let dataFile be "myData.cpp"
io.write(dataFile, "#include <iostream> int main(){ return 0;}")
let content be io.read(dataFile)
print content

```

> 26

```elpl


use elpl.sys.io
let file be "Test.java"
try {
io.write(file, "public class Test { // check java}")
io.append(file, "public static void main(String[] mine){}")
io.delete(file)
let content be io.readLines(file)
print content
} catch error {
print "Error: "error
}

```
## CLASSES


> 27

```elpl

class myclass {
    public let name

    function myclass(newName) {
        this.name be newName
    }

    function greet() {
        print "Hello," this.name
    }
}
myclass p be new myclass("Ishaq")
p.greet()

```

> 28

```elpl

Array board be [
  1,0,0,4,
  0,0,0,0,
  0,0,0,0,
  3,0,0,2
]

function get(board, row, col): int {
  return board[row multiply 4 add col]
}

function set(board, row, col, value): void {
  let board[row multiply 4 add col] be value
}

function isSafe(board, row, col, num): boolean {
  // row check
  for c be 0 to 3 {
    if get(board, row, c) is equal to num then {
      return false
    }
  }
  // col check
  for r be 0 to 3 {
    if get(board, r, col) is equal to num then {
      return false
    }
  }
  // 2x2 subgrid
  let startRow be row subtract (row mod 2)
  let startCol be col subtract (col mod 2)
  for r be 0 to 1 {
    for c be 0 to 1 {
      if get(board, startRow add r, startCol add c) is equal to num then {
        return false
      }
    }
  }
  return true
}

function solve(board): bool {
  for row be 0 to 3 {
    for col be 0 to 3 {
      if get(board, row, col) is equal to 0 then {
        // try numbers 1 to 4
        for num be 1 to 4 {
          if isSafe(board, row, col, num) then {
            set(board, row, col, num)
            if solve(board) then {
              return true
            }
            set(board, row, col, 0)
          }
        }
        return false
      }
    }
  }
  return true
}

function Print(board): void {
  for r be 0 to 3 {
    for c be 0 to 3 {
      print get(board, r, c) " "
    }
    printnl " "
  }
}

if solve(board) is equal to true then {
  Print(board)
} otherwise {
  print "No solution found."
}

```

### If you facing weird compiler errors, try explicitly declaring types to get rid of it.

> 29

```elpl

Array board be [
  1, 0, 0, 0, 0, 0, 0, 2,
  0, 0, 0, 0, 3, 0, 0, 0,
  0, 0, 0, 4, 0, 0, 0, 0,
  0, 5, 0, 0, 0, 6, 0, 0,
  0, 0, 7, 0, 0, 0, 4, 0,
  0, 0, 0, 0, 5, 0, 0, 0,
  0, 0, 0, 0, 0, 8, 0, 0,
  3, 0, 0, 0, 0, 0, 0, 1
]

function get(board, row, col): int {
  return board[row multiply 8 add col]
}

function set(board, row, col, value): void {
  let board[row multiply 8 add col] be value
}

function isSafe(board, row, col, num): boolean {
  // row check
  for c be 0 to 7 {
    if get(board, row, c) is equal to num then {
      return false
    }
  }
  // col check
  for r be 0 to 7 {
    if get(board, r, col) is equal to num then {
      return false
    }
  }
  // subgrid check (2x4)
  let startRow be row subtract (row mod 2)
  let startCol be col subtract (col mod 4)
  for r be 0 to 1 {
    for c be 0 to 3 {
      if get(board, startRow add r, startCol add c) is equal to num then {
        return false
      }
    }
  }
  return true
}

function solve(board): boolean {
  for row be 0 to 7 {
    for col be 0 to 7 {
      if get(board, row, col) is equal to 0 then {
        for num be 1 to 8 {
          if isSafe(board, row, col, num) then {
            set(board, row, col, num)
            if solve(board) is equal to true then {
              return true
            }
            set(board, row, col, 0)
          }
        }
        return false
      }
    }
  }
  return true
}

function Print(board): void {
  for r be 0 to 7 {
    for c be 0 to 7 {
      print " " get(board, r, c)
    }
    printnl " "
  }
}

if solve(board) is equal to true then {
  Print(board)
} otherwise {
  print "No solution found."
}
```

> 30


```elpl

Array<Array<Int>> board be [
  [1, 0, 0, 0, 0, 0, 0, 2],
  [0, 0, 0, 0, 3, 0, 0, 0],
  [0, 0, 0, 4, 0, 0, 0, 0],
  [0, 5, 0, 0, 0, 6, 0, 0],
  [0, 0, 7, 0, 0, 0, 4, 0],
  [0, 0, 0, 0, 5, 0, 0, 0],
  [0, 0, 0, 0, 0, 8, 0, 0],
  [3, 0, 0, 0, 0, 0, 0, 1]
]

function isSafe(Array<Array<Int>> board, Int row, Int col, Int num): Boolean {
  // row check
  for c be 0 to 7 {
    if board[row][c] is equal to num then {
      return false
    }
  }
  // col check
  for r be 0 to 7 {
    if board[r][col] is equal to num then {
      return false
    }
  }
  // subgrid check (2x4)
  let startRow be row subtract (row mod 2)
  let startCol be col subtract (col mod 4)
  for r be 0 to 1 {
    for c be 0 to 3 {
      if board[startRow add r][startCol add c] is equal to num then {
        return false
      }
    }
  }
  return true
}

function solve(Array<Array<Int>> board): Boolean {
  for row be 0 to 7 {
    for col be 0 to 7 {
      if board[row][col] is equal to 0 then {
        for num be 1 to 8 {
          if isSafe(board, row, col, num) then {
            let board[row][col] be num
            if solve(board) is equal to true then {
              return true
            }
            let board[row][col] be 0
          }
        }
        return false
      }
    }
  }
  return true
}

function Print(Array<Array<Int>> board): Void {
  for r be 0 to 7 {
    for c be 0 to 7 {
      print " " board[r][c]
    }
    printnl " "
  }
}

if solve(board) is equal to true then {
  Print(board)
} otherwise {
  print "No solution found."
}

```

> 31


```elpl

let day be 0
switch(day){
case 1 => print "Monday"
case 2 => print "Tuesday"
case 3 => print "Wednesday"
default => print "Other day"
}

```

> 32


```elpl
 let counter be 0
      Thread t1 {
   for i be 1 to 3 {
       counter pels 1
      printnl "T1 incremented: " counter
    nl
    sleep => 100
  } 
 }
  Thread t2 {
  for i be 1 to 3 {
   counter pels 1
   printnl "T2 incremented: " counter
      nl
    sleep => 150
    }
 }
    printnl "Counting started"
   nl
  join t1
  join t2
    printnl "Counting finished"
   nl
printnl "Final counter: " counter

```

> 33

Constructors overload

```elpl

class Person {
    public let name

    function Person(){
        this.name be "Unknown"
    }
     
         function Person(name){
              this.name be name
          }
             function greet(){
                return "Hello, "this.name
          }
      } 
      
Person p1 be new Person()
print p1.name
nl
Person p2 be new Person("Alice")
print p2.greet()

```

> 34


```elpl

class Animal { 

    public let type: string
    public let name: string
    public let age: int

      function Animal(type,name,age){
          this.type be type 
          this.name be name 
          this.age be age 
       } 
            function animalData(): string {
              return "My pet is a: " this.type" , his name is: "this.name", he's "this.age" years old." 
        } 
   } 
    Animal p be new Animal("Cat", "Snow", 5) 

   print p.animalData()

   ```

   > 35


   ```elpl

   let score be 85

if score is greater than or equal to 90 then {
    print "A"
}
otherwise if score is greater than or equal to 80 then {
    print "B"
}
otherwise if score is greater than or equal to 70 then {
    print "C"
}
otherwise if score is greater than or equal to 60 then {
    print "D"
}
otherwise {
    print "F"
}

```

> 36


```elpl
// keep files names matched with class names, if you're defining like this.
class University {

    class Student {

        public let name

        function Student(name): void {

            this.name be name

        }

        function greet(): string {

            return "Hi, I'm " this.name

        }

    }

}

University.Student s be new University.Student("Alice")

print s.greet()

```

> 37


```elpl


class Animal { 
    public let type: string
    public let name: string
    public let age: int

    function Animal(type, name, age): void {
        this.type be type 
        this.name be name 
        this.age be age 
    } 
        
    function animalData(): string {
        return "My pet is a: " this.type " , his name is: " this.name ", he's " this.age " years old." 
    } 
} 

function main(Array<string> args) {
    // Pass type, name, and age directly from the command line
    Animal p be new Animal(args[0], args[1], args[2]) 
    print p.animalData()
}

```

> 38

```elpl


// Another example

class Animal {

    function speak() {
        return "Animal"
    }

}

class Dog extends Animal {

    function speak() {
        return super.speak() // new
    }

}

let d be new Dog()

print d.speak() // output: Animal

```

> 39

```elpl

class Animal {

    function speak() {
        return "Animal"
    }

}

class Dog extends Animal {

    function speak() {
        return super.speak() " -> Dog"
    }

}

let d be new Dog()

print d.speak() 

```

> 40

```elpl

class Animal {

    public let name: String

    function Animal(){
        this.name be "Buddy"
    }

    function info(): String {
        return this.name
    }

}

class Dog extends Animal {

    function info(): String{
        return super.info()
    }

}

Dog d be new Dog()

print d.info()

```

> 41

```elpl

class Animal {
    function animalSound() {
    printnl "The animal makes a sound"
     }
}
class Dog extends Animal  {
      function animalSound(){
      super.animalSound() //. Use of 'super'
      print "The dog says: bow bow"
    }
  }
let myDog be new Dog()
 myDog.animalSound()

 ```

 > 42


 ```elpl

 class Animal {
    public let name
    function Animal() {
     this.name be "Unknown"
    }
    function info() {
    return "Hi," this.name
   }
  }
class Dog extends Animal {
    }
    
let d be new Dog()
d.name be "Buddy"
print d.info() 

```

> 43


```elpl

class Animal  {
    function Animal(){
    printnl "Animal is created"
   }
  }
class Dog extends Animal {
    function Dog() {
     super() // super constructor  <============    
     print "Dog is created"
   }
  }
let dog be new Dog()

```

> 44

```elpl

class Animal {
    public let name: String

    function Animal(String name) {
      this.name be name
    }
  }

class Dog extends Animal {

    public let breed: String

      function Dog(String name, String breed) {
          super(name)
        this.breed be breed
     }
  }
    Dog dog be new Dog("Buddy", "Labrador")
      printnl dog.name
      print dog.breed

```

> 45


```elpl

class Person {

     private function secret() {
        print "hidden"
    }

    function reveal(){
       this.secret()
    }

}

Person p be new Person()

 p.reveal()     

//p.secret() //this will fail

```

> 46


```elpl

class Animal {

    function speak(){

        return "animal"

    }

}


class Dog extends Animal {

    @override // override annotation to check for function overrides
    function speak(){

        return "dog"

    }

}


let a be new Dog()

print a.speak()

```

> 47


```elpl

class Person {
     protected function getAge(){
      return 25
    }
 }
class Employee extends Person {
     public function printAge(){
     print this.getAge()
   }
 }
Employee e be new Employee()
e.printAge()

```

> 48


```elpl

class Math {
    // also field static ‘private static let a’
     public static function Add(a,b){
         return a add b
       }
  }
print Math.Add(5,10)

```

> 49


```elpl

abstract class Shape {

    abstract function area()

    abstract function perimeter()

}

class Rectangle extends Shape {

    function area() {
        return 50
    }

    function perimeter() {
        return 30
    }

}

let r be new Rectangle()

printnl r.area()
print r.perimeter()

```

> 50


```elpl

abstract class Animal {

    function eat() {
        return "Eating"
    }

    abstract function speak()

}

class Dog extends Animal {

    function speak() {
        return "Woof"
    }

}

let d be new Dog()

printnl d.eat()
print d.speak()

```

> 51

```elpl

interface Animal {
    function speak()
}

class Dog implements Animal {

    function speak() {
        return "dog"
    }

}


class Puppy extends Dog {

}




Animal b be new Puppy()

//Dog c be new Puppy()

```

> 52

```elpl
class Math {

    public static float PI be 3.14

    public static function square(x) {
        return x multiply x
    }

}

printnl Math.PI
print Math.square(5)

```

> 53


```elpl

enum Color {
      RED,
     GREEN
   }
     Color c be Color.GREEN

    switch(c) {
       case RED =>
         print "red"
       case GREEN =>
        print "green"
       default =>
        print "default case" 
   }

   ```

   > 54


   ```elpl

   enum Color(label, code) {
   RED("red", 1),
   GREEN("green", 2),
   BLUE("blue", 3)
}
printnl Color.RED.name()
printnl Color.RED.ordinal()
printnl Color.RED.label
print Color.RED.code

```

> 55

```elpl
Array<int> a be [
    [1,2],
    [3,4]
]

a[1][0] be 10

```

> 56

```elpl

interface Flyable {
    function fly(): String
}

interface Runnable {
    function run(): String
}

interface AnimalInterface {
    function speak(): String
}

interface DogLike extends AnimalInterface {
    function bark(): Void
}

abstract class Shape {
    abstract function area(): Int
    abstract function perimeter(): Int
}

abstract class BaseAnimal implements DogLike {
    function eat(): String {
        return "Eating..."
    }

    abstract function speak(): String

    abstract function bark(): Void
}

class Rectangle extends Shape {
    private let width: Int
    private let height: Int

    function Rectangle(Int w, Int h) {
        this.width be w
        this.height be h
    }

    function area(): Int {
        return this.width multiply this.height
    }

    function perimeter(): Int {
        return 2 multiply (this.width add this.height)
    }
}

class Person {
    protected let age: Int

    function Person(Int initialAge) {
        this.age be initialAge
    }

    public function getAge(): Int {
        return this.age
    }

    public function setAge(Int newAge): Void {
        if newAge is greater than or equal to 0 then {
            this.age be newAge
        } otherwise {
            printnl "Age cannot be negative!"
        }
    }
}

class Employee extends Person {
    private let salary: Int

    function Employee(Int initialAge, Int initialSalary) {
        super(initialAge)
        this.salary be initialSalary
    }

    public function printAge(): Void {
        print "Employee Age: "
        printnl this.getAge()
    }
}

class Dog extends BaseAnimal {
    
    @override
    function speak(): String {
        return "Woof!"
    }

    function bark(): Void {
        printnl "Bark! Bark!"
    }
}

class Bird implements Flyable, Runnable {
    
    public function fly(): String {
        return "flying high in the sky"
    }

    public function run(): String {
        return "running fast on the ground"
    }
}


class MathUtils {
    public static Float PI be 3.14

    public static function Add(Int a, Int b): Int {
        return a add b
    }

    public static function Multiply(Int a, Int b): Int {
        return a multiply b
    }
}


printnl "=== 1. Testing Person & Employee ==="
Person person be new Person(26)
print "Person's age is: "
printnl person.getAge()

Employee emp be new Employee(30, 75000)
emp.printAge()


printnl "=== 2. Testing Static Utility Methods ==="
print "MathUtils.Add(5, 10) = "
printnl MathUtils.Add(5, 10)

print "MathUtils.Multiply(4, 6) = "
printnl MathUtils.Multiply(4, 6)


printnl "=== 3. Testing Abstract Classes & Shapes ==="
Rectangle rect be new Rectangle(5, 10)
print "Rectangle Area: "
printnl rect.area()
print "Rectangle Perimeter: "
printnl rect.perimeter()


printnl "=== 4. Testing Abstract Base Animal & Dog ==="

BaseAnimal myDog be new Dog()


print "Dog Action: "
printnl myDog.eat()
print "Dog Sound: "
printnl myDog.speak()
myDog.bark()


printnl "=== 5. Testing Multiple Interfaces (Bird) ==="
Bird myBird be new Bird() // Bird implements both Flyable and Runnable, so created object for Bird instead of Runnable or Flyable
print "Bird Flying: "
printnl myBird.fly()
print "Bird Running: "
printnl myBird.run()



```

> 57


```elpl

let name be "John"
let age be 20

@java{
    age += 5;
    name = name.toUpperCase();
}

printnl age
printnl name

```

> 58

```elpl

class BankAccount {

    private function secretMessage() {
        return "Private method works!"
    }

    public function test(): String {
        return this.secretMessage()
    }
}

BankAccount account be new BankAccount()

printnl account.test()

```

> 59

```elpl

class BankAccount {

    private function secretMessage() {
        return "You should not see this"
    }
}

BankAccount account be new BankAccount()

printnl account.secretMessage()

```

> 60

```elpl

class Parent {

    protected function greet(): String {
        return "Hello from Parent"
    }
}

class Child extends Parent {

    public function test(): String { 
        return this.greet()
    }
}

Child child be new Child()

printnl child.test()

```
> 61

```elpl
class Parent {

    protected function secret(): String {
        return "Protected"
    }
}

class Other {

    public function test(Parent p) {
        return p.secret()
    }
}

Parent parent be new Parent()
Other other be new Other()

printnl other.test(parent)

```

> 62


```elpl

class Animal {

    public function speak() {
        return "Animal sound"
    }
}

class Dog extends Animal {
}

Dog dog be new Dog()

printnl dog.speak()

```

> 63

```elpl
class Animal {

    public function speak() {
        return "Animal"
    }
}

class Dog extends Animal {

    @override
    public function speak() {
        return "Woof"
    }
}

Animal animal be new Dog()

printnl animal.speak()

```

> 64

```elpl

class A {

    protected let value

    function A() {
        this.value be 100
    }

    protected function getValue() {
        return this.value
    }
}

class B extends A {

    function B() {
        super()
    }
}

class C extends B {

    public function test() {
        return this.getValue()
    }
}

C c be new C()

printnl c.test()

```

> 65

```elpl

class Person {

    private let name: String

    function Person(String n) {
        this.name be n
    }

    public function getName(): String {
        return this.name
    }
}

Person p be new Person("John")

printnl p.getName()

```

> 66


```elpl

class Person {
    protected let age

    function Person(a) {
        this.age be a
    }
}

class Employee extends Person {
    function Employee(a) {
        super(a)
    }

    public function getAge() {
        return this.age
    }
}

Employee e be new Employee(30)
printnl e.getAge()

```

> 67


```elpl

class Person {

    public let name: String

    function Person(String n) {
        this.name be n
    }
}

Person p be new Person("John")

printnl p.name

```

> 68


```elpl

class Animal {

    protected let name: String

    function Animal(String n) {
        this.name be n
    }
}

class Dog extends Animal {

    function Dog(String n) {
        super(n)
    }

    public function getName(): String {
        return this.name
    }
}

Dog d be new Dog("Buddy")

printnl d.getName()

```

> 69


```elpl

class Parent {

    protected let parentValue

    function Parent(value) {
        this.parentValue be value
    }
}

class Child extends Parent {

    private let childValue

    function Child(parentValue, childValue) {
        super(parentValue)
        this.childValue be childValue
    }

    public function test() {
        print "Parent = "
        printnl this.parentValue

        print "Child = "
        printnl this.childValue
    }
}

Child c be new Child(10, 20)

c.test()

```

> 70


```elpl

interface Speaker {
    function speak()
}

class Dog implements Speaker {

    function speak() {
        return "Woof"
    }
}

class Cat implements Speaker {

    function speak() {
        return "Meow"
    }
}

Speaker a be new Dog()
Speaker b be new Cat()

printnl a.speak()
printnl b.speak()

```

> 71


```elpl

class Config {

    public final let version be 1

    function change() {
        this.version be 2
    }
}

Config c be new Config()

c.change()

```

> 72


```elpl

class Config {

    public final let version

    function Config(v) {
        this.version be v
    }

    public function getVersion() {
        return this.version
    }
}

Config c be new Config(10)

printnl c.getVersion()

```

> 73

```elpl

class Engine {

    public function start() {
        return "Engine started"
    }
}

class Car {

    private let engine: Engine

    function Car(e) {
        this.engine be e
    }

    public function startCar(){
        return this.engine.start()
    }
}

Engine engine be new Engine()
Car car be new Car(engine)

printnl car.startCar()

```

> 74


```elpl

interface Logger {
    function log(String message)
}

class ConsoleLogger implements Logger {
     @override
    function log(message): Void {
        print "CONSOLE: "
        printnl message
    }
}

class FileLogger implements Logger {
     @override
    function log(String message) {
        print "FILE: "
        printnl message
    }
}

class Application {

    private let logger: Logger  // 🔥 Native ELPL syntax: Type followed by variable name

    function Application(Logger l) {
        this.logger be l
    }

   public function run(): Void {
    this.logger.log("Application started")
   
  }

}

Logger logger be new ConsoleLogger()

Application app be new Application(logger)

app.run()

```

> 75

```elpl

interface Logger {
    function log(String message)
}

class ConsoleLogger implements Logger {
     @override
    function log(String message): Void {
        print "CONSOLE: "
        printnl message
    }
}

class FileLogger implements Logger {
     @override
    function log(String message) {
        print "FILE: "
        printnl message
    }
}

class Application {

    private let logger: Logger 

    function Application(Logger l) {
        this.logger be l
    }

   public function run(): Void {
    this.logger.log("Application started")
   
  }

}

Logger logger be new FileLogger()

Application app be new Application(logger)

app.run()

```

> 76


```elpl

interface PaymentProcessor {
    function processPayment(int amount): Void
}

class CreditCardProcessor implements PaymentProcessor {
    public function processPayment(int amount): Void {
        print "Charged $"
        print amount
        printnl " securely via Credit Card Gateway."
    }
}

class CryptoProcessor implements PaymentProcessor {
    public function processPayment(int amount): Void {
        print "Transferred $"
        print amount
        printnl " equivalent via Crypto Smart Contract."
    }
}

// ==========================================
// 2. Abstract Classes & Encapsulation
// ==========================================

abstract class SmartDevice {
    public let deviceId: String
    public let powerDraw: int
    public let isOn: boolean

    function initDevice(String id, int power): Void {
        this.deviceId be id
        this.powerDraw be power
        this.isOn be false
    }

    public function togglePower(): boolean {
        if this.isOn then {
            this.isOn be false
            print "Device "
            print this.deviceId
            printnl " is now OFF."
        } otherwise {
            this.isOn be true
            print "Device "
            print this.deviceId
            printnl " is now ON."
        }
        return this.isOn
    }

    public function getPowerStatus(): boolean {
        return this.isOn
    }

    abstract function operate(): Void
}

// ==========================================
// 3. Inheritance & Implementation
// ==========================================

class SmartThermostat extends SmartDevice {
    private let targetTemp: String

    function SmartThermostat(String id, int power, String temp) {
        this.initDevice(id, power)
        this.targetTemp be temp
    }

    public function operate(): Void {
        if this.getPowerStatus() then {
            print "Thermostat "
            print this.deviceId
            print " regulating temperature to "
            print this.targetTemp
            printnl " degrees."
        } otherwise {
            print "Thermostat "
            print this.deviceId 
            printnl " is off. Turn it on first."
        }
    }
}

// ==========================================
// 4. Composition (Using Setter Injection)
// ==========================================

class SmartHomeHub {
    private let hubName: String
    private let paymentEngine: PaymentProcessor
    private let activeDevice: SmartDevice

    function SmartHomeHub(String name) {
        this.hubName be name
    }

    public function setPaymentEngine(PaymentProcessor processor): Void {
        this.paymentEngine be processor
    }

    public function setDevice(SmartDevice device): Void {
        this.activeDevice be device
    }

    public function runRoutine(): Void {
        this.activeDevice.togglePower()
        this.activeDevice.operate()
    }

    public function payBill(int amount): Void {
        printnl "--- Processing Utility Bill ---"
        this.paymentEngine.processPayment(amount)
    }
}

// ==========================================
// 5. Execution Flow
// ==========================================

printnl "=== 1. Setting up Smart Thermostat ==="
SmartThermostat nest be new SmartThermostat("TH-01", 15, "22")

printnl "=== 2. Setting up Payment Processors ==="
CryptoProcessor crypto be new CryptoProcessor()
CreditCardProcessor card be new CreditCardProcessor()

printnl "=== 3. Initializing Composition Hub ==="
SmartHomeHub myHome be new SmartHomeHub("Villa Hub")

myHome.setDevice(nest)
myHome.setPaymentEngine(crypto)

printnl "=== 4. Executing System Logic ==="
myHome.runRoutine()
myHome.payBill(45)

printnl ""
printnl "=== 5. Demonstrating Polymorphism (Swapping Processors) ==="
myHome.setPaymentEngine(card)
myHome.payBill(120)

```

> 77

```elpl

interface PaymentProcessor {
    function processPayment(Int amount)
}

class CreditCardProcessor implements PaymentProcessor {
    public function processPayment(Int amount) {
        print "Charged $"
        print amount
        printnl " securely via Credit Card Gateway."
    }
}

class CryptoProcessor implements PaymentProcessor {
    public function processPayment(Int amount) {
        print "Transferred $"
        print amount
        printnl " equivalent via Crypto Smart Contract."
    }
}

// ==========================================
// 2. Abstract Classes & Encapsulation
// ==========================================

abstract class SmartDevice {
    public let deviceId: String
    protected let powerDraw: Int
    public let isOn: Boolean

    function SmartDevice(String id, Int power) {
        this.deviceId be id
        this.powerDraw be power
        this.isOn be false
    }

    public function togglePower(): Boolean {
        if this.isOn then {
            this.isOn be false
            print "Device "
            print this.deviceId
            printnl " is now OFF."
        } otherwise {
            this.isOn be true
            print "Device "
            print this.deviceId
            printnl " is now ON."
        }
        return this.isOn
    }

    public function getPowerStatus(): Boolean {
        return this.isOn
    }

    abstract function operate()
}

// ==========================================
// 3. Inheritance & Implementation
// ==========================================

class SmartThermostat extends SmartDevice {
    private let targetTemp: String

    function SmartThermostat(String id, Int power, String temp) {
        super(id, power)
        this.targetTemp be temp
    }

    @override
    public function operate() {
        if this.getPowerStatus() then {
            print "Thermostat "
            print this.deviceId
            print " regulating temperature to "
            print this.targetTemp
            printnl " degrees."
        } otherwise {
            print "Thermostat "
            print this.deviceId
            printnl " is off. Turn it on first."
        }
    }
}

// ==========================================
// 4. Composition (Has-A Relationships)
// ==========================================

class SmartHomeHub {
    private let hubName: String
    private let device1: SmartDevice
    private let paymentEngine: PaymentProcessor

    function SmartHomeHub(String name, PaymentProcessor processor) {
        this.hubName be name
        this.paymentEngine be processor
    }

    public function setDevice(SmartDevice device) {
        this.device1 be device
        print "Added "
        print device.deviceId
        print " to "
        printnl this.hubName
    }

    public function runRoutine() {
        printnl ""
        print "--- Running Routine on "
        print this.hubName
        printnl " ---"
        
        this.device1.togglePower()
        this.device1.operate()
    }

    public function payElectricityBill(Int amount) {
        printnl ""
        printnl "--- Processing Utility Bill ---"
        this.paymentEngine.processPayment(amount)
    }
}

// ==========================================
// 5. Explicit Entry-Point Execution Block
// ==========================================

class My {
    public static function Start() {
        printnl "=== Initializing Polymorphic Payments ==="
        CryptoProcessor cryptoEngine be new CryptoProcessor()

        printnl "=== Initializing Composition Hub ==="
        SmartHomeHub myHome be new SmartHomeHub("Villa Hub", cryptoEngine)

        printnl "=== Instantiating Inherited Objects ==="
        SmartThermostat nestThermostat be new SmartThermostat("TH-01", 15, "21")

        printnl "=== Building System Relationships ==="
        myHome.setDevice(nestThermostat)

        printnl "=== Simulating Ecosystem Logic ==="
        myHome.runRoutine()
        myHome.payElectricityBill(45)
    }
}

// Run the script directly through the static runner
My.Start()

```

> 78


```elpl

Queue<String> tasks be {}

tasks.affix("First")
tasks.affix("Second")
tasks.affix("Third")

printnl tasks.peek()
printnl tasks.poll()
printnl tasks.poll()
printnl tasks.peek()
print tasks.size()

```

> 79

```elpl

Set numbers be {}

numbers.include(10)
numbers.include(20)
numbers.include(10)
numbers.include(30)

printnl numbers
printnl numbers.contains(20)
printnl numbers.contains(50)
printnl numbers.size()

numbers.remove(20)

print numbers

```

> 80


```elpl

let x be 5
let y be 10

printnl "Initial values: " x " and " y

if x is less than y then{
  printnl "x is less than y"
}otherwise{
  printnl "x is not less than y"
}
repeat 3 times {
  printnl "Repeating" x
}

while x is less than 10 {
  printnl "Incrementing x:" x;
  x pels 1
}

function greet() {
  printnl "Hello from function!"
}

greet()

let result be y multiply x
printnl "x * y = " result

let condition be true
if condition is equal to true then{
  printnl "Condition is true"
  }otherwise{
  printnl "Condition is false"
}
let a be not false
printnl "a (not false) = " a

```

> 81

```elpl

Array nums be [2, 7, 11, 15]
let target be 9
let found be false
let sums be 0

for i be 0 to length(nums){
    for j be i add 1 to length(nums){
       

        sums be nums[i] add nums[j];
        print "checking pair: " i j " sum: " sums
        if sums is equal to target then {
            print "indices: " i j;
            found be true
            stop
        } otherwise{
        print "pair no found"
        }
    }
   
        stop
    
}

```

> 82


```elpl

Array nums be [2, 7, 11, 15]
let target be 9
let found be false
Array result be [-1, -1]
let sums be 0

for i be 0 to length(nums) subtract 1 {
    for j be i add 1 to length(nums) subtract 1 {
        sums be nums[i] add nums[j];
        print "checking pair:" i j "sum:" sums

        if sums is equal to target then {
            found be true
            let result[0] be i
            let result[1] be j
            stop
        }
    }
    if found is equal to true then {
        stop
    }
}

if found is equal to true then {
    print "indices: " result[0] result[1]
} otherwise {
    print "no pair found"
}

```

> 83

```elpl

Array nums be [3, 9, 12,11]
Array reversed be []

for i be 0 to length(nums){
    let reversed[i] be nums[length(nums) subtract 1 subtract i]
}

print reversed

```
> 84


```elpl

Array nums be [2, 7, 11, 15]
let n be length(nums)
let mid be n divide 2
let temp be 0
for i be 0 to mid subtract 1 {
    temp be nums[i]
    let nums[i] be nums[n subtract 1 subtract i]
    let nums[n subtract 1 subtract i] be temp
}

print nums

```

> 85


```elpl

function power(x, n) {
    if n is equal to 0 then {
        return 1
    }
    return x multiply power(x, n subtract 1)
}

print power(2, 4) 

```

> 86


```elpl

function sumArray(Array<int> arr, i) {
    if i is equal to length(arr) then {
        return 0
    }
    return arr[i] add sumArray(arr, i add 1)
}

Array<int> nums be [1, 2, 3, 4, 5]
print sumArray(nums, 0)

```

> 86


```elpl

Array nums be [-1, 0, 1, 2, -1, -4]
let sums be 0

for i be 0 to length(nums) subtract 3 {
  for j be i add 1 to length(nums) subtract 2 {
    for k be j add 1 to length(nums){
      sums be nums[i] add nums[j] add nums[k]
     print "checking triple: " i j k " sum: " sums
     if sums is equal to 0 then {
       print "FOUND triple at indices: " i j k " sum: " sums

  stop
}

       otherwise {
        print "not a valid triple"
      }
    }
stop
   
  }
stop
 
}

```

> 87


```elpl

Array nums be [-2, -1, 0, 1, 2, 3]
let target be 3


for i be 0 to length(nums) subtract 5 {
 for j be i add 1 to length(nums) subtract 4 {
  for k be j add 1 to length(nums) subtract 3 {
   for l be k add 1 to length(nums) subtract 2 {
    for m be l add 1 to length(nums){
     let sums be nums[i] add nums[j] add nums[k] add nums[l] add nums[m]
     print "checking quintuple: " i j k l m " sum: " sums
     if sums is equal to target then {
      print "FOUND quintuple at indices: " i j k l m " sum: " sums
    
      stop
     } otherwise {
     print "not found"
     } 
    }
    stop
   }
   
  }
  stop
 }
 stop
}

```

> 88


```elpl

function fib(Int n): Int{
if n is less than or equal to 1 then {
return n
} otherwise {
 let a be fib(n subtract 1)
 let b be fib(n subtract 2)
 return a add b
}



}

for i be 0 to 30{
printnl fib(i)
}  

```

> 89


```elpl

function subsetSum(Array<Int> nums, Int index, Int target) {
    print "subsetSum called with index = " index ", target = " target

    if target is equal to 0 then {
        print "Target reached 0 — returning true"
        return true
    }

    if index is equal to length(nums) then {
        print "Reached end of array — returning false"
        return false
    }

    if nums[index] is less than or equal to target then {
        print "Trying including nums[" index "] = " nums[index]
        if subsetSum(nums, index add 1, target subtract nums[index]) then {
            print "Path including nums[" index "] worked — returning true"
            return true
        }
    }

    print "Trying excluding nums[" index "] = " nums[index]
    let Result: Boolean be subsetSum(nums, index add 1, target)
    print "Result after excluding nums[" index "]: " result
    return result
}

Array<Int> nums be [3, 4, 5, 2]
let target: Int be 9
let result: Boolean be subsetSum(nums, 0, target)
print "Final result: " result

```

> 90

```elpl

function fib(Int n) {
    if n is equal to 0 then {
        return 0
    }
    if n is equal to 1 then {
        return 1
    }
    let a: Int be fib(n subtract 1) 
    let b: Int be fib(n subtract 2)
    return a add b
}

let result: Int be fib(6)
print "Fib(6): " result

```

> 91


```elpl

function isPalindrome(Array<String> s, Int left, Int right) {
    if left is greater than or equal to right then {
        return true
    }

    if s[left] not equal to s[right] then {
        return false
    }

    return isPalindrome(s, left add 1, right subtract 1)
}

// Test case
Array<String> word be ["r", "a", "c", "e", "c", "a", "r"]
let result: Boolean be isPalindrome(word, 0, length(word) subtract 1)
print "Is Palindrome: " result

```

> 92


```elpl

Array nums be [[0,2,3],[2,3,4]]

let total be 0

for i be 0 to length(nums){
  for j be 0 to length(nums[i]){
     total pels nums[i][j] 
  }
}

print total  // output: 14

```

> 93

```elpl

Map[key,value] mymap be {1: "a", 2: "b", 3: "c", 5: "v"}

foreach k,v : mymap{
   print "key: "k "value: " v
} 

```

> 94

```elpl

let name be scan("Enter your name: ")

print "Hello, "name    // Hello, <your entry>

```

> 95

```elpl

Map[key,value] m be {1:"a", 2:"b"}


m.put(3, "c")
printnl m.size() 
printnl m.get(3)        //  3 c   
                     


Map[k,v] map be {1: "a", 2: "b"}
foreach k,v : m {             
   printnl k v
}

```

> 96

```elpl

Map[k,v] mymap be {1: "a", 2: "b"}

mymap.put(3, "c")       // add a new key-value
print mymap.size()       // 3

if mymap.has(2) then {
  print "key 2 exists"
}

mymap.delete(1)          // remove key 1
print mymap.has(1)       // false

mymap.clear()            // remove all entries
print mymap.size()       // 0

```

> 97


```elpl

function twoSum(Array<Int> nums, Int target): Array {
    Map<Int, Int> map be {} // initialize empty map
    
    // 1. Declare the variable once in the function scope
    let complement: Int

    for i be 0 to length(nums) {
        // 2. Reassign it inside the loop without 'let' or type prefix
        complement be target subtract nums[i]
        
        // check if complement exists in map
        if map.has(complement) then {
            return [map.get(complement), i]
        }
        
        // store current number with its index in map
        map.put(nums[i], i)
    }
    
    return [] // return empty array if no solution
}

// Example usage
Array<Int> nums be [2, 7, 11, 15]
let target: Int be 9
print "Indices: " twoSum(nums, target)

```

> 98


```elpl



List nums be [10, 20, 30]

// Heterogeneous types
List mixed be ["apple", true, 99]

// Nested lists
List<List<Int>> matrix be [[1, 2], [3, 4], [5, 6]]

// Expressions inside
List calc be [2 add 2, 5 multiply 3, length([1,2,3])]


print matrix
print calc
print nums

```

> 99


```elpl

List nums be [10, 20, 30]
nums.insert(1, 15)       // inserts 15 at index 1
nums.append(50)      // adds 40 at end
nums.remove(2)        // removes 3rd element
print nums  

```

> 100


```elpl

use elpl.sys.io // Introducing standard library for I/O
//example use
let dataFile be "myData.cpp"
io.write(dataFile, "#include <iostream> int main(){ return 0;}")

print io.read(dataFile)

```

> 101


```elpl

use elpl.sys.io
let file be "Test.java"
try {
io.write(file, "public class Test { // check java}")
io.append(file, "public static void main(String[] mine){}")
io.delete(file)
let content be io.readLines(file)
print content
} catch error {
print "Error: "error
}

```

> 102


```elpl

let day be 0
switch(day){
case 1 => print "Monday"
case 2 => print "Tuesday"
case 3 => print "Wednesday"
default => print "Other day"
}

```

> 103

```elpl

let score be 85

if score is greater than or equal to 90 then {
    print "A"
}
otherwise if score is greater than or equal to 80 then {
    print "B"
}
otherwise if score is greater than or equal to 70 then {
    print "C"
}
otherwise if score is greater than or equal to 60 then {
    print "D"
}
otherwise {
    print "F"
}

```

> 104


```elpl

enum Color {
      RED,
     GREEN
   }
     Color c be Color.GREEN

    switch(c) {
       case RED =>
         print "red"
       case GREEN =>
        print "green"
       default =>
        print "default case" 
   }


```

> 105


```elpl


enum Color(label, code) {
   RED("red", 1),
   GREEN("green", 2),
   BLUE("blue", 3)
}
printnl Color.RED.name()
printnl Color.RED.ordinal()
printnl Color.RED.label
print Color.RED.code
```


__ELPL is constantly adapting to new rules of the rigit architectures and developing environments. Please check documentation carefully to resolve issues in your code.__


> 106


```elpl

class Animal {

    protected let name: String

    function Animal(String n): Void {
        this.name be n
    }
}

class Dog extends Animal {

    function Dog(String n) {
        super(n)
    }

    public function getName(): String {
        return this.name
    }
}

Dog d be new Dog("Buddy")

printnl d.getName()

```

> 107


```elpl


interface PaymentProcessor {
    function processPayment(Int amount): Void
}

class CreditCardProcessor implements PaymentProcessor {
    public function processPayment(Int amount): Void {
        print "Charged $"
        print amount
        printnl " securely via Credit Card Gateway."
    }
}

class CryptoProcessor implements PaymentProcessor {
    public function processPayment(Int amount): Void {
        print "Transferred $"
        print amount
        printnl " equivalent via Crypto Smart Contract."
    }
}

// ==========================================
// 2. Abstract Classes & Encapsulation
// ==========================================

abstract class SmartDevice {
    public let deviceId: String
    public let powerDraw: Int
    public let isOn: Boolean

    function initDevice(String id, Int power): Void {
        this.deviceId be id
        this.powerDraw be power
        this.isOn be false
    }

    public function togglePower(): Boolean {
        if this.isOn then {
            this.isOn be false
            print "Device "
            print this.deviceId
            printnl " is now OFF."
        } otherwise {
            this.isOn be true
            print "Device "
            print this.deviceId
            printnl " is now ON."
        }
        return this.isOn
    }

    public function getPowerStatus(): Boolean {
        return this.isOn
    }

    abstract function operate(): Void
}

// ==========================================
// 3. Inheritance & Implementation
// ==========================================

class SmartThermostat extends SmartDevice {
    private let targetTemp: String

    function SmartThermostat(String id, Int power, String temp) {
        this.initDevice(id, power)
        this.targetTemp be temp
    }

    public function operate(): Void {
        if this.getPowerStatus() then {
            print "Thermostat "
            print this.deviceId
            print " regulating temperature to "
            print this.targetTemp
            printnl " degrees."
        } otherwise {
            print "Thermostat "
            print this.deviceId 
            printnl " is off. Turn it on first."
        }
    }
}

// ==========================================
// 4. Composition (Using Setter Injection)
// ==========================================

class SmartHomeHub {
    private let hubName: String
    private let paymentEngine: PaymentProcessor
    private let activeDevice: SmartDevice

    function SmartHomeHub(String name) {
        this.hubName be name
    }

    public function setPaymentEngine(PaymentProcessor processor): Void {
        this.paymentEngine be processor
    }

    public function setDevice(SmartDevice device): Void {
        this.activeDevice be device
    }

    public function runRoutine(): Void {
        this.activeDevice.togglePower()
        this.activeDevice.operate()
    }

    public function payBill(Int amount): Void {
        printnl "--- Processing Utility Bill ---"
        this.paymentEngine.processPayment(amount)
    }
}

// ==========================================
// 5. Execution Flow
// ==========================================

printnl "=== 1. Setting up Smart Thermostat ==="
SmartThermostat nest be new SmartThermostat("TH-01", 15, "22")

printnl "=== 2. Setting up Payment Processors ==="
CryptoProcessor crypto be new CryptoProcessor()
CreditCardProcessor card be new CreditCardProcessor()

printnl "=== 3. Initializing Composition Hub ==="
SmartHomeHub myHome be new SmartHomeHub("Villa Hub")

myHome.setDevice(nest)
myHome.setPaymentEngine(crypto)

printnl "=== 4. Executing System Logic ==="
myHome.runRoutine()
myHome.payBill(45)

printnl ""
printnl "=== 5. Demonstrating Polymorphism (Swapping Processors) ==="
myHome.setPaymentEngine(card)
myHome.payBill(120)

```


> 108


```elpl

// ------------------------------------------------------------
// Graph
//
//        A
//       / \
//      B   C
//     / \   \
//    D   E   F
// ------------------------------------------------------------

Map[k,v] graph be {
    "A": ["B", "C"],
    "B": ["D", "E"],
    "C": ["F"],
    "D": [],
    "E": [],
    "F": []
}


// ------------------------------------------------------------
// BFS
// ------------------------------------------------------------

// 1. Fully typed function signature (Map and String)
function bfs(Map graph, String start) {

    Queue queue be {}

    Set visited be {}

    queue.affix(start)
    visited.include(start)

    printnl "BFS traversal:"

    while not queue.isEmpty() {

        // 2. Explicitly type the extracted queue item instead of using 'let'
        let current: String be queue.remove()

        print current

        // 3. Explicitly type the iterator variable in the foreach loop
        foreach neighbor : graph.get(current) {

            if not visited.contains(neighbor) then {

                visited.include(neighbor)
                queue.affix(neighbor)
            }
        }
    }
}


// ------------------------------------------------------------
// Run BFS
// ------------------------------------------------------------

bfs(graph, "A")

printnl ""
printnl "========================================"
printnl "          BFS TEST COMPLETE"
printnl "========================================"

```

> 108


```elpl

use elpl.sys.time.LocalDate

printnl "========================================"
printnl "       ELPL LocalDate Test Suite"
printnl "========================================"


// ------------------------------------------------------------
// 1. Create dates
// ------------------------------------------------------------

printnl ""
printnl "--- Creating Dates ---"

LocalDate date1 be LocalDate.of(2026, 8, 10)
LocalDate date2 be LocalDate.of(2026, 12, 25)
LocalDate leapDate be LocalDate.of(2024, 2, 29)

print "Date 1: "
printnl date1

print "Date 2: "
printnl date2

print "Leap Date: "
printnl leapDate


// ------------------------------------------------------------
// 2. Current date
// ------------------------------------------------------------

printnl ""
printnl "--- Current Date ---"

LocalDate today be LocalDate.now()

print "Today: "
printnl today


// ------------------------------------------------------------
// 3. Date components
// ------------------------------------------------------------

printnl ""
printnl "--- Date Components ---"

print "Year: "
printnl date1.getYear()

print "Month: "
printnl date1.getMonthValue()

print "Day: "
printnl date1.getDayOfMonth()

print "Day of Week: "
printnl date1.getDayOfWeek()

print "Day of Year: "
printnl date1.getDayOfYear()

print "Leap year (2024): "
printnl leapDate.isLeapYear()

print "Leap year (2026): "
printnl date1.isLeapYear()


// ------------------------------------------------------------
// 4. Month/year lengths
// ------------------------------------------------------------

printnl ""
printnl "--- Month / Year Length ---"

print "February 2024 days: "
printnl leapDate.lengthOfMonth()

print "February 2024 year length: "
printnl leapDate.lengthOfYear()

print "August 2026 days: "
printnl date1.lengthOfMonth()

print "2026 year length: "
printnl date1.lengthOfYear()


// ------------------------------------------------------------
// 5. Adding days
// ------------------------------------------------------------

printnl ""
printnl "--- Plus / Minus Days ---"

LocalDate plusDays be date1.plusDays(10)
LocalDate minusDays be date1.minusDays(10)

print "Original: "
printnl date1

print "Plus 10 days: "
printnl plusDays

print "Minus 10 days: "
printnl minusDays


// ------------------------------------------------------------
// 6. Adding / removing weeks
// ------------------------------------------------------------

printnl ""
printnl "--- Plus / Minus Weeks ---"

print "Plus 2 weeks: "
printnl date1.plusWeeks(2)

print "Minus 2 weeks: "
printnl date1.minusWeeks(2)


// ------------------------------------------------------------
// 7. Adding / removing months
// ------------------------------------------------------------

printnl ""
printnl "--- Plus / Minus Months ---"

print "Original: "
printnl date1

print "Plus 2 months: "
printnl date1.plusMonths(2)

print "Minus 2 months: "
printnl date1.minusMonths(2)


// ------------------------------------------------------------
// 8. Date transformation
// ------------------------------------------------------------

printnl ""
printnl "--- Date Transformation ---"

print "Change year to 2030: "
printnl date1.withYear(2030)

print "Change month to December: "
printnl date1.withMonth(12)

print "Change day to 25: "
printnl date1.withDayOfMonth(25)


// ------------------------------------------------------------
// 9. Date comparisons
// ------------------------------------------------------------

printnl ""
printnl "--- Date Comparisons ---"

print "date1 before date2: "
printnl date1.isBefore(date2)

print "date1 after date2: "
printnl date1.isAfter(date2)

print "date1 equal date2: "
printnl date1.isEqual(date2)

print "date1 equal itself: "
printnl date1.isEqual(date1)


// ------------------------------------------------------------
// 10. Days between dates
// ------------------------------------------------------------

printnl ""
printnl "--- Date Difference ---"

// Number variables (math operations automatically infer 'I' / integer)
let daysToChristmas: Long be date2.toEpochDay() subtract date1.toEpochDay()

print "Days from date1 to date2: "
printnl daysToChristmas

let daysBack: Long be date1.toEpochDay() subtract date2.toEpochDay()

print "Days from date2 back to date1: "
printnl daysBack


// ------------------------------------------------------------
// 11. Date arithmetic consistency
// ------------------------------------------------------------

printnl ""
printnl "--- Arithmetic Consistency ---"

LocalDate future be date1.plusDays(30)
LocalDate back be future.minusDays(30)

print "Original: "
printnl date1

print "After +30 days: "
printnl future

print "After +30 then -30: "
printnl back

print "Returned to original: "
printnl date1.isEqual(back)


// ------------------------------------------------------------
// 12. Month-end handling
// ------------------------------------------------------------

printnl ""
printnl "--- Month-End Handling ---"

LocalDate januaryEnd be LocalDate.of(2026, 1, 31)

print "January 31: "
printnl januaryEnd

print "January 31 + 1 month: "
printnl januaryEnd.plusMonths(1)

print "January 31 + 2 months: "
printnl januaryEnd.plusMonths(2)


// ------------------------------------------------------------
// 13. Leap-year behavior
// ------------------------------------------------------------

printnl ""
printnl "--- Leap Year Behavior ---"

LocalDate leapYearDate be LocalDate.of(2024, 2, 29)

print "Leap date: "
printnl leapYearDate

print "Is leap year: "
printnl leapYearDate.isLeapYear()

print "One year later: "
printnl leapYearDate.plusMonths(12)


// ------------------------------------------------------------
// 14. String conversion
// ------------------------------------------------------------

printnl ""
printnl "--- String Conversion ---"

print "date1.toString(): "
printnl date1.toString()


// ------------------------------------------------------------
// 15. Real-world example
// ------------------------------------------------------------

printnl ""
printnl "--- Project Deadline Example ---"

LocalDate projectStart be LocalDate.of(2026, 8, 1)
LocalDate projectDeadline be LocalDate.of(2026, 9, 30)

print "Project starts: "
printnl projectStart

print "Project deadline: "
printnl projectDeadline

print "Days available: "
printnl projectDeadline.toEpochDay() subtract projectStart.toEpochDay()

if today.isBefore(projectDeadline) then {
    printnl "Project deadline has not passed."
} otherwise {
    printnl "Project deadline has passed."
}


// ------------------------------------------------------------
// Finished
// ------------------------------------------------------------

printnl ""
printnl "========================================"
printnl "       LocalDate Tests Completed"
printnl "========================================"

```

> 109

```elpl

// Declare the external C++ function
extern function double_value(Int val) : Int

let a be 21
printnl "ELPL: Sending variable 'a' to Pure C..."

// Call the C++ function natively
let result be double_value(a)

printnl "ELPL: Received result back: " result

// with --native LLVMCompiler(new backend)
```

> 110

```elpl

let age: Int be 20
let status: String be (age is greater than or equal to 18) ? "Adult" : "Minor"

printnl "Status: " status

// Testing short-circuiting: The divide-by-zero should never happen!
let safeMath: Int be (1 is equal to 1) ? 42 : (10 divide 0)
printnl "Safe Math: " safeMath

```

> 111

```elpl

package test;

class Testerr{
function main(Array<String> args): Void {
    let statusCode: Int be 500
    let debugMessage: String be "Internal Server Exception"

    print "Standard log output: App execution started."
    printnl ""

    // Testing printerr (no trailing newline)
    printerr "ERROR [" statusCode "]: "
    
    // Testing printerrnl (appends newline)
    printerrnl debugMessage

    // Single statement printerrnl
    printerrnl "⚠️ Warning: Database connection pool exceeded capacity."
}
}

```

> 112


```elpl

class LambdaTest {
    public static function main(Array<String> args): Void {
        let double_it be (x) => x multiply 2
        
        // This will naturally execute as a primitive without any reflection hacks!
        let result be double_it.applyAsInt(5)
        
        print "Result: "
        printnl result
    }
}

```