docs: update array docs

pull/4613/head
Alexander Medvednikov 2020-04-26 17:19:08 +02:00 committed by GitHub
parent d16474442a
commit cd45e9ea48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -253,8 +253,7 @@ println(s) // "hello\nworld"
import os import os
fn main() { fn main() {
println('Enter your name:') name := os.input('Enter your name:')
name := os.get_line()
println('Hello, $name!') println('Hello, $name!')
} }
``` ```
@ -283,8 +282,11 @@ println('Alex' in names) // "false"
names = [] // The array is now empty names = [] // The array is now empty
// Declare an empty array:
users := []User{}
// We can also preallocate a certain amount of elements. // 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`). 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 println('bad_key' in m) // Use `in` to detect whether such key exists
m.delete('two') m.delete('two')
// Short syntax
numbers := { numbers := {
'one': 1, 'one': 1,
'two': 2 'two': 2