From 9772eb7c96beeb20eb74a7b4e44c7cf65ec1f186 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 26 Oct 2020 13:14:21 +0200 Subject: [PATCH] examples: fix warnings when doing `./v -W -progress -check-syntax build-examples` --- examples/2048/2048.v | 10 +- examples/concurrency/concurrency.v | 6 +- examples/game_of_life/life.v | 10 +- examples/game_of_life/life_gg.v | 72 ++++---- .../modules/automaton/automaton.v | 166 +++++++++++------- examples/hanoi.v | 14 +- examples/regex_with_memoization.v | 6 +- examples/sokol/drawing.v | 4 +- examples/sokol/sounds/melody.v | 4 +- examples/sokol/sounds/simple_sin_tones.v | 4 +- examples/sokol/sounds/wav_player.v | 16 +- examples/spectral.v | 24 ++- examples/terminal_control.v | 22 ++- examples/vcasino/vcasino.v | 2 +- 14 files changed, 203 insertions(+), 157 deletions(-) diff --git a/examples/2048/2048.v b/examples/2048/2048.v index 696843cc90..41af2ae686 100644 --- a/examples/2048/2048.v +++ b/examples/2048/2048.v @@ -202,7 +202,7 @@ enum Direction { // Utility functions [inline] -fn min(a, b int) int { +fn min(a int, b int) int { if a < b { return a } else { @@ -211,7 +211,7 @@ fn min(a, b int) int { } [inline] -fn max(a, b int) int { +fn max(a int, b int) int { if a > b { return a } else { @@ -229,7 +229,7 @@ fn abs(a int) int { } [inline] -fn avg(a, b int) int { +fn avg(a int, b int) int { return (a + b) / 2 } @@ -676,7 +676,7 @@ fn (app &App) draw_tiles() { } match app.tile_format { .normal { - app.gg.draw_text(xpos, ypos, '${1< play_wav_file: $fpath') - samples := read_wav_file_samples(fpath)? + samples := read_wav_file_samples(fpath) ? p.finished = true p.samples << samples p.finished = false @@ -121,7 +119,7 @@ struct RIFFFormat { fn read_wav_file_samples(fpath string) ?[]f32 { mut res := []f32{} // eprintln('> read_wav_file_samples: $fpath -------------------------------------------------') - mut bytes := os.read_bytes(fpath)? + mut bytes := os.read_bytes(fpath) ? mut pbytes := byteptr(bytes.data) mut offset := u32(0) rh := &RIFFHeader(pbytes) diff --git a/examples/spectral.v b/examples/spectral.v index 63efb57e50..fddc6c1b3f 100644 --- a/examples/spectral.v +++ b/examples/spectral.v @@ -14,14 +14,14 @@ import math import os import strconv -fn evala(i, j int) int { +fn evala(i int, j int) int { return ((i + j) * (i + j + 1) / 2 + i + 1) } fn times(mut v []f64, u []f64) { - for i in 0..v.len { + for i in 0 .. v.len { mut a := f64(0) - for j in 0..u.len { + for j in 0 .. u.len { a += u[j] / f64(evala(i, j)) } v[i] = a @@ -29,9 +29,9 @@ fn times(mut v []f64, u []f64) { } fn times_trans(mut v []f64, u []f64) { - for i in 0..v.len { + for i in 0 .. v.len { mut a := f64(0) - for j in 0..u.len { + for j in 0 .. u.len { a += u[j] / f64(evala(j, i)) } v[i] = a @@ -39,10 +39,9 @@ fn times_trans(mut v []f64, u []f64) { } fn a_times_transp(mut v []f64, u []f64) { - mut x := []f64{len:u.len, init:0} + mut x := []f64{len: u.len, init: 0} times(mut x, u) times_trans(mut v, x) - } fn main() { @@ -50,19 +49,18 @@ fn main() { mut n := 0 if args.len == 2 { n = strconv.atoi(args[1]) - } - else { + } else { n = 0 } - mut u := []f64{len:n, init:1} - mut v := []f64{len:n, init:1} - for _ in 0..10 { + mut u := []f64{len: n, init: 1} + mut v := []f64{len: n, init: 1} + for _ in 0 .. 10 { a_times_transp(mut v, u) a_times_transp(mut u, v) } mut vbv := f64(0) mut vv := f64(0) - for i in 0..n { + for i in 0 .. n { vbv += u[i] * v[i] vv += v[i] * v[i] } diff --git a/examples/terminal_control.v b/examples/terminal_control.v index bb5c943d25..5efb871045 100644 --- a/examples/terminal_control.v +++ b/examples/terminal_control.v @@ -2,28 +2,34 @@ import term fn main() { term.erase_clear() - sleeping_line(5,5,5,'*') - standing_line(5,5,5,'*') - sleeping_line(5,10,5,'*') - standing_line(9,5,5,'*') + sleeping_line(5, 5, 5, '*') + standing_line(5, 5, 5, '*') + sleeping_line(5, 10, 5, '*') + standing_line(9, 5, 5, '*') term.cursor_down(5) print('\n') println(term.bold(term.red('It Worked!'))) } -fn sleeping_line(x,y,size int, ch string) { +fn sleeping_line(x int, y int, size int, ch string) { mut i := 0 for i < size { - term.set_cursor_position(x: x+i, y: y) + term.set_cursor_position({ + x: x + i + y: y + }) print(term.bold(term.yellow(ch))) i++ } } -fn standing_line(x,y,size int, ch string) { +fn standing_line(x int, y int, size int, ch string) { mut i := 0 for i < size { - term.set_cursor_position(x: x, y: y+i) + term.set_cursor_position({ + x: x + y: y + i + }) print(term.bold(term.yellow(ch))) i++ } diff --git a/examples/vcasino/vcasino.v b/examples/vcasino/vcasino.v index 0919388901..3a038239a3 100644 --- a/examples/vcasino/vcasino.v +++ b/examples/vcasino/vcasino.v @@ -89,7 +89,7 @@ fn get_bet(money int) int { return bet } -fn run_wheel(bet_nbr, _bet int) int { +fn run_wheel(bet_nbr int, _bet int) int { mut bet := _bet winning_nbr := rand.intn(50) print('Roulette Wheel spinning... and stops on the number $winning_nbr which is a ')