Skip to the page
Results for “match”
30 results, best first
-
error codeError codes
E0013: unmatched closing bracket
A closing ), ] or } doesn't match the innermost open bracket, or there is no open bracket for it to close. The note says which bracket is still open and where.
-
error codeError codes
E0262: pattern doesn't match the value's type
The pattern could never match because it describes a different type than the value being matched, such as a string pattern against an int.
-
error codeError codes
E0402: let ... else whose pattern always matches
The pattern of this let matches every value of its type, so the else part can never run. Auk flags dead code like this so it doesn't mislead readers; the fix removes the else.
-
error codeError codes
E0403: pattern that might not match where one must always match
…loop and function parameters bind with patterns that must match every value. This one might not; the message shows a value it misses. Auk never fails a binding silently at run time.
-
error codeError codes
E0009: unmatched } in a string
A string contains a } that doesn't close an interpolation. Because { and } mark interpolations, a literal brace must be doubled.
-
error codeError codes
E0200: mismatched types
A value of one type was used where another type is expected. Auk has no implicit conversions (not even int to float), so every conversion is visible in the code: float(n), int(x), str(v).
-
error codeError codes
E0204: closure parameter count mismatch
The closure takes a different number of parameters than the function it is passed to expects. For example, map passes one item, reduce passes two values.
-
error codeError codes
E0290: mismatched units in an operator
+, -, %, the comparisons, min, max and sort need both sides in the same unit: adding metres to seconds is a bug. * and / combine units instead (m / s is m/s). A plain number has no unit, so it can…
-
error codeError codes
E0291: mismatched units of measure
A value's unit differs from the unit expected there: a function argument, a return value, a let with a type, a field or an assignment. The types are otherwise the same (float<m> where float<s> is…
-
definitionReference › Glossary
pattern
A description of the form a value can take, used to take it apart: Circle(r), [first, ..rest], (a, b), some(v). Patterns appear in match, in clauses and in let. More: Functions, clauses and patterns.
-
The language › Basics
Control flow
if, match and loop are expressions, so they produce values: let n = 7 let size = if n > 5 { "big" } else { "small" } print(size) // big for i in 0..3 { print(i) } // 0 1 2 for i in 0..=3 { print(i) }…
-
The language › Errors and optionals
Optionals: T?
…in; else supplies the fallback print(name) // nobody match find(users, 1) { some(u) => print("found {u.name}") // found ann none => print("no such user") } let u = find(users, 1) else return // or…
-
The language › Errors and optionals
Errors: T!
…x else fallback and x else e => ... handle the error here. match x { ok(v) => ..., err(e) => ... } when both paths need real code. ? on a list of results ([T!]) gives the list of values or the first…
-
The language › Errors and optionals
Typed errors: T!E
…any error through ? let n = parse(s)? n * 2 } fn main() { match parse("") { ok(n) => print(n) err(Eof) => print("ran out of input") // ran out of input err(BadToken(at)) => print("bad token at {at}")…
-
The language › Functions, clauses and patterns
Clauses
A function can be written as several clauses, each matching its arguments against patterns. Clauses are tried top to bottom, and the compiler rejects the function unless they cover every possible…
-
The language › Functions, clauses and patterns
Patterns
The same patterns work in clauses, in match, in let, in for, and with is. pattern matches 0 "GET" 'c' true that literal _ anything x anything, bound to x Circle(r) that enum variant, binding its…
-
The language › Structs, enums and shapes
Enums
…float, h: float), Empty, } fn area(s: Shape): float = match s { Circle(r) => 3.14159 * r * r Rect(w, h) => w * h Empty => 0.0 } fn main() { let shapes = [Circle(1.0), Rect(2.0, 3.0), Empty]…
-
The language › Structs, enums and shapes
Operators on your types
Define add, sub, mul, div or mod and the matching operator works: struct Vec { x: float, y: float } fn add(a: Vec, b: Vec): Vec = Vec { x: a.x + b.x, y: a.y + b.y } fn mul(a: Vec, k: float): Vec =…
-
Start here › A tour of Auk
2. Choices, and functions by cases
…until you handle it. The same checking applies to match. More: Functions, clauses and patterns, Structs, enums and shapes.
-
Start here › A tour of Auk
3. Things that can fail
…let [a, b, c] = ... else ... is a pattern that might not match, with what to do when it doesn't. ? on a list of results gives every value, or the first error. There are no exceptions and no null. A…
-
The language › Calling C
Raw memory: the ffi module
…read_i32, read_i64, read_f64, read_ptr, and the matching p.write_u8(offset, v), ...; offsets are in bytes p.cstr() (a C string as str), ffi.bytes(p, n), ffi.from_bytes(bs) ffi.symbol(name): ffi.Ptr?…
-
error codeError codes › E0262: pattern doesn't match the value's type
Wrong
fn f(x: int): int = match x { "a" => 1 _ => 2 }
-
error codeError codes › E0262: pattern doesn't match the value's type
Fixed
fn f(x: int): int = match x { 1 => 1 _ => 2 }
-
error codeError codes › E0402: let ... else whose pattern always matches
Common causes
An enum with a single variant: its pattern always matches. A plain let x = v else ... on a value that isn't T? or T! is E0255 instead. Defensive else blocks copied from code where the pattern really…
-
error codeError codes › E0403: pattern that might not match where one must always match
Common causes
…enum or literal with a plain let: add else { ... }, or use match. for Circle(r) in shapes: filter first, or match inside the loop.
-
packagePackages
compress
…encoder writes stored and fixed-Huffman blocks with LZ77 matching. Its output decodes with any standard tool (gzip -d, zlib, browsers), but it is not zlib-level compression: there are no dynamic…
-
packagePackages
encoding
…let q = encoding.percent_encode("a b&c") // "a%20b%26c" match encoding.from_base64("Zm9v YmFy") { err(e) => print(encoding.message(e)) // bad char ' ' at 4 ok(_) => {} }
-
packagePackages
glob
Glob patterns for file paths: *, ?, [...], ** and {a,b}. Matching is a pure function of two strings. walk and find list directories to return the paths that match. Effects: fs, and only walk and find…
-
packagePackages
graphics
…// the first show sends it all var n = 0 loop { match gui.next_event(win, -1) { some(gui.Close) => break some(gui.MouseDown(_, _, _, _)) => { n += 1 c.fill(20, 70, 300, 40, 0xffffff) c.text(&face,…
-
packagePackages
json
…fs.write("todos.json", json.encode(ts))? match json.parse("[1,]") { err(e) => print(json.message(e)) // 1:4: unexpected ']' ok(_) => {} }