Skip to content
Documentation

Examples

The examples/ folder in the repository holds one runnable program per language area. Each subsection below shows what the program demonstrates and what it prints, verified against luca 1.0.4 Beta. Run any of them after installing, from the repository root:

luca examples/hello.lucc
FileTeaches
examples/hello.luccFirst program: print, interpolation, reassignment
examples/arithmetic.luccNumeric arithmetic, exact decimals, precedence
examples/inference.luccType inference, none, clear()
examples/comparison.luccWorded comparisons across types
examples/conditional.luccif / else if / else, nesting, logic
examples/functions.luccParameters, defaults, return values, recursion
examples/loops.luccAll three loop forms, stop/skip
examples/collections.luccLists, tuples, sets, dictionaries
examples/modules/main.luccImporting a second file
examples/errors.lucctry/capture/finally, custom errors, raise
examples/ask.luccTyped input with ask
examples/stdlib.luccMath, Text, File, System
examples/text.luccEvery Text helper, including empty-separator edge cases
examples/math.luccEvery Math helper and exact division
examples/files.luccWriting, appending, reading, checking, and deleting a file
examples/utility.luccReusable helpers plus a uni variable holding a collection
examples/integration.luccEverything combined

hello.lucc

luca examples/hello.lucc
Hello, Luca!
Visit 2
Six divided by two is:
3.0

arithmetic.lucc

2.5
14
40
6
2
21.50
5.00
0.3

inference.lucc

Hello, Luca! Visit 2
3.14
none
5

comparison.lucc — nine comparison checks

true
true
true
true
true
false
true
true
true

conditional.lucc

Hello, Luca!
B
nested
after inner
and true
not false
inner
outer

functions.lucc

Hello, Luca!
Hello, Alex!
5
30
120
2
15
5
hi

loops.lucc

5
10
hi
hi
hi
3
13
nested
nested
nested
nested
5
4
3
done
3
2
1

collections.lucc — the four kinds in action

["Luca", "Alex"]
Luca
2
true
["Luca", "Alex", "Sam"]
["Alex", "Sam"]
(123, true, "Luca")
Luca
(456, true, "Luca")
{"alpha", "stable"}
true
{"alpha", "stable", "beta"}
{"Name" = "Luca", "Age" = 16}
Luca
true
true
{"Name" = "Luca", "Age" = 16, "City" = "Berlin"}
{"Name" = "Luca", "Age" = 17, "City" = "Berlin"}
Alex
Sam
true
2
2

modules/main.lucc — run the file, not the folder

luca examples/modules/main.lucc
hi World
hi Luca
1.0
demo
true
1
2
demo
modules

errors.lucc

caught division
cleanup
no trouble
always
inner finally
outer caught
5.0
0
503
unavailable
41
500
boom

ask.lucc — feed it lines

ask needs input; pipe it in when not typing interactively:

printf 'Luca\n16\n' | luca examples/ask.lucc
What is your name?
How old are you?
Hello, Luca. You are 16 years old.

stdlib.lucc

The program deliberately probes a missing file first — its warning is part of the demo, printed with the location of the offending statement:

Warning at 14:1: File 'examples/.no-such-demo-file' does not exist
5.0
1024.0
3
1
HELLO
a-b-c
true
true
true
true

text.lucc

Luca Code
LUCA CODE
luca code
Luca-Code
["list", "tuple", "set", "dict"]
list / tuple / set
["", "a", "b", "c", ""]
.a.b.c.

math.lucc

5.0
1024.0
7
2.50
3
-3
-3
-2
1.50
4
2.5
0.3333333333333333333333333333
0.25

files.lucc

Creates luca-example.tmp, reads it, then deletes it — running it leaves no file behind:

true
first and second
false

utility.lucc

32.0
212.0
0
42
100
3
["alpha", "beta", true, 3.50]
now a scalar

integration.lucc

skipped oops
35.50
skipped oops
1 over 10.00
{"retries" = 5}
true
no crash
done

Continue with the guided tour, the language reference, or the stdlib reference for function-level details.