1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

all: ast walker for marking unused fns

This commit is contained in:
Alexander Medvednikov
2021-02-05 08:05:13 +01:00
parent 119dfc0bb0
commit 1084b43ffb
13 changed files with 230 additions and 25 deletions

View File

@ -757,7 +757,7 @@ println(array_2) // [0, 1, 3, 5, 4]
### Fixed size arrays
V also supports arrays with fixed size. Unlike ordinary arrays, their
V also supports arrays with fixed size. Unlike ordinary arrays, their
length is constant. You cannot append elements to them, nor shrink them.
You can only modify their elements in place.
@ -1661,11 +1661,16 @@ fn sqr(n int) int {
return n * n
}
fn cube(n int) int {
return n * n * n
}
fn run(value int, op fn (int) int) int {
return op(value)
}
fn main() {
// Functions can be passed to other functions
println(run(5, sqr)) // "25"
// Anonymous functions can be declared inside other functions:
double_fn := fn (n int) int {
@ -1676,6 +1681,11 @@ fn main() {
res := run(5, fn (n int) int {
return n + n
})
// You can even have an array/map of functions:
fns := [sqr, cube]
println(fns[0](10)) // "100"
fns_map := { 'sqr': sqr, 'cube': cube}
println(fns_map['cube'](2)) // "8"
}
```
@ -3867,8 +3877,8 @@ if x {
}
my_label:
```
`goto` should be avoided when `for` can be used instead. In particular,
[labelled break](#labelled-break--continue) can be used to break out of
`goto` should be avoided when `for` can be used instead. In particular,
[labelled break](#labelled-break--continue) can be used to break out of
a nested loop.
# Appendices