mutable decl syntax change
This commit is contained in:
@@ -63,18 +63,18 @@ make_box func() Box {
|
||||
}
|
||||
|
||||
main func() i32 {
|
||||
acc i32 = 0
|
||||
acc i32 := 0
|
||||
|
||||
dog Data = Data{ dog = 9 }
|
||||
bird Data = Data{ bird = 38 }
|
||||
dog Data := Data{ dog = 9 }
|
||||
bird Data := Data{ bird = 38 }
|
||||
acc = acc + describe(dog) + describe(bird) # 10 + 40 = 50
|
||||
|
||||
# same-type multi-pattern capture
|
||||
acc = acc + payload_of(dog) + payload_of(bird) # 9 + 38 = 47
|
||||
|
||||
# enum statement match, exhaustive, with a multi-pattern arm
|
||||
a Animal = .bird
|
||||
rank i32 = 0
|
||||
a Animal := .bird
|
||||
rank i32 := 0
|
||||
match a {
|
||||
.dog, .cat: rank = 1
|
||||
.bird: rank = 3
|
||||
@@ -89,7 +89,7 @@ main func() i32 {
|
||||
acc = acc + legs # +2
|
||||
|
||||
# scalar match: a range arm, a multi-literal arm, and a mandatory else
|
||||
bucket i32 = 0
|
||||
bucket i32 := 0
|
||||
match rank {
|
||||
0..3: bucket = 1 # exclusive 0,1,2 — does not include 3
|
||||
3, 4: bucket = 5 # rank is 3
|
||||
@@ -98,8 +98,8 @@ main func() i32 {
|
||||
acc = acc + bucket # +5
|
||||
|
||||
# void-payload variant: contextual construction (`.empty` coerces to Box) + no-capture arm
|
||||
e Box = .empty
|
||||
hit i32 = 0
|
||||
e Box := .empty
|
||||
hit i32 := 0
|
||||
match e {
|
||||
.point |pt|: hit = pt.x
|
||||
.empty: hit = 7
|
||||
@@ -107,7 +107,7 @@ main func() i32 {
|
||||
acc = acc + hit # +7
|
||||
|
||||
# pointer capture mutates the subject's payload in place
|
||||
b Box = Box{ point = Point{ x = 1, y = 2 } }
|
||||
b Box := Box{ point = Point{ x = 1, y = 2 } }
|
||||
match b {
|
||||
.point |@p|: p.x = 10
|
||||
.empty: hit = hit
|
||||
|
||||
Reference in New Issue
Block a user