Published
Simpler variant syntax in Jik v0.1.0-alpha.26
Jik v0.1.0-alpha.26 is now available. This release makes variants more elegant to inspect and unpack: tag names are inferred from the value being checked or matched, and payloads use checked member access.
Check tags without repeating the variant type
The value on the left of is supplies the variant type, so a tag
check now uses the tag name directly.
variant Value:
INT: int
TEXT: String
NUMS: Vec[int]
EOF
end
value := Value.INT{7}
if value is INT:
println("integer")
end
Access payloads as checked members
A variant payload is now accessed with value.TAG. The generated
code still checks that the named tag is active and reports a runtime error
otherwise. The same syntax can update an active payload.
value := Value.INT{7}
value.INT += 1
println(value.INT)
Use contextual tags in matches
Match arms also infer their variant or enum type from the matched expression. Payload bindings and exhaustiveness checking work as before, with less repetition in each case.
func describe(value: Value):
match value:
case INT{number}:
println("integer: ", number)
case TEXT{text}:
println("text: ", text)
case NUMS{numbers}:
println("numbers: ", numbers)
case EOF:
println("end of input")
end
end
Release: Jik v0.1.0-alpha.26 Changelog: v0.1.0-alpha.25...v0.1.0-alpha.26 Docs: Variants