mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
docs/readmes: format almost all remaining code blocks (#8590)
This commit is contained in:
parent
576492af4e
commit
58b3a30b47
28
doc/docs.md
28
doc/docs.md
@ -418,7 +418,7 @@ Literals like `123` or `4.56` are treated in a special way. They do
|
||||
not lead to type promotions, however they default to `int` and `f64`
|
||||
respectively, when their type has to be decided:
|
||||
|
||||
```v ignore
|
||||
```v nofmt
|
||||
u := u16(12)
|
||||
v := 13 + u // v is of type `u16` - no promotion
|
||||
x := f32(45.6)
|
||||
@ -718,7 +718,7 @@ numbers.sort() // 1, 2, 3
|
||||
numbers.sort(a > b) // 3, 2, 1
|
||||
```
|
||||
|
||||
```v nofmt
|
||||
```v
|
||||
struct User {
|
||||
age int
|
||||
name string
|
||||
@ -1487,7 +1487,7 @@ assert button.height == 20
|
||||
|
||||
As you can see, both the struct name and braces can be omitted, instead of:
|
||||
|
||||
```v ignore
|
||||
```v oksyntax nofmt
|
||||
new_button(ButtonConfig{text:'Click me', width:100})
|
||||
```
|
||||
|
||||
@ -1499,7 +1499,7 @@ Struct fields are private and immutable by default (making structs immutable as
|
||||
Their access modifiers can be changed with
|
||||
`pub` and `mut`. In total, there are 5 possible options:
|
||||
|
||||
```v nofmt
|
||||
```v
|
||||
struct Foo {
|
||||
a int // private immutable (default)
|
||||
mut:
|
||||
@ -1510,9 +1510,9 @@ pub:
|
||||
pub mut:
|
||||
e int // public, but mutable only in parent module
|
||||
__global:
|
||||
// (not recommended to use, that's why the 'global' keyword starts with __)
|
||||
f int // public and mutable both inside and outside parent module
|
||||
} // (not recommended to use, that's why the 'global' keyword
|
||||
// starts with __)
|
||||
}
|
||||
```
|
||||
|
||||
For example, here's the `string` type defined in the `builtin` module:
|
||||
@ -1587,7 +1587,7 @@ intended for low-level applications like kernels and drivers.
|
||||
|
||||
It is possible to modify function arguments by using the keyword `mut`:
|
||||
|
||||
```v nofmt
|
||||
```v
|
||||
struct User {
|
||||
name string
|
||||
mut:
|
||||
@ -1803,7 +1803,7 @@ module, and inside it. That restriction is relaxed only for the `main` module
|
||||
constants too, i.e. just `println(numbers)`, not `println(main.numbers)` .
|
||||
|
||||
vfmt takes care of this rule, so you can type `println(pi)` inside the `math` module,
|
||||
and vffmt will automatically update it to `println(math.pi)`.
|
||||
and vfmt will automatically update it to `println(math.pi)`.
|
||||
|
||||
<!--
|
||||
Many people prefer all caps consts: `TOP_CITIES`. This wouldn't work
|
||||
@ -1812,8 +1812,8 @@ They can represent complex structures, and this is used quite often since there
|
||||
are no globals:
|
||||
-->
|
||||
|
||||
```v ignore
|
||||
println('Top cities: $top_cities.filter(.usa)')
|
||||
```v oksyntax
|
||||
println('Top cities: ${top_cities.filter(.usa)}')
|
||||
```
|
||||
|
||||
## Builtin functions
|
||||
@ -1835,8 +1835,12 @@ fn print_backtrace() // print backtraces on stderr
|
||||
`println` is a simple yet powerful builtin function, that can print anything:
|
||||
strings, numbers, arrays, maps, structs.
|
||||
|
||||
```v nofmt
|
||||
struct User{ name string age int }
|
||||
```v
|
||||
struct User {
|
||||
name string
|
||||
age int
|
||||
}
|
||||
|
||||
println(1) // "1"
|
||||
println('hi') // "hi"
|
||||
println([1, 2, 3]) // "[1, 2, 3]"
|
||||
|
@ -4,7 +4,7 @@ A V module for designing terminal UI apps
|
||||
|
||||
#### Quickstart
|
||||
|
||||
```v nofmt
|
||||
```v
|
||||
import term.ui as tui
|
||||
|
||||
struct App {
|
||||
@ -32,12 +32,12 @@ fn frame(x voidptr) {
|
||||
|
||||
mut app := &App{}
|
||||
app.tui = tui.init(
|
||||
user_data: app,
|
||||
event_fn: event,
|
||||
user_data: app
|
||||
event_fn: event
|
||||
frame_fn: frame
|
||||
hide_cursor: true
|
||||
)
|
||||
app.tui.run()
|
||||
app.tui.run() ?
|
||||
```
|
||||
|
||||
See the `/examples/term.ui/` folder for more usage examples.
|
||||
|
@ -4,7 +4,7 @@
|
||||
`x.json2` is an experimental JSON parser written from scratch on V.
|
||||
|
||||
## Usage
|
||||
```v oksyntax nofmt
|
||||
```v oksyntax
|
||||
import x.json2
|
||||
import net.http
|
||||
|
||||
@ -22,11 +22,11 @@ fn main() {
|
||||
pi := person['pi'].f64() // 3.14....
|
||||
|
||||
// Constructing an `Any` type
|
||||
mut me := map[string]json2.Any
|
||||
mut me := map[string]json2.Any{}
|
||||
me['name'] = 'Bob'
|
||||
me['age'] = 18
|
||||
|
||||
mut arr := []json2.Any
|
||||
mut arr := []json2.Any{}
|
||||
arr << 'rock'
|
||||
arr << 'papers'
|
||||
arr << json2.null
|
||||
@ -34,7 +34,7 @@ fn main() {
|
||||
|
||||
me['interests'] = arr
|
||||
|
||||
mut pets := map[string]json2.Any
|
||||
mut pets := map[string]json2.Any{}
|
||||
pets['Sam'] = 'Maltese Shitzu'
|
||||
me['pets'] = pets
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user