You might find blog.golang.org/constants helpful. -rob
On Tue, Feb 12, 2019 at 5:04 AM Jamie Caldwell <mr.jamie.caldw...@gmail.com> wrote: > Thanks for the help and quick response Tyler. > > On Mon, 11 Feb 2019 at 17:56, Tyler Compton <xavi...@gmail.com> wrote: > >> Constant expressions like 'A' or 3 or named constants like "const x = 7" >> are what Go calls "untyped constants". The type of these constants are >> determined by the context in which they're used. For example: >> >> const myConst = 3 >> myFloat := 2.5 >> fmt.Println(myFloat + myConst) >> fmt.Println(myFloat + 3) >> >> Both of the above cases work because myConst and the literal 3 are >> untyped constants that take on the type float64 automatically. >> >> You can also declare typed constants, which no longer have these type >> inference properties. >> >> const myConst int = 3 >> myFloat := 2.5 >> fmt.Println(myFloat + myConst) // No longer works >> >> If you're curious about the details, I would check out the section of the >> language spec on this: https://golang.org/ref/spec#Constants >> >> On Mon, Feb 11, 2019 at 9:37 AM Jamie Caldwell < >> mr.jamie.caldw...@gmail.com> wrote: >> >>> Hello, >>> >>> Can you help? >>> >>> https://play.golang.org/p/XfJZ3h06p60 >>> >>> Why does 'A' work, when first assigning it to a variable doesn't? >>> >>> Thank you, >>> Jamie. >>> >>> -- >>> 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. >>> >> -- > 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. > -- 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.