Quick Start
Get started with Levython in minutes. This guide will walk you through writing and running your first programs.
Hello World#
Create a file named hello.levy:
say("Hello, World!")
Run it:
$ levython hello.levy
Hello, World!
File Extensions#
Levython supports two file extensions:
.levy- Full extension (recommended).ly- Short extension
Both are fully supported and equivalent:
levython hello.levy # Works
levython hello.ly # Also works
A Basic Program#
Here's a comprehensive example demonstrating core Levython features including functions, variables, control flow, and iteration:
# A simple calculator demonstrating Levython features
# Function definitions use 'act' keyword
# Returns use '->' operator
act add(a, b) {
-> a + b
}
act subtract(a, b) {
-> a - b
}
act multiply(a, b) {
-> a * b
}
act divide(a, b) {
if b == 0 {
say("Error: Division by zero")
-> 0
}
-> a / b
}
# Variable assignment uses '<-' operator
x <- 10
y <- 5
# Output with say() function
say("Calculator Demo")
say("===============")
say(str(x) + " + " + str(y) + " = " + str(add(x, y)))
say(str(x) + " - " + str(y) + " = " + str(subtract(x, y)))
say(str(x) + " * " + str(y) + " = " + str(multiply(x, y)))
say(str(x) + " / " + str(y) + " = " + str(divide(x, y)))
# Conditional execution
if x > y {
say(str(x) + " is greater than " + str(y))
} else {
say(str(y) + " is greater than " + str(x))
}
# Iteration with for loops
say("")
say("Counting to 5:")
for i in range(1, 6) {
say(" " + str(i))
}
# Working with lists
say("")
say("Computing squares:")
numbers <- [1, 2, 3, 4, 5]
for n in numbers {
square <- multiply(n, n)
say(" " + str(n) + " squared = " + str(square))
}
Output:
Calculator Demo
===============
10 + 5 = 15
10 - 5 = 5
10 * 5 = 50
10 / 5 = 2
10 is greater than 5
Counting to 5:
1
2
3
4
5
Computing squares:
1 squared = 1
2 squared = 4
3 squared = 9
4 squared = 16
5 squared = 25
Interactive Input
Levython supports interactive user input with the ask() function:
# Get user input
name <- ask("What is your name? ")
say("Hello, " + name + "!")
# Input can be converted to numbers
age_str <- ask("What is your age? ")
age <- int(age_str)
if age >= 18 {
say("You are an adult.")
} else {
say("You are a minor.")
}
Syntax Highlights
| Feature | Syntax | Example |
|---|---|---|
| Variable Assignment | <- |
x <- 42 |
| Function Definition | act |
act greet(name) { ... } |
| Return Statement | -> |
-> result |
| Output | say() |
say("Hello") |
| Input | ask() |
name <- ask("Name? ") |
| Comments | # |
# This is a comment |
Running Examples#
Levython comes with 10 tutorial examples in the examples/ directory:
| File | Topic |
|---|---|
01_hello_world.levy |
Basic output |
02_variables.levy |
Variables and types |
03_arithmetic.levy |
Math operations |
04_conditionals.levy |
If/else |
05_loops.levy |
For and while |
06_functions.levy |
Functions with act |
07_lists.levy |
Working with lists |
08_strings.levy |
String operations |
09_fibonacci.levy |
Performance demo |
10_file_io.levy |
File operations |
Run any example:
levython examples/01_hello_world.levy
Next Steps#
Now that you've run your first Levython programs, dive deeper into the language features:
Core Language
- Variables & Data Types - Numbers, strings, booleans, lists, and type conversion
- Functions - Defining functions with
act, parameters, returns, and recursion - Control Flow - Conditional execution with if/elif/else
- Loops - Iteration with for and while loops
- Lists & Collections - Creating, accessing, and manipulating lists
Input/Output & Files
- Input/Output - User input with
ask()and output formatting - File System - Reading and writing files, directory operations
Advanced Topics
- Performance Optimization - Understanding JIT compilation and optimization techniques
- Memory Management - Direct memory operations and NaN-boxing internals
- Bitwise Operations - Low-level bit manipulation
- Tensor Operations - High-performance multi-dimensional arrays for ML/AI
- SIMD Vectorization - Parallel data processing with vector instructions
Tools & Ecosystem
- Command Line Interface - All CLI options and flags
- Package Manager (LPM) - Installing and managing packages
- VS Code Extension - Syntax highlighting, snippets, and debugging
REPL Mode
Levython includes an interactive REPL (Read-Eval-Print Loop) for experimenting with code:
$ levython
Levython 1.0.0 REPL
Type 'exit' to quit
>>> x <- 42
>>> say(str(x * 2))
84
>>> act square(n) { -> n * n }
>>> square(7)
49
>>> exit
The REPL is perfect for quick calculations, testing functions, and learning the language interactively.