🌍 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:

4. Conditional Logic (if)

Simple If Statement

set "x" 15
if greater get "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

set "i" 1
while not greater get "i" 5 do
    print get "i"
    set "i" add get "i" 1
end

Output:

1
2
3
4
5

Explanation:

6. FizzBuzz

Classic FizzBuzz (English)

set "i" 1
while not greater get "i" 20 do
    if equal 0 modulus get "i" 15
        print " FizzBuzz "
        if equal 0 modulus get "i" 3
            print " Fizz "
            if equal 0 modulus get "i" 5
                print " Buzz "
                print get "i"
    set "i" add get "i" 1
end

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 argument 1 argument 1

print square 5
print square 12

Output:

25
144

Syntax Breakdown:

8. Recursive Functions

Factorial

define_word "factorial" 1
    if equal 0 argument 1
        1
        multiply argument 1 factorial add -1 argument 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 argument 1 1
        argument 1
        add fib add -1 argument 1 fib add -2 argument 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

set "name" "Alice"
print get "name"

define_word "greet" 1
    print argument 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 argument 1
        1
        multiply argument 1 factorial add -1 argument 1

Syntax:

! "<filename>" - Executes the specified file

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

11. do...end Blocks

Grouping Multiple Statements

set "x" 10

if greater get "x" 5 do
    print " x is greater than 5 "
    print " The value is: "
    print get "x"
end do
    print " x is not greater than 5 "
end

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 argument 1 argument 2

define_word is_prime 1 do
    set n argument 1
    if not greater get n 1
        false
        if equal get n 2
            true
            do
                set i 2
                set prime true
                while not greater get i multiply get n get n do
                    if greater multiply get i get i get n
                        set i multiply get n get n
                        do
                            if is_divisible get n get i
                                set prime false
                                dont nothing
                            set i add get i 1
                        end
                end
                get prime
            end
end

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.