Re: [go-nuts] Mismatched types work sometimes?
Cheers Rob, I'll certainly read that. On Mon, 11 Feb 2019 at 20:53, Rob Pike wrote: > 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 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.
Re: [go-nuts] Mismatched types work sometimes?
Thanks for the help and quick response Tyler. On Mon, 11 Feb 2019 at 17:56, Tyler Compton 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.
[go-nuts] Mismatched types work sometimes?
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.
Re: [go-nuts] Re: When would you use single quotes?
Volker / Jan / Tamás & Peter -- thank you all for your replies. On Thu, 7 Feb 2019 at 13:16, peterGo wrote: > Jamie, > > This is a question about Unicode: > > The Unicode Consortium: http://unicode.org/ > > The Unicode Standard: http://www.unicode.org/standard/standard.html > > Unicode Frequently Asked Questions: UTF-8, UTF-16, UTF-32 & BOM: > http://www.unicode.org/faq/utf_bom.html > > Briefly, a Unicode code point is 24 bits. The nearest common hardware > equivalent is 32 bits. Go uses type int32. Go uses an alias of type rune to > distinguish code points from integers. > > A Unicode transformation format (UTF) is an algorithmic mapping from every > Unicode code point to a unique byte sequence. Go favors UTF-8. > > In Go, single quotes enclose a rune (32 bit) literal, double quotes > enclose a UTF-8 encoded string (one to four byte) literal. > > Peter > > On Wednesday, February 6, 2019 at 6:14:41 PM UTC-5, Jamie Caldwell wrote: >> >> Hello, >> >> I'd be grateful if someone could please explain why you would use >> >> r := '⌘' >> >> Instead of >> >> s := "⌘" / s:= `⌘` >> >> All use three bytes ...? >> >> Thank you, >> Jamie. >> > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/-bvJLkhX_dY/unsubscribe. > To unsubscribe from this group and all its topics, 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.
Re: [go-nuts] When would you use single quotes?
Thank you both for your answers. It is much appreciated. The UTF8 encoding of that codepoint is three bytes. So the rune will still occupy 4 bytes, even if the last byte holds no data? I'm sorry for the school boy question! Thank you. On Thu, 7 Feb 2019, 10:52 Tamás Gulácsi A rune is an int32, so it takes 4 bytes by definition. > A string in a struct with position, length and backing array of bytes. The > backing array here consumes 3 bytes, but tge position and length occupies > space too, so the string of that rune occupies more than 3 bytes after all. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/-bvJLkhX_dY/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > On Thu, 7 Feb 2019, 10:52 Tamás Gulácsi A rune is an int32, so it takes 4 bytes by definition. > A string in a struct with position, length and backing array of bytes. The > backing array here consumes 3 bytes, but tge position and length occupies > space too, so the string of that rune occupies more than 3 bytes after all. > > -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/-bvJLkhX_dY/unsubscribe. > To unsubscribe from this group and all its topics, 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.
Re: [go-nuts] When would you use single quotes?
Thank you for getting back to me, but I don't think you have answered my question. I understand they are a rune and string respectively. But *why* would you use one over the other? Why does Go support being able to assign a codepoint using single quotes? Also, why do they take more than three bytes each? Thank you. On Wed, 6 Feb 2019 at 23:30, Wagner Riffel wrote: > '⌘' is of type rune (aka int32), "⌘" and `⌘` are of type string, both > takes more than 3 bytes. > -- 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.
[go-nuts] When would you use single quotes?
Hello, I'd be grateful if someone could please explain why you would use r := '⌘' Instead of s := "⌘" / s:= `⌘` All use three bytes ...? 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.