66 lines
715 B
V
66 lines
715 B
V
type Expr = IfExpr | IntegerLiteral
|
|
|
|
struct IfExpr{}
|
|
struct IntegerLiteral{}
|
|
|
|
struct User {
|
|
age int
|
|
name string
|
|
}
|
|
|
|
fn get_opt() ?int {
|
|
return 0
|
|
}
|
|
|
|
/*
|
|
fn new_user() User {
|
|
return User{}
|
|
}
|
|
|
|
fn get_user_opt() ?User {
|
|
return new_user()
|
|
//return User{age:20, name:'Peter'}
|
|
}
|
|
*/
|
|
|
|
fn (u &User) foo() {
|
|
age := u.age
|
|
zzz := [''].repeat(u.age)
|
|
a := 10
|
|
if a in [10, 20, 30] {
|
|
b := 10
|
|
}
|
|
}
|
|
|
|
fn println(s string) {}
|
|
|
|
fn handle_expr(e Expr) {
|
|
match e {
|
|
IfExpr {
|
|
println('if')
|
|
|
|
|
|
}
|
|
IntegerLiteral {
|
|
println('integer')
|
|
|
|
}
|
|
else {
|
|
println('else')
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
fn main() {
|
|
user := User{}
|
|
user.age = 10
|
|
user.age++
|
|
user.name = 'bob'
|
|
n := get_opt() or {
|
|
return
|
|
}
|
|
a := n + 3
|
|
handle_expr(IfExpr{})
|
|
}
|