Structs as trailing literal arguments to a function
As V does not support default function arguments or named arguments, we can use trailing struct literal syntax. In V, you can define functions that accept structs as input arguments. Therefore, we can pass a struct with default values to a function that accepts the struct as an input argument.
For example, let's create a function that creates a Note
struct to remind us to buy groceries. This function will take the Note
struct provided as an input argument and create a new Note
struct that prepends a phrase, Buy Groceries:
, to the message
field of every new note being created, as follows:
fn new_grocery_note(n Note) &Note { return &Note{ id: n.id message: 'Buy Groceries...