-
Notifications
You must be signed in to change notification settings - Fork 0
Guide Pattern Matching
GitHub Actions edited this page Jan 25, 2026
·
2 revisions
VelinScript unterstützt erweiterte Pattern Matching mit Guards, Range Patterns, Destructuring und mehr.
match (value) {
"hello" => {
return "greeting";
},
"world" => {
return "planet";
},
_ => {
return "unknown";
}
}
Guards erlauben zusätzliche Bedingungen in Pattern Matches:
match (result) {
Ok(value) if value > 0 => {
return "positive";
},
Ok(value) if value == 0 => {
return "zero";
},
Ok(value) => {
return "negative";
},
Error(err) => {
return "error";
}
}
Range Patterns erlauben das Matching von Zahlenbereichen:
match (age) {
0..=12 => "child",
13..=19 => "teenager",
20..=64 => "adult",
_ => "senior"
}
match (user) {
User { name: "admin", role } => {
return "admin user";
},
User { name, role: "user" } => {
return "regular user: " + name;
},
_ => {
return "unknown";
}
}
match (coordinates) {
(0, 0) => "origin",
(x, 0) => "x-axis",
(0, y) => "y-axis",
(x, y) => "point at (" + x + ", " + y + ")"
}
enum Result<T, E> {
Ok(value: T),
Error(error: E),
}
match (result) {
Result::Ok(value) => {
return value;
},
Result::Error(err: DatabaseError) => {
return "database error";
},
Result::Error(err: NetworkError) => {
return "network error";
}
}
Mehrere Patterns können mit | kombiniert werden:
match (status) {
"pending" | "processing" => {
return "in progress";
},
"completed" | "done" => {
return "finished";
},
_ => {
return "unknown";
}
}
Der Wildcard _ matched alles:
match (value) {
1 => "one",
2 => "two",
_ => "other"
}
- Verwende Guards für komplexe Bedingungen
- Nutze Range Patterns für Zahlenbereiche
- Destructure Structs für bessere Lesbarkeit
- Verwende Wildcard als Fallback
- Compiler Architecture
- Pass-Verlauf
- Type Inference
- Code Ordering
- IR Representation
- Borrow Checker
- Code Generation
- Multi-Target Compilation
- Module Resolution
- Framework Integration
- Parallelization
- AI Compiler Passes
- Prompt Optimizer
- System Generation
- Basics
- APIs
- Security
- Database
- Validation
- Authentication
- ML/LLM
- Intelligence Features
- Type Inference
- ML Training
- Pattern Matching
- Closures
- Collections
- HTTP Client
- String Interpolation
- Debugger
- Vektor-Datenbanken
- CLI Reference
- API Keys Setup
- Advanced
- Backend
- Security Best Practices
- AI/ML
- Auto Imports
- Plugin Development