Jule by examples

This article is a draft. It is not finished yet and might never be.

Created on 06/30/2025

There is a new programming language I found thanks to a comment under a video of Fireship : Jule.

Jule is a recent programming language similar to Go, but with immutable variables by default, better error handling, and native compile-time evaluation capabilities.

Currently the language lacks examples, so here are a few:

hello_world.jule
fn main() {
    println("Hello world!")
}

read_user_input.jule
use "std/bufio"
use "std/os"

fn readLine(mut scanner: &bufio::Scanner): str {
    scanner.Scan()!
    ret scanner.Text()
}

fn main() {
    mut scanner := bufio::Scanner.New(os::Stdin())

    print("Enter your name: ")
    name := readLine(scanner)
    println("So your name is '" + name + "'")
}

fizz_buzz.jule
fn main() {
  mut i := 1
  for i <= 16, i++ {
    if i % 15 == 0 {
      println("FizzBuzz")
    } else if i % 3 == 0 {
      println("Fizz")
    } else if i % 5 == 0 {
      println("Buzz")
    }
  }
}

randomness.jule
use "std/fmt"
use "std/math/rand"
use "std/time"

fn newRand(): &rand::Rand {
  seed := u64(time::Now().Unix())
  source := rand::NewSource(seed)

  // New is a static method
  ret rand::Rand.New(source)
}

fn main() {
  // Constants are compile-time known values
  const min = 1
  const max = 10

  rnd := newRand()
  random_number := rnd.Intn(max - min) + min

  // print[ln] doesn't accept multiple arguments, so you have to use fmt::Print
  fmt::Print("Here is a number between ", min, " and ", max, ": ")
  println(random_number)
}

array_and_slice.jule
fn incFirstElement(mut numbers: []int) {
  numbers[0]++
}

fn main() {
  // A slice
  mut numbers := [1, 2, 6] // short version of []int([1, 2, 6])

  // A static array
  // You have to use let notation to indicate the type
  mut staticNumbers := [...]int([1, 2, 6]) // [...] auto-deduces array length

  incFirstElement(numbers)
  incFirstElement(staticNumbers[:])

  println(numbers) // [2, 2, 6]
  println(staticNumbers) // [1, 2, 6]

  /*
    As you can see, the array is not modified when you pass it as a slice to
    functions. But it works in the array scope.
  */

  staticNumbers[0]++
  println(staticNumbers) // [2, 2, 6]
}