A calmer way
to write for the JVM.

Friendly JVM syntax. Full access to Java libraries.

App.kalm
pub fun greeting(name: Text) -> Text:
    return @"Hello, $name!"

pub fun main() -> Unit:
    sayLine(greeting(""))
App.kalm
pub fun greeting(name: Text) -> Text {
    return @"Hello, $name!"
}

pub fun main() -> Unit {
    sayLine(greeting(""))
}
App.kalms
fun greeting(name: Text) -> Text:
    return @"Hello, $name!"

sayLine(greeting(""))
App.kalms
fun greeting(name: Text) -> Text {
    return @"Hello, $name!"
}

sayLine(greeting(""))
Output

Language notes

Indentation or braces. Same language. Choose indentation-based blocks or explicit braces. Both styles express the same Kalm code and work with the same tools.
Indentation or braces. Same language.

Choose indentation-based blocks or explicit braces. Both styles express the same Kalm code and work with the same tools.

Indentation
pub fun main() -> Unit:
    sayLine("Room to think.")
Indentation
sayLine("Room to think.")
Braces
pub fun main() -> Unit {
    sayLine("Room to think.");
}
Braces
sayLine("Room to think.");
Read the full guide
Java interoperability goes both ways.Call Java libraries from a script. Call Java libraries directly. Kalm compiles to Java source and ordinary JVM classes, so Java can call Kalm in the same build.Use Java libraries directly from a .kalms file. Publish Java-callable APIs from a .kalm project.
Java interoperability goes both ways.Call Java libraries from a script.

Call Java libraries directly. Kalm compiles to Java source and ordinary JVM classes, so Java can call Kalm in the same build.Use Java libraries directly from a .kalms file. Publish Java-callable APIs from a .kalm project.

Java sees ordinary methods, constructors, records and interfaces. Top-level functions become static methods on a file facade.

Calendar.kalm
use java.time.LocalDate

pub fun tomorrow() -> Text:
    return LocalDate.now().plusDays(1L).toString()
Calendar.kalm
use java.time.LocalDate

pub fun tomorrow() -> Text {
    return LocalDate.now().plusDays(1L).toString()
}
Calendar.kalms
use java.time.LocalDate

fun tomorrow() -> Text:
    return LocalDate.now().plusDays(1L).toString()
Calendar.kalms
use java.time.LocalDate

fun tomorrow() -> Text {
    return LocalDate.now().plusDays(1L).toString()
}
Calendar.java
import java.time.LocalDate;

public final class Calendar {
    public static String tomorrow() {
        return LocalDate.now().plusDays(1L).toString();
    }
}
Read the full guide
Async runs on virtual threads. Tasks use JVM virtual threads. Await either a Kalm Task or a Java CompletionStage, with cancellation, failure and interruption handling.
Async runs on virtual threads.

Tasks use JVM virtual threads. Await either a Kalm Task or a Java CompletionStage, with cancellation, failure and interruption handling.

Tasks.kalm
pub async fun answer() -> Int:
    fix pending: Task<Int> = task:
        return 6 * 7

    return await pending
Tasks.kalm
pub async fun answer() -> Int {
    fix pending: Task<Int> = task {
        return 6 * 7
    }
    return await pending
}
Tasks.kalms
async fun answer() -> Int:
    fix pending: Task<Int> = task:
        return 6 * 7

    return await pending
Tasks.kalms
async fun answer() -> Int {
    fix pending: Task<Int> = task {
        return 6 * 7
    }
    return await pending
}
Tasks.java
import java.util.concurrent.CompletableFuture;

public final class Tasks {
    public static CompletableFuture<Integer> answer() {
        var pending = start();
        return pending.thenApply(value -> value);
    }

    public static CompletableFuture<Integer> start() {
        var pending = new CompletableFuture<Integer>();
        Thread.startVirtualThread(() -> pending.complete(6 * 7));
        return pending;
    }
}
Read the full guide
Delegate a contract in one line. The forward declaration generates contract methods for a delegate, preserving generic types and checked Java exceptions.
Delegate a contract in one line.

The forward declaration generates contract methods for a delegate, preserving generic types and checked Java exceptions.

Wrap an implementation without writing the same forwarding methods by hand.

Delegation.kalm
contract Greeter:
    fun greet(name: Text) -> Text

