Code Snippets V

Short texts V 🧑‍💻 Code snippets V ✍️ Reading lists V 👀


// We use a double linked list, to be able to delete players easily from the // ring, and two pointers: one to the current player, and another one to their // target, the player across the circle. By maintaining both pointers in each // turn, we avoid the algorithmic complexity of the naive approach. […]

Blueprint of what an example cli in V should be.

module main import cli, os fn main( mut app := cli.Command{ name: ‘pizzahut’ description: ‘Cli for ordering pizza from Pizza Hut’ // execute: // Without specifying the `execute` parameter, it will just output the usage message commands: [ cli.Command{ name: ‘order’ description: ‘Order food’ flags: [ Flag{ name: ‘delivery’ abbrev: ‘d’ description: ‘Delivery options’ // […]


import x.json2 struct First { mut: a int } struct Second { mut: ok bool } type ZType = First | Second struct MyS { mut: s string c ZType } ////// pub fn (z ZType) to_any() json2.Any { mut mc := map[string]json2.Any{} mc[‘kind’] = typeof(z) mc[‘value’] = match z { First { json2.Any(map{ ‘a’: […]


// This program is a direct port of // which in turn is an implementation of (Beeler et al. 1972, Item 120), // see // It calculates and prints the first 800 digits of pi, using only integer math. const maxr = 2800 fn main() { mut r := [maxr + 1]int{} mut […]

A simple timer app written in V, using gg.

module main import gg import gx import time const ( win_width = 600 win_height = 700 bg_color = gx.white count_color = ) struct App { mut: gg &gg.Context = 0 seconds i64 } fn main() { mut app := &App{} = gg.new_context( width: win_width height: win_height window_title: ‘Timer’ user_data: app bg_color: bg_color frame_fn: […]