Re: [go-nuts] Difference with function returning struct and function returning pointer to struct

2019-11-20 Thread Andrew Klager
c := getX() c.x = 1 vs getX().x = 1 On Wed, Nov 20, 2019 at 2:32 PM Robert Engels wrote: > I must of misread something, because this code works fine: > > package main > > import "fmt" > > type X struct { > x int > } > > func getX() X { > var x X > return x > } > > func main() { >

Re: [go-nuts] Bugs on switch

2019-06-17 Thread Andrew Klager
I'm going to guess, based on the "break" statement in the final case, that you expect each of the case statements without a break to fall through to the nest case. Go does not work like that. By default, each case, whether there's any action taken or not, breaks. Take a look at this to accomplish w

Re: [go-nuts] How to confirm a function is NOT compiled into a go binary

2019-06-08 Thread Andrew Klager
Take a look at https://golang.org/cmd/nm/ On Sat, Jun 8, 2019 at 1:38 PM wrote: > I'm looking for some type of tool or method to examine a compiled go > binary and confirm that a list of functions is NOT included in the compiled > binary. > > example: > package internal > > func A() string {

Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-25 Thread Andrew Klager
> > > Is this so bad? > > Yes, it's horrible as you'll loose any type information you had. > Meaning the next thing you naturally had to do was type cast it, which > isn't the nicest syntax to begin with. > By then it's probably more work than just using if / else > So what you're saying is that G

Re: [go-nuts] Go if else syntax .. suggested replacement

2019-04-24 Thread Andrew Klager
Is this so bad? func ternary(cond bool, pos, neg interface{}) interface{} { if cond { return pos } else { return neg } } color := ternary( temp < 80, "blue", "red") On Wed, Apr 24, 2019 at 4:14 PM Chris Broadfoot wrote: > > > On Wed, Apr 24, 2019 at 4:22 AM Robert Engels > wrote: >

Re: [go-nuts] why is this not ascending?

2019-04-08 Thread Andrew Klager
If you add fmt.Println(runtime.NumCPU()), you'll see there's one CPU in the playground environment. When main calls sleep after printing 0, the go routine is ready to run, so it switches there, and prints 1. At that point, when the go routine sleeps, main is not runnable (it's still sleeping), so i