Skip to content

Migrating from 0.1 to 0.2

The breaking changes between Prismio 0.1.0 and 0.2.0, each with the 0.1 spelling, the 0.2 spelling, and a program that compiles.

Last verified

On this page7 sections

Most 0.1 programs need a handful of mechanical edits to build with 0.2.0. Each change below says what to search for, what to write instead, and why it changed. The release notes list everything else that is new.

To find the places a program needs attention, build it and read the first errors: every change here fails with a message that names the new spelling.

bash
prismio check src/main.psm

Option<T> is now T?

Two spellings of "a T or nothing" were one more thing to learn, so Option<T> is gone and T? is the only optional. Every function that answered an Option now answers a T?, including Vec.get, pop, min, max, find, HashMap.get, String.get, readLine and process.env.

In 0.1In 0.2
Option.Some(x)x
Option.Nonenone
optionOr(o, d)o ?? d or o.unwrapOr(d)
o.isSome, o.isNoneo != none, o == none
match on an Optiona test against none, then expect(o)

?? and unwrapOr need import std.option.

prismio
import std.io
import std.map
import std.option
import std.vec

fn main() {
    let mut ages = HashMap<String, Int>()
    ages.set("ada", 36)
    let found = ages.get("ada") ?? 0
    let missing = ages.get("bob") ?? -1
    println(found, missing)

    let mut v = Vec<Int>()
    v.push(7)
    let last = v.pop()
    if last != none {
        println("popped", last ?? 0)
    }
}
text
36 -1
popped 7

Map is now HashMap

Search for Map<. The type is HashMap<K, V>, built with HashMap<K, V>() or HashMap<K, V>.withCapacity(n), and let m: HashMap<K, V> is an empty map. The map* free functions keep their names. Map is no longer a type. There is also a new HashSet<K>.

The stdin value is gone

Reading input is now plain functions from std.input.

In 0.1In 0.2
stdin.lines()inputLines()
stdin.readLine()readLine()
stdin.readAll()readAll()
stdin.isAtEndask for the next item: readLine() answers none at the end
readLineOr(fallback)readLine() ?? fallback
readWords()readTokens()
readBytes(count) as textreadText(count); readBytes(count) now returns Vec<U8>
prismio
import std.input
import std.io
import std.option

fn main() {
    for line in inputLines() {
        println(line.length)
    }
    let name = readLine() ?? "anonymous"
    println(name)
}
bash
printf 'one\ntwo\n' | prismio run
text
3
3
anonymous

An index out of range stops the program

On a Vec and on an Array<T, N>, an index past the end now prints runtime error: index 6 is out of range for a Vec of length 1 and exits. In 0.1 a Vec read answered the element type's zero and a write did nothing. A constant index that is out of range is a compile error. Check a length first where a program relied on the old answer.

Structs are internal, and fields are private

A struct is visible inside its package, and its fields inside its own module, unless marked. Mark a struct or field public when another package must name it.

__builtin_* belongs to the standard library

A program that writes a __builtin_ function is refused, and the error names the wrapper to write instead: s.length, min(a, b), portOutU8(port, v), volatileLoadU32(address) or asm("nop").

Declare the new minimum in build.ums

A project that asks for prismio = "0.1.0" still builds. Raise the line to prismio = "0.2.0" once the program uses a 0.2 feature, so an older compiler refuses it with a clear message.