Migrating from 0.4.4 to 0.5
Zen C 0.5 changes how strings are printed and interpolated, gives lambdas their own arrow, and removes several statements. Most old forms are compile errors that name their replacement, so the quickest way to migrate is to build your program and follow the errors. This page lists every change that needs an edit, with the old and the new code.
Strings and printing
Only f"..." interpolates
A plain string is an ordinary string: { and } are plain characters. Add f where you interpolate:
// 0.4.4
let msg = "total: ";
// 0.5
let msg = f"total: ";
In this release, a plain string that would have interpolated ("total: {n}") is an error, so that it does not silently print the braces. {{ and }} are escapes only inside f"...": in a plain string, write { and }.
print and println are functions
print, println, eprint and eprintln are functions of std/io.zc. They take one string, written in parentheses, and print it as text (a % in it is printed as is). Import std/io.zc to use them:
// 0.4.4
println "Hello, !";
// 0.5
import "std/io.zc"
println(f"Hello, !");
The other printing shortcuts are gone too:
| 0.4.4 | 0.5 |
|---|---|
println "text" | println("text") |
print "text" | print("text") |
"text"; (a string as a statement) | println("text"); |
"text"..; | print("text"); |
!"text"; | eprintln("text"); |
? "prompt" (a, b); | print("prompt"); then readln(a, b); |
? a, b; | readln(a, b); |
The argument must be a string: println(f"{n}") prints a number. The printf-style print(fmt, ...) and println(fmt, ...) of std/io.zc are replaced by these: to format with %d, call printf.
Lambdas take =>
Lambdas and match arms use =>. -> is member access through a pointer and the return type arrow only:
// 0.4.4
let twice = x -> x * 2;
let add = (a, b) -> a + b;
// 0.5
let twice = x => x * 2;
let add = (a, b) => a + b;
p->value reads the field value through the pointer p; in 0.4.4 it was the lambda p => value. A match arm or a lambda written with -> is an error with a hint towards =>.
Removed statements
| 0.4.4 | 0.5 |
|---|---|
autofree let p = alloc(...); | let p = alloc(...); and defer free(p);, or implement Drop |
async fn / await | call the function directly, or use std/thread.zc |
unless cond { ... } | if !cond { ... } |
guard cond else { ... } | if !cond { ... } |
repeat n { ... } | for _ in 0..n { ... } |
do { ... } while cond; | while |
Each removed form is a compile error that says what to write instead.
Other changes
x[i]callsget. Indexing a struct calls itsgetmethod, and onlyget. A struct that implemented[]with anindexmethod must rename it toget.Vec::indexis gone: usev.get(i)orv[i].- Struct patterns in
match(Opt { has: true, val: v } =>) are an error: they were never implemented, and matched any value. Match on the field instead:match o.has { true => ..., _ => ... }. - Top-level
constis an error: writedef LIMIT = 10;(compile-time constant) orlet LIMIT: const int = 10;. assertoutside atestblock stops the program with exit code 1 when it fails. It used to print the message and go on.c_long_longandc_ulong_longarec_longlongandc_ulonglong.zc run main.zc a bpassesaandbto the program. Extra source files after the first one are only read byzc build.- Standard library:
to_string()returnschar*everywhere (ComplexandJsonValuereturnedString);len()(JSON) andfree_mem()(BigInt,BigFloat) still work but are deprecated: uselength()andfree();alloc,alloc_nandzallocreturn zeroed memory;- each
Randomhas its own generator state.
Tools
- The language server, the REPL, the documentation generator and the formatter are separate programs:
zc-lsp,zc-repl,zc-docandzc-format.zc lsp,zc repl,zc docandzc formatstill work but are deprecated: point your editor atzc-lsp.--zenis gone. #defineand#includein Zen C code give a deprecation warning: usedefandimport.
See the changelog for everything else in 0.5: new features and more than 140 fixes.