From e1a2a4f3626c7450cacd7102575e870396910610 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 16 Apr 2020 02:01:55 +0200 Subject: [PATCH] docs: imports and a simple os.get_line() example --- doc/docs.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/docs.md b/doc/docs.md index e2629cc5e6..531c64a4c2 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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. +

 

+ ```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