1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

docs: imports and a simple os.get_line() example

This commit is contained in:
Alexander Medvednikov
2020-04-16 02:01:55 +02:00
committed by GitHub
parent 8e8f543013
commit e1a2a4f362

View File

@ -77,6 +77,8 @@ Functions can be used before their declaration:
This is true for all declarations in V and eliminates the need of header files This is true for all declarations in V and eliminates the need of header files
or thinking about the order of files and declarations. or thinking about the order of files and declarations.
<p>&nbsp;</p>
```v ```v
fn foo() (int, int) { fn foo() (int, int) {
return 2, 3 return 2, 3
@ -100,7 +102,7 @@ fn private_function() {
} }
``` ```
## Variables ## Consts & variables
```v ```v
name := 'Bob' name := 'Bob'
@ -245,6 +247,20 @@ s := r'hello\nworld'
println(s) // "hello\nworld" println(s) // "hello\nworld"
``` ```
## Imports
```v
import os
fn main() {
println('Enter your name:')
name := os.get_line()
println('Hello, $name!')
}
```
Modules can be imported using keyword `import`. When using types, functions, and consts from other modules, the full path must be specified. In the example above, `name := get_name()` wouldn't work. That means that it's always clear from which module a function is called
## Arrays ## Arrays
```v ```v