523b3885dda1d16e260bd00f539eece79878d95d
[dotfiles/.git] / C1.go
1 // +build ignore
2
3 package C1
4
5 import "strings"
6
7 func example() {
8         x := "foo"
9         println(x[:len(x)])
10
11         // Match, but the transformation is not sound w.r.t. possible side effects.
12         println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 3))])
13
14         // No match, since second use of wildcard doesn't match first.
15         println(strings.Repeat("*", 3)[:len(strings.Repeat("*", 2))])
16
17         // Recursive match demonstrating bottom-up rewrite:
18         // only after the inner replacement occurs does the outer syntax match.
19         println((x[:len(x)])[:len(x[:len(x)])])
20         // -> (x[:len(x)])
21         // -> x
22 }