* pradam <pradam.programm...@gmail.com> [180112 01:45]: > I'm Newbie to golang,
Welcome to Go! Many newbies often use "golang" rather than "Go" as the language name, and most old-timers usually ignore this incorrect usage, but golang is an artifact of the web site's hostname, golang.org. Also, using golang in web searches for Go language information can help make the results more specific to the computer language rather than other uses of "go". However, in normal conversation, it is correct to use "Go" for the name of the language. A very good introduction to Go can be found at the Go Tour «https://tour.golang.org/». > var m []int //array declaration First, m is a slice of int, not an array of int. An array is a type that has a fixed number of elements. A slice is a view into an array that can vary in size. An array would be declared with an explicit size, as var a [3]int A very good explanation of slices and arrays can be found at «https://blog.golang.org/go-slices-usage-and-internals». > m = {1,2,3,4,5,6,7} // this throws error The left side of the assignment above is an attempt to specify a composite literal. The correct syntax is m = []int{1, 2, 3, 4, 5, 6, 7} In other words, you must specify both the literal's type, []int, and its value, {1, 2, 3, 4, 5, 6, 7}. You could do the same for the array a declared above (note the explicit size in the type; it must match the size in the original declaration): a = [3]int{23, 29, 31} This is described in the language specification at «https://golang.org/ref/spec#Composite_literals». The complete language spec is extremely short compared to the specs for most other computer languages. Once you have completed the Go Tour and have played with Go for a little bit, it is probably worth your time to read the entire spec. > so I have declared an array which takes only int items, > > so I can append items to it with append function.: > > m = append(m, 1,2,3,4,5,6,7,8,9) > > but I want to insert items without using append function. Again, the above blog entry about slices should help you understand how to use slices and arrays more effectively. The Go language is designed to make it easier to reason about when memory is being allocated for a new value than in dynamically typed languages such as Python or JavaScript. Because of this, an explicit function call to append is necessary when appending to a slice might need to allocate a larger backing array. I hope this explanation and the above links help you to better understand this terrific language! ...Marvin -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.