Re: [go-nuts] Error vs. Panic: Should functions like strings.Repeat return an error value?

2016-07-07 Thread Martin Geisler
in other languages. > 1. https://golang.org/doc/faq#exceptions -- Martin Geisler -- 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

Re: [go-nuts] Error vs. Panic: Should functions like strings.Repeat return an error value?

2016-07-07 Thread Martin Geisler
s the ideomatic and good way in Go. That's very strange to me, and from reading about Go around the net, strange to a lot of people. -- Martin Geisler -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and

Re: [go-nuts] Re: Append to slice... what happens?

2016-07-03 Thread Martin Geisler
much more room there is beyond the length. If you set the capacity to the length, the next call to append will conclude that there's no space in the underlying array and proceed to allocate a new array, copy the data from the slide to the new array, and return a slice into this new array.

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-03 Thread Martin Geisler
Hi Chad, On Sat, Jul 2, 2016 at 10:43 AM, Chad wrote: > > On Saturday, July 2, 2016 at 10:23:04 AM UTC+2, Martin Geisler wrote: >> >> On Fri, Jul 1, 2016 at 4:01 PM, Chad wrote: >>> >>> On Friday, July 1, 2016 at 3:44:10 PM UTC+2, Martin Geisler wrote: >

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-02 Thread Martin Geisler
and the kind of optimization the compiler can do when it knows the implementation of map and string. However, it shouldn't be part of the language specification. -- Martin Geisler -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-02 Thread Martin Geisler
On Fri, Jul 1, 2016 at 4:01 PM, Chad wrote: > > > On Friday, July 1, 2016 at 3:44:10 PM UTC+2, Martin Geisler wrote: >> >> On Fri, Jul 1, 2016 at 12:52 PM, Chad wrote: >> > However, that it's a valid point you raise (re strings) >> > But that&#

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
x27;s similarly sized. I'm very new to Go, so please let me know if I'm missing anything? -- Martin Geisler -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving email

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
On Fri, Jul 1, 2016 at 12:48 PM, Chad wrote: > On Friday, July 1, 2016 at 12:11:43 PM UTC+2, Martin Geisler wrote: >> >> On Fri, Jul 1, 2016 at 3:15 AM, Chad wrote: >> > No, it's actually fine. You are comparing values. >> > >> > A slice bein

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-07-01 Thread Martin Geisler
strings can. Two strings (that are not slices from the same original string) can be compared for equality just fine. I hope Go takes the shortcut when the strings refer to the same memory and otherwise does the slower per-byte comparison. The same could perhaps apply to slices in general. -- Martin

Re: [go-nuts] Append to slice... what happens?

2016-07-01 Thread Martin Geisler
Hi Ian, On Mon, Jun 27, 2016 at 8:18 PM, Ian Lance Taylor wrote: > On Sun, Jun 26, 2016 at 10:55 PM, Dan Kortschak > wrote: >> On Mon, 2016-06-27 at 07:49 +0200, Martin Geisler wrote: >>> BTW, I was about to say that you could simplify the line one step >>> furthe

Re: [go-nuts] Shuffle Items in a Slice

2016-06-26 Thread Martin Geisler
e point in the past : the > clock, the randomness sources, and you can't make outgoing requests to > import randomness from the network. I found this blog post with a lot more background information: https://blog.golang.org/playground -- Martin Geisler -- You received thi

Re: [go-nuts] Re: Shuffle Items in a Slice

2016-06-26 Thread Martin Geisler
Hi Val On Fri, Jun 24, 2016 at 2:48 PM, Val wrote: > 2 implementations here : > http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go > > As for the map iteration trick, the runtime doesn't guarantee to randomize > anything, although it often tries to, so developers don't rely on some

Re: [go-nuts] Append to slice... what happens?

2016-06-26 Thread Martin Geisler
to me since the second (middle) index has a useful default (len(a)) that is used when there are only two indexes used. -- Martin Geisler -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving

Re: [go-nuts] Append to slice... what happens?

2016-06-26 Thread Martin Geisler
in b. In your example you were "lucky" since you started with a = [1, 2] and cap(a) = 2. When you create b, append notices that the capacity is exhausted and *creates a new underlying array for b*. After that step, a and b are no longer "entangled" like this and updates to one c

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Martin Geisler
ate indexes into the map. Use these indexes to swap elements and permute the array as Konstantin mentioned (https://en.wikipedia.org/wiki/Fisher–Yates_shuffle). -- Martin Geisler -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscr