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

pull/4432/head
Alexander Medvednikov 2020-04-16 02:01:55 +02:00 committed by GitHub
parent 8e8f543013
commit e1a2a4f362
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

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
or thinking about the order of files and declarations.
<p>&nbsp;</p>
```v
fn foo() (int, int) {
return 2, 3
@ -100,7 +102,7 @@ fn private_function() {
}
```
## Variables
## Consts & variables
```v
name := 'Bob'
@ -245,6 +247,20 @@ s := r'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
```v