Published
More flexible matches and declarations in Jik v0.1.0-alpha.25
Jik v0.1.0-alpha.25 is now available. This release adds a catch-all arm for
match, lets typed local declarations include an initializer, and
shortens struct construction when variable and field names agree. It also adds
a runtime region-lifetime view for allocation behavior diagnostics.
Handle remaining match cases with other
A final other arm handles every enum member or variant tag that
preceding case arms do not cover. This keeps matches concise when
several remaining values have the same behavior. Without other,
matches remain exhaustive.
enum Mode:
DEBUG
RELEASE
TEST
end
func label(mode: Mode, r: Region) -> String:
match mode:
case Mode.DEBUG:
return "debug"[r]
other:
return "ordinary"[r]
end
end
Give typed locals an initial value
Local declarations may now combine a type annotation and initializer. This is
useful where the declared type documents the value or gives context to an
expression such as None.
func main():
retries: int = 3
result: Option[int] = None
println(retries, ": ", result)
end
Use struct field initializer shorthand
A struct initializer can name a visible variable directly when it has the same name as the target field. The shorthand remains named, so fields can still appear in any order and can be mixed with regular field initializers.
struct Config:
host: String
port: int
end
func main():
host := "localhost"
port := 8080
config := Config{host, port}
println(config.host, ": ", config.port)
end
Inspect runtime region lifetimes
The --region-tree option for jik run,
jik build, and jik tran prints runtime regions in
creation order. Indentation shows which region lifetime is nested inside
another, making it easier to inspect a program's allocation structure.
jik run hello.jik --region-tree
Release: Jik v0.1.0-alpha.25
Docs: match on enums
Docs: Variables and assignment
Docs: Structs
Docs: --region-tree