odin-lang / odin-lang.org

http://odin-lang.org
22 stars 81 forks source link

Resize / Reserve with a dynamic array in Overview commented output is incorrect #150

Closed mahSource closed 8 months ago

mahSource commented 11 months ago

The examples have output for the fmt.println(len(x), cap(x)) that show elements with commas, they are/should be space delimited in the output See: https://odin-lang.org/docs/overview/#resize--reserve-with-a-dynamic-array . This is the current Overview Example

x: [dynamic]int
fmt.println(len(x), cap(x)) // 0, 0
append(&x, 1, 2, 3) // [1, 2, 3]
fmt.println(len(x), cap(x)) // 3, 8
resize(&x, 5) 
fmt.println(x[:]) // [1, 2, 3, 0, 0] other values are zero'd memory
fmt.println(len(x), cap(x)) // 5, 8
reserve(&x, 32)
fmt.println(len(x), cap(x)) // 5, 32
shrink(&x)
fmt.println(len(x), cap(x)) // 5, 5

Suggest the Overview be updated to this

x: [dynamic]int
fmt.println(len(x), cap(x)) // 0 0
append(&x, 1, 2, 3) // [1, 2, 3]
fmt.println(len(x), cap(x)) // 3 8
resize(&x, 5) 
fmt.println(x[:]) // [1, 2, 3, 0, 0] other values are zero'd memory
fmt.println(len(x), cap(x)) // 5 8
reserve(&x, 32)
fmt.println(len(x), cap(x)) // 5 32
shrink(&x)
fmt.println(len(x), cap(x)) // 5 5

. Notice the commas for the output of 5 lines are removed....a minor update, but should be changed to this.