Re: [go-nuts] Newbie question

2023-01-10 Thread Daniel Jankins
Thanks! On Tue, Jan 10, 2023, 10:31 AM wagner riffel wrote: > On 1/10/23 11:42, Daniel Jankins wrote: > > Hi, > > > > Why can you update a value in a map struct? > > > > Sort answer, because m["foo"] is not addressable, but you can have the > desired behavior using a temp variable: > > func f()

Re: [go-nuts] Newbie question

2023-01-10 Thread 'wagner riffel' via golang-nuts
On 1/10/23 11:42, Daniel Jankins wrote: Hi, Why can you update a value in a map struct? Sort answer, because m["foo"] is not addressable, but you can have the desired behavior using a temp variable: func f() { m := make(map[string]struct{ i int }) x := m["foo"] x.i

[go-nuts] Newbie question

2023-01-10 Thread Daniel Jankins
Hi, Why can you update a value in a map struct? // UnaddressableFieldAssign occurs when trying to assign to a struct field // in a map value. // // Example: // func f() { // m := make(map[string]struct{i int}) // m["foo"].i = 42

Re: [go-nuts] Newbie question about type-casts

2020-08-04 Thread peterGo
Martin Møller Skarbiniks Pedersen, Use a RoundUp function for n / d. For example, // n / d rounded up func RoundUp(n, d int64) int64 { if d == 0 { return 0 } return (n + (d - 1)) / d } https://play.golang.org/p/kEMJ04ggkMc Peter On Tuesday, August 4, 2020 at 6:37:06 AM UTC-

Re: [go-nuts] Newbie question about type-casts

2020-08-04 Thread Jesper Louis Andersen
On Tue, Aug 4, 2020 at 12:31 PM Martin Møller Skarbiniks Pedersen < traxpla...@gmail.com> wrote: bet := int64(math.Ceil(float64(cash)/float64(4))) > > Programming languages must make a conscious choice here. Do we make type casts explicit or implicit? Go opted for the explicit approach, probably b

Re: [go-nuts] Newbie question about type-casts

2020-08-04 Thread Michael Jones
var cash, change, bet int64 : bet = cash/4 // change is 0,1,2,3 meaning 0/4, 1/4, 2/4, 3/4 dineros or zlottys or whatever change = cash - 4*bet // or, change = cash%4 // choose one of these if change>0{ bet++ // a: round up means 1/4 and 2/4 and 3/4 go to 1 } // ...or... if change>=2{ bet++ /

Re: [go-nuts] Newbie question about type-casts

2020-08-04 Thread Martin Møller Skarbiniks Pedersen
> > On Sun, Aug 2, 2020 at 2:09 PM Martin Møller Skarbiniks Pedersen < > traxp...@gmail.com > wrote: > >> I have written my first little piece of Go-code. >> However it took some time and code for me to divide a int64 by 4 and >> round down. >> >> [...] >> var bet int64 >> bet = int64(math.Ceil(

Re: [go-nuts] Newbie question about type-casts

2020-08-04 Thread Martin Møller Skarbiniks Pedersen
> > On Sun, Aug 2, 2020 at 2:09 PM Martin Møller Skarbiniks Pedersen < > traxp...@gmail.com > wrote: > >> I have written my first little piece of Go-code. >> However it took some time and code for me to divide a int64 by 4 and >> round down. >> >> How can the last two lines be rewritten? >> >> R

Re: [go-nuts] Newbie question about type-casts

2020-08-02 Thread Kurtis Rader
In addition to Jake's question regarding whether you want to round up or down I'll point out there isn't any to cast to float64 and back to int64. If you want to "round down" just divide by four. If you want to "round up" add one less than the divisor before dividing; e.g., bet := (cash + 3) / 4. N

[go-nuts] Newbie question about type-casts

2020-08-02 Thread Martin Møller Skarbiniks Pedersen
I have written my first little piece of Go-code. However it took some time and code for me to divide a int64 by 4 and round down. How can the last two lines be rewritten? Regards Martin package main import ( "fmt" "bufio" "math" ) var cash int64 scanner := bufio.NewScanner(os.Stdin) scanne

Re: [go-nuts] Newbie question on slice bound checking

2019-06-16 Thread Ugorji Nwoke
Thanks much, to you and Jan Merci. I needed it to validate whether the performance gap in my library was due to bounds checking or not. If it was, then I would try harder to use tips to reduce bounds checking. I wasn't planning on running it in production. I ended up having to use -gcflags=all=

Re: [go-nuts] Newbie question on slice bound checking

2019-06-16 Thread Jan Mercl
On Sun, Jun 16, 2019, 13:53 Ugorji Nwoke wrote: > I know this is an old thread, but is -B still supported? > That compiler flag provides compiling a program, semantic of which isn't compatible with the Go language specification. It's only valid use is to enable easy evaluation of the bounds che

Re: [go-nuts] Newbie question on slice bound checking

2019-06-16 Thread Michael Jones
It has been, yes, and unless it changed in the last few weeks, it still is. I use to to measure cost as an awareness metric, but seldom run that way. Go is safe until you do that, then it becomes unsafe. Too risky for serious use. On Sun, Jun 16, 2019 at 4:53 AM Ugorji Nwoke wrote: > I know thi

Re: [go-nuts] Newbie question on slice bound checking

2019-06-16 Thread Ugorji Nwoke
I know this is an old thread, but is -B still supported? On Monday, August 27, 2012 at 2:09:19 AM UTC-4, minux wrote: > > > On Monday, August 27, 2012, bluehorn wrote: >> >> Is "-gcflags -B" still supported in go1.0.2? I suppose it was gone >> already. >> > It is still there. > -- You receive

Re: [go-nuts] Newbie question about struct definition

2018-12-03 Thread Brian Hatfield
Hi Freddy! Those are Struct Tags (see here for more ) and are a way to add some metadata to struct fields that can be accessed via reflection. Lots of libraries use these to denote names or other notes about each fields. Those libraries expect to have a "known" st

[go-nuts] Newbie question about struct definition

2018-12-03 Thread Freddy Martinez
Hey guys, I’ve been learning Go for the lat couple of weeks but now that I’m looking to more advanced topics, I’ve seen things like type Person struct { FirstName string `db:"first_name"` LastName string `db:"last_name"` Email string } What `db:”first_name”` means ? Regards =