An interpreted, dynamically typed programming language
Bern is a small, interpreted, dynamically typed programming language focused on clarity and expressiveness.
It blends ideas from functional programming (inspired by Haskell) with a lightweight, imperative syntax influenced by Lua and Odin.
Bern is designed so that:
- Everything is an expression
- Literals and expressions are evaluated and printed automatically
- Syntax stays minimal and readable
- Control flow is explicit and uniform
The goal is to make experimentation, scripting, and learning feel natural without sacrificing structure.
In Bern, literals and expressions are evaluated immediately:
"Hello, World!"
23
There is no need for an explicit print function - evaluation implies output.
Variables are defined with a simple assignment syntax:
integer = 2
double = 3.14
helloworld = "Hello, World!"
Variables can be used directly in expressions:
"Result from variable \"helloworld\": " + helloworld
Bern provides clear if / else if / else control flow:
age = 18
if age >= 18 then
"You are an adult."
else
"You are a minor."
end
Multiple conditions can be chained naturally:
score = 85
if score >= 90 then
"You got an A."
else if score >= 80 then
"You got a B."
else if score >= 70 then
"You got a C."
else
"You need to improve."
end
Bern uses a single keyword, for, with different forms depending on context.
for 3 do
"Hello, Loops!"
end
counter = 2
for counter > 0 do
"Hello, Loops!"
counter = counter - 1
end
for true do
"Hello!"
end
Iterating over a string:
text = "Bern"
for char : text do
"Current char is: " + char
end
With automatic indexing:
text = "Bern"
for char, index : text do
"Current char is: " + char
"Current index is: " + index
end
Bern supports concise function definitions, lambdas, and multi-clause pattern matching.
Define a function with def name(params) -> expr:
def add(x, y) -> x + y
add(2, 3)
Lambdas use the same arrow syntax and can be passed around:
inc = \x -> x + 1
pairSwap = \a, b -> [b, a]
inc(10)
pairSwap(1, 2)
Define multiple clauses; the first matching pattern runs:
def sign(0) -> "zero"
def sign(n) -> "positive"
sign(0)
sign(42)
Wildcards and literals are supported too:
def greet("Alice") -> "Hi, Alice!"
def greet(_) -> "Hello, someone else!"
greet("Alice")
greet("Bob")
Use do ... end with return when you need statements:
def sumList(xs) do
total = 0
for n : xs do
total = total + n
end
return total
end
sumList([1, 2, 3, 4])
A complete FizzBuzz example demonstrating variables, conditionals, and loops:
numbers = [1..100]
for n : numbers do
if n % 15 == 0 then
"FizzBuzz"
else if n % 3 == 0 then
"Fizz"
else if n % 5 == 0 then
"Buzz"
else
n
end
end
Each branch evaluates to a value, which is automatically printed.
- Interpreter written in Haskell
- Dynamically typed
- Expression-oriented evaluation model
Bern is currently in pre-alpha and under active development. Syntax and semantics may change as the language evolves.
Contributions, feedback, and experimentation are welcome.
