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: {n}";

// 0.5
let msg = f"total: {n}";

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, 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, {name}!";

// 0.5
import "std/io.zc"

println(f"Hello, {name}!");

The other printing shortcuts are gone too:

0.4.40.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.40.5
autofree let p = alloc(...);let p = alloc(...); and defer free(p);, or implement Drop
async fn / awaitcall 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] calls get. Indexing a struct calls its get method, and only get. A struct that implemented [] with an index method must rename it to get. Vec::index is gone: use v.get(i) or v[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 const is an error: write def LIMIT = 10; (compile-time constant) or let LIMIT: const int = 10;.
  • assert outside a test block stops the program with exit code 1 when it fails. It used to print the message and go on.
  • c_long_long and c_ulong_long are c_longlong and c_ulonglong.
  • zc run main.zc a b passes a and b to the program. Extra source files after the first one are only read by zc build.
  • Standard library:
    • to_string() returns char* everywhere (Complex and JsonValue returned String);
    • len() (JSON) and free_mem() (BigInt, BigFloat) still work but are deprecated: use length() and free();
    • alloc, alloc_n and zalloc return zeroed memory;
    • each Random has its own generator state.

Tools

  • The language server, the REPL, the documentation generator and the formatter are separate programs: zc-lsp, zc-repl, zc-doc and zc-format. zc lsp, zc repl, zc doc and zc format still work but are deprecated: point your editor at zc-lsp. --zen is gone.
  • #define and #include in Zen C code give a deprecation warning: use def and import.

See the changelog for everything else in 0.5: new features and more than 140 fixes.