All news

Published

Jik v0.1.0-alpha.19

Jik v0.1.0-alpha.19 is now available. Its headline change is a broader uniform function-call syntax (UFCS): more values can lead a call, so code can follow the value being worked on instead of repeatedly naming a module or free function.

Variants support UFCS

Functions declared next to a variant can be called through a value of that variant, just like struct-related functions. The receiver is passed as the first argument, and returned values can be chained. This is particularly practical for values that move through a few small transformations.

variant Reading:
    VALUE: int
    MISSING
end

func increase(reading: Reading, amount: int) -> Reading:
    if reading is Reading.VALUE:
        reading[Reading.VALUE] += amount
    end
    return reading
end

func reading_value(reading: Reading) -> int:
    return reading[Reading.VALUE]
end

func main():
    reading := Reading.VALUE{4}
    println(reading.increase(3).reading_value()) // 7
end

The last line is shorthand for reading_value(increase(reading, 3)), but reads from left to right as a small pipeline.

Common operations stay with their values

The built-in push, pop, len, clear, and copy functions now accept the same syntax. The normal calls remain valid.


func main():
    entries := ["draft", "review"]
    entries.push("published")

    println(entries.len()) // 3

    last := entries.pop()
    snapshot := entries.copy()
    entries.clear()
end

External handles work the same way

UFCS also works with external structs, including standard-library handles:

use "jik/io" as io

func main():
    file := must io::open("notes.txt", "r", _)
    contents := must file.read(_)
    must file.close()
end