GitHub

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:

hello.levy
say("Hello, World!")

Run it:

terminal
$ 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:

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

calculator.levy
# 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:

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:

interactive.levy
# 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:

terminal
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

Input/Output & Files

  • Input/Output - User input with ask() and output formatting
  • File System - Reading and writing files, directory operations

Advanced Topics

Tools & Ecosystem

Pro Tip: Install the VS Code extension for enhanced development experience with syntax highlighting, code snippets, and auto-completion. See the VS Code Extension guide for installation instructions.

REPL Mode

Levython includes an interactive REPL (Read-Eval-Print Loop) for experimenting with code:

terminal
$ 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.