diff --git a/doc/docs.md b/doc/docs.md index 55106007d7..0d50f9d907 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -18,12 +18,12 @@ you can do in V. - - - - - - + + + + + + @@ -39,7 +39,7 @@ you can do in V. - + @@ -51,7 +51,7 @@ you can do in V. - + @@ -177,7 +177,7 @@ 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. -## Constants & variables +## Variables ```v name := 'Bob' @@ -200,6 +200,8 @@ type `T`. Unlike most other languages, V only allows defining variables in functions. Global (module level) variables are not allowed. There's no global state in V. +

 

+ ```v mut age := 20 println(age) @@ -215,6 +217,8 @@ Try compiling the program above after removing `mut` from the first line. Note the (important) difference between `:=` and `=` `:=` is used for declaring and initializing, `=` is used for assigning. +

 

+ ```v fn main() { age = 21 @@ -224,6 +228,8 @@ fn main() { This code will not compile, because the variable `age` is not declared. All variables need to be declared in V. +

 

+ ```v fn main() { age := 21 @@ -233,6 +239,8 @@ fn main() { In development mode the compiler will warn you that you haven't used the variable (you'll get an "unused variable" warning). In production mode (enabled by passing the `-prod` flag to v – `v -prod foo.v`) it will not compile at all (like in Go). +

 

+ ```v fn main() { a := 10
1. Hello world2. Comments3. Functions4. Variables5. Primitive types6. Strings1. Hello world2. Comments3. Functions4. Variables5. Primitive types6. Strings
7. ImportsAccess modifiers Methods Pure functions by defaultAnonymous & high order functionsAnonymous & high order fns
References
Sum typesOption/Result & error handlingOption/Result & error handling Generics Concurrency Decoding JSON