Semua buku

Profesional

Aplikasi Tentang Pelatih Masuk Mulai membaca

Computer Science · Glosarium

Apa itu Pattern, pattern matching?

Dikenal juga sebagai: pattern · pattern matching

Definition 7.4 University Computer Science — Year 2 · Bab 7 — Enums, Pattern Matching and Error Handling

A pattern describes a shape of value: a literal (0), a range (1..=9), a variable that binds whatever it matches (x), the wildcard _, a variant with patterns for its fields (Shape::Rect { w, h }), a tuple of patterns, or alternatives p | q. Pattern matching, match v { p1 => e1, p2 if c => e2, ... }, tries the patterns in order and evaluates the expression of the first one that matches, with its variables bound; an arm may add a guard, if c, a condition on the bound variables.

Baca dalam konteks →