From cd45e9ea48798525a5a5d4986567bdd84ff07e71 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 26 Apr 2020 17:19:08 +0200 Subject: [PATCH] docs: update array docs --- doc/docs.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/docs.md b/doc/docs.md index dcddcfd567..79e0e79d5a 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -253,8 +253,7 @@ println(s) // "hello\nworld" import os fn main() { - println('Enter your name:') - name := os.get_line() + name := os.input('Enter your name:') println('Hello, $name!') } ``` @@ -283,8 +282,11 @@ println('Alex' in names) // "false" names = [] // The array is now empty +// Declare an empty array: +users := []User{} + // We can also preallocate a certain amount of elements. -ids := [0].repeat(50) // This creates an array with 50 zeros +ids := []int{ len: 50, default: 0 } // This creates an array with 50 zeros ``` Array type is determined by the first element: `[1, 2, 3]` is an array of ints (`[]int`). @@ -330,6 +332,7 @@ println(m['bad_key']) // "0" println('bad_key' in m) // Use `in` to detect whether such key exists m.delete('two') +// Short syntax numbers := { 'one': 1, 'two': 2