[go-nuts] Variadic assignable values and covariance

2017-12-14 Thread Ivan Kurnosov
Why does this code not compile: https://play.golang.org/p/f5fMvO8Ns7 package main import ( "fmt" ) func f(items ...interface{}) { fmt.Println(items) } func main() { f("a", "b", "c") tab := []interface{}{"d"} f("a", "b", "c", tab...) } The spec says: > Otherwise, the value passed is a

Re: [go-nuts] Variadic assignable values and covariance

2017-12-14 Thread Ivan Kurnosov
er 2017 at 12:59, Jesse McNelis wrote: > On Fri, Dec 15, 2017 at 8:18 AM, Ivan Kurnosov wrote: > > Why does this code not compile: https://play.golang.org/p/f5fMvO8Ns7 > > func f(items ...interface{}) { > > fmt.Println(items) > > } > > The spec also says: > >

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
@Rob, honestly to me they look the same: func IsSorted(data Interface) bool { n := data.Len() for i := n - 1; i > 0; i-- { if data.Less(i, i-1) { return false } } return true } func IsSortedForward(data sort.Interface) bool { n := data.Len() f

Re: [go-nuts] Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Ivan Kurnosov
Speaking low level - how about memory prefetch algorithms (os, hardware)? Do they work equally good when one iterates backward? On Friday, April 21, 2017 at 3:50:39 PM UTC+12, andrey mirtchovski wrote: > > > 297 for i := n - 1; i > 0; i-- { > > "i > 0" is cheaper than "i < n" on some processors

[go-nuts] Re: Turning unicode code string to rune

2017-04-22 Thread Ivan Kurnosov
1. Convert it to a number 2. Use `rune()` On Sunday, April 23, 2017 at 6:51:09 AM UTC+12, Tong Sun wrote: > > Hi, > > Given a unicode code string, be it "4e16", or "0x4e16", or "u4e16", how to > turn it into a single char rune? > > You can finish the code at https://play.golang.org/p/AFIEz3eJVz