diff --git a/doc/docs.md b/doc/docs.md index 096308654b..701d9874a5 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -36,44 +36,45 @@ you can do in V. Match Structs + Short struct init syntax Access modifiers Methods Pure functions by default - Anonymous & high order fns + Anonymous & high order fns References Constants println Modules Interfaces - Enums + Enums Sum types Option/Result & error handling Generics Concurrency Decoding JSON - Testing + Testing Memory managment Defer ORM vfmt Writing documentation - Calling C functions from V + Calling C functions from V Conditional compilation Reflection via codegen Limited operator overloading Inline assembly Translating C/C++ to V - Hot code reloading + Hot code reloading Cross compilation Cross-platform shell scripts in V Appendix I: Keywords @@ -177,6 +178,8 @@ Like constants and types, functions are private (not exported) by default. To allow other modules to use them, prepend `pub`. The same applies to constants and types. + + ## Variables ```v @@ -266,8 +269,10 @@ rune // represents a Unicode code point f32 f64 -byteptr +byteptr // these two are mostly used for C interop voidptr + +any // similar to C's void* and Go's interface{} ``` Please note that unlike C and Go, `int` is always a 32 bit integer. @@ -666,6 +671,29 @@ All struct fields are zeroed by default during the creation of the struct. Array It's also possible to define custom default values. + +## Short struct initialization syntax + +There are no default function argument values or named arguments, for that the short struct initialization syntax can be used instead: + +```v +struct ButtonConfig { + text string + is_disabled bool + width int = 70 + height int = 20 +} +fn new_button(c ButtonConfig) &Button { + return &Button{ + width: c.width + height: c.height + text: c.text + } +} + +button := new_button(text:'Click me', width:100) // the height is unset, so it's 20, the default value +``` + ## Access modifiers Struct fields are private and immutable by default (making structs immutable as well).