A functionally inspired language focused on expressiveness.
iex (irm https://bern-lang.github.io/Bern/install/install_bern.ps1)
Install with PowerShell using the command above.
Alternatively, install with Bash using curl -fsSL https://bern-lang.github.io/Bern/install/install_bern.sh | bash
The standard library offers a rich set of functions for data manipulation, I/O, and more, so you can get started quickly.
import core
import random
import strings
-- This is actually a 'random' function that wraps a C binding!
text = random_choice(['apple', 'banana', 'cherry'])
map(text, \c -> char_to_upper(c))
Define functions with multiple clauses that match on patterns, making your code clear and maintainable.
def sign(0) -> "zero"
def sign(n) -> "positive"
def greet("Alice") -> "Hi, Alice!"
def greet(_) -> "Hello, someone else!"Create custom types with multiple constructors for type-safe data modeling. ADTs combine naturally with pattern matching.
adt Shape = Circle Double | Rectangle Double Double
def area(Circle(r)) -> 3.14159 * r * r
def area(Rectangle(w, h)) -> w * h
c = Circle(5.0)
r = Rectangle(3.0, 4.0)
area(c) // Calculates circle area
Use the for keyword for all loop types, inspired by Odin. Clean syntax for repeating, conditional, and iteration loops.
// Repeat loop
for 3 do
"Hello!"
end
// Conditional loop
for counter > 0 do
counter = counter - 1
end
// For-in loop
for char : "Bern" do
char
end
Functions are values that can be passed around, returned, and composed. Lambda expressions make inline functions natural.
import core
// Higher-order function usage
map([1, 2, 3, 4, 5], \x -> x * 2)
// Lambda expressions
inc = \x -> x + 1
applyTwice(\n -> n * 2, 5)
[1..10] for lists<>, <|, |>, </> for lists and sets#{key: value}# syntax:>(length) and ::(typeof)write_file(), read_file() and get_host_machine())In Bern, literals are interpreted and printed automatically. Variables are defined with simple assignment.
Use if-then-else statements and else-if chains for conditional logic.
Lists are homogeneous collections with range syntax and various operations.
Sets automatically handle uniqueness and support set theory operations.
Objects use #{...}# notation for key-value pairs.
Use do...end blocks with return for more complex functions.
Extend functionality by importing libraries like core.
Capture user input with the input() function.