class Delegated impl Greeter:
    fix delegate: Greeter
    init(delegate: Greeter):
        self.delegate = delegate

    forward Greeter to delegate
Delegation.kalm
contract Greeter {
    fun greet(name: Text) -> Text
}

class Delegated impl Greeter {
    fix delegate: Greeter
    init(delegate: Greeter) {
        self.delegate = delegate
    }
    forward Greeter to delegate
}
Delegation.kalms
contract Greeter:
    fun greet(name: Text) -> Text

class Delegated impl Greeter:
    fix delegate: Greeter
    init(delegate: Greeter):
        self.delegate = delegate

    forward Greeter to delegate
Delegation.kalms
contract Greeter {
    fun greet(name: Text) -> Text
}

class Delegated impl Greeter {
    fix delegate: Greeter
    init(delegate: Greeter) {
        self.delegate = delegate
    }
    forward Greeter to delegate
}
Delegation.java
interface Greeter {
    String greet(String name);
}

final class Delegated implements Greeter {
    public final Greeter delegate;

    public Delegated(Greeter delegate) {
        this.delegate = delegate;
    }

    @Override
    public final String greet(String name) {
        return delegate.greet(name);
    }
}
Read the full guide
Cleanup belongs to the scope. Use with to close Java resources automatically, and defer to run cleanup when a scope exits—even on an early return.
Cleanup belongs to the scope.

Use with to close Java resources automatically, and defer to run cleanup when a scope exits—even on an early return.

with closes resources in reverse order. defer keeps cleanup next to the work that needs it.

Resources.kalm
pub fun firstLine() -> Text?:
    defer:
        sayLine("read finished")

    with reader = java.util.Scanner("hello\nworld"):
        if reader.hasNextLine():
            return reader.nextLine()

    return null
Resources.kalm
pub fun firstLine() -> Text? {
    defer {
        sayLine("read finished")
    }
    with reader = java.util.Scanner("hello\nworld") {
        if reader.hasNextLine() {
            return reader.nextLine()
        }
    }
    return null
}
Resources.kalms
fun firstLine() -> Text?:
    defer:
        sayLine("read finished")

    with reader = java.util.Scanner("hello\nworld"):
        if reader.hasNextLine():
            return reader.nextLine()

    return null
Resources.kalms
fun firstLine() -> Text? {
    defer {
        sayLine("read finished")
    }
    with reader = java.util.Scanner("hello\nworld") {
        if reader.hasNextLine() {
            return reader.nextLine()
        }
    }
    return null
}
Resources.java
import java.util.Scanner;

public final class Resources {
    public static String firstLine() {
        try (var reader = new Scanner("hello\nworld")) {
            if (reader.hasNextLine()) return reader.nextLine();
            return null;
        } finally {
            System.out.println("read finished");
        }
    }
}
Read the full guide
Tests are part of the syntax.Project mode adds native tests. Write named test blocks with before and after hooks. The CLI, Maven and Gradle run the same native tests without a separate test library.Scripts are for sequential programs. Native tests and before/after hooks belong in a Kalm project; switch to Kalm to follow the test workflow.
Tests are part of the syntax.Project mode adds native tests.

Write named test blocks with before and after hooks. The CLI, Maven and Gradle run the same native tests without a separate test library.Scripts are for sequential programs. Native tests and before/after hooks belong in a Kalm project; switch to Kalm to follow the test workflow.

Put tests under src/test/kalm and run them with kalm test. Checks such as expect stay active without JVM assertion flags.

ArithmeticTests.kalm
before:
    sayLine("starting")

test "arithmetic works":
    expect 2 + 3 == 5

after:
    sayLine("finished")
ArithmeticTests.kalm
before {
    sayLine("starting")
}

test "arithmetic works" {
    expect 2 + 3 == 5
}

after {
    sayLine("finished")
}
ArithmeticTests.java
import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.*;

public class ArithmeticTests {
    @BeforeEach
    void before() {
        System.out.println("starting");
    }

    @Test
    void arithmeticWorks() {
        assertEquals(5, 2 + 3);
    }

    @AfterEach
    void after() {
        System.out.println("finished");
    }
}
Read the full guide

Learn Kalm

Start with a word counter. Add file input, handle errors, and finish with tests. Eight small steps, one useful program.Start with a word counter in a single script. Add file input and handle errors, then explore project mode for reusable APIs and native tests.

Follow the learning path