🌍 Pangea / Pang

Practical Code Examples

Code Examples

Learn Pangea through practical examples, from simple arithmetic to recursive functions.

1. Hello World

English Version

print " Hello, World! "

Italian Version

stampa " Ciao, Mondo! "

Output:

Hello, World!

2. Simple Arithmetic

Addition and Multiplication

print add 5 6
print multiply 7 8
print add multiply 2 3 4

Output:

11
56
10

Explanation:

3. Variables

Setting and Getting Variables

set "x" 10
set "y" 20
print get "x"
print add get "x" get "y"

Output:

10
30

How it works:

Variable Syntax Sugar ($name and name=)

x= 10
print $x
y= add $x 5
print $y

Output:

10
15

How it works:

4. Conditional Logic (if)

Simple If Statement

x= 15
if greater $x 10
    print " x is greater than 10 "
    print " x is not greater than 10 "

Output:

x is greater than 10

Syntax:

if <condition> <then-branch> <else-branch>

The if word takes exactly 3 arguments. Both branches are expressions that get evaluated only if selected.

5. Loops (while)

Count to 5

i= 1
while not greater $i 5 {
    print $i
    i= add $i 1
}

Output:

1
2
3
4
5

Explanation:

6. FizzBuzz

Classic FizzBuzz (English)

i= 1
while not greater $i 20 {
    if equal 0 modulus $i 15
        print " FizzBuzz "
        if equal 0 modulus $i 3
            print " Fizz "
            if equal 0 modulus $i 5
                print " Buzz "
                print $i
    i= add $i 1
}

Sample Output:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

FizzBuzz in Italian

metti "i" 1
mentre non maggiore prendi "i" 20 fai
    se uguale 0 modulo prendi "i" 15
        stampa " FizzBuzz ... multiplo di 15 "
        se uguale 0 modulo prendi "i" 3
            stampa " Fizz ... multiplo di 3 "
            se uguale 0 modulo prendi "i" 5
                stampa " Buzz ... multiplo di 5 "
                stampa prendi "i"
    metti "i" somma prendi "i" 1
fine

7. User-Defined Functions

Square Function

define_word "square" 1
    multiply @1 @1

print square 5
print square 12

Output:

25
144

Syntax Breakdown:

8. Recursive Functions

Factorial

define_word "factorial" 1
    if equal 0 @1
        1
        multiply @1 factorial add -1 @1

print factorial 0
print factorial 4
print factorial 5

Output:

1
24
120

How Recursion Works:

Fibonacci

define_word "fib" 1
    if not greater @1 1
        @1
        add fib add -1 @1 fib add -2 @1

print fib 0
print fib 1
print fib 5
print fib 10

Output:

0
1
5
55

9. String Literals

Quoted Literals with Escapes

name= "Alice"
print $name

define_word "greet" 1
    print @1

greet " Hello! "
print "line1\nline2"
print "tab:\tvalue"
print "quote: \"ok\""

Output:

Alice
Hello!
line1
line2
tab:    value
quote: "ok"

String Rules:

Strings are quoted with "...". Supported escapes are \", \\, \n, and \t.

10. File Includes

main.words

print " Loading factorial... "
! "factorial.words"

print " Computing factorial(5) "
print factorial 5

factorial.words

define_word "factorial" 1
    if equal 0 @1
        1
        multiply @1 factorial add -1 @1

Syntax:

! "<filename>" - Executes the specified file

The ! operator includes and runs another file's code.

11. do...end Blocks

Grouping Multiple Statements

x= 10

if greater $x 5 {
    print " x is greater than 5 "
    print " The value is: "
    print $x
} {
    print " x is not greater than 5 "
}

Output (when x = 10):

x is greater than 5
The value is:
10

Usage:

12. Complex Example: Prime Number Check

is_prime Function

define_word "is_divisible" 2
    equal 0 modulus @1 @2

define_word "is_prime" 1 {
    n= @1
    if not greater $n 1 {
        return false
    } {
        pass
    }
    i= 2
    while not greater multiply $i $i $n {
        if is_divisible $n $i {
            return false
        } {
            pass
        }
        i= add $i 1
    }
    return true
}

print is_prime 2
print is_prime 17
print is_prime 20

Output:

true
true
false

13. Bilingual Programs

The same logic in English and Italian:

English Italian
print stampa
add somma
multiply moltiplica
set / get metti / prendi
if se
while mentre
do / end fai / fine
define_word definisci_parola
argument argomento

⚠ Running Modes

To run Italian programs:

lua src/pangea1/main.lua italian program.parole

For English (default):

lua src/pangea1/main.lua program.words

Tips and Best Practices

💡 Formatting

💡 Debugging

💡 Performance

🎓 Next Steps

Explore the complete Language Reference to see all built-in words and their usage.