[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread Kaveh Shahbazian
@ Louki Sumirniy Slices are values AFAIK. There is no passby pointer. And the point is, race detector does not flag anything: https://play.golang.org/p/NC8mBwS1-0P -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group a

[go-nuts] On Accepting Interfaces and Structs

2018-04-21 Thread Kaveh Shahbazian
Regarding "Accept interfaces, return concrete types", how can it be applied for structs that represent a payload/value? For example in package first, logger is defined as: type logger interface { Debugf(template string, args ...interface{}) Errorf(template string, args ...interface{})

Re: [go-nuts] On Accepting Interfaces and Structs

2018-04-21 Thread 'Axel Wagner' via golang-nuts
On Sat, Apr 21, 2018 at 1:52 PM Kaveh Shahbazian wrote: > Is there a way to actually achieve this? > Either change `second.cloner` to return an interface, or (IMO better) just import `second`. I don't understand why you'd want to avoid that. -- You received this message because you are subscri

[go-nuts] proposal: disallow implicitly comparing true with value of interface{} in a switch with no value

2018-04-21 Thread b97tsk
var someInterfaceValue interface{} switch { case someInterfaceValue: // proposal: compile error: non-bool used as condition case someInterfaceValue == true: // OK } Sometimes carefulness is just not enough. One may type a wrong variable as the case condition, or a incomplete condition. Why

[go-nuts] Re: net/http: get does not work

2018-04-21 Thread romanbo
How do you get golang on iOS? On Friday, April 20, 2018 at 4:19:40 PM UTC-4, Haydon Ryan wrote: > > url := "https://google.com/"; > req, err := http.NewRequest("GET", url, nil) > if err != nil { > log.Fatal(err) > fmt.Printf(err.Error()) > return > } > r

[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread Ankit Gupta
@Kaveh Slices are values but they refer to the same back array location. You have created localized v which is appended inside goroutine which refer to a location containing its own byte array of len=10. So, you are not really referencing the same memory location as other v slice in the gorouti

[go-nuts] Global variable not used, but it works fine

2018-04-21 Thread zpsyhapcst
What did you do? https://play.golang.org/p/aryK9Btv5kH What did you expect to see? There should be a error "declared and not used" What did you see instead? It seems work fine. System details ``` go version go1.10.1 windows/amd64 GOARCH="amd64" GOBIN="" GOCACHE="C:\Users\zps

[go-nuts] Re: net/http: get does not work

2018-04-21 Thread romanbo
On Friday, April 20, 2018 at 4:19:40 PM UTC-4, Haydon Ryan wrote: > > url := "https://google.com/"; > req, err := http.NewRequest("GET", url, nil) > if err != nil { > log.Fatal(err) > fmt.Printf(err.Error()) > return > } > res, err := http.DefaultClient

[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread Louki Sumirniy
Unless you pass pointers in Go, every time you hop in and out of a new scope any changes are discarded. This is why unless you type-bind with pointers you don't actually have an OOP method, as the function will not act upon the parent variable/structure. I think if you change your playground co

Re: [go-nuts] proposal: disallow implicitly comparing true with value of interface{} in a switch with no value

2018-04-21 Thread 'Axel Wagner' via golang-nuts
On Sat, Apr 21, 2018 at 3:30 PM wrote: > Why is this special? Because it's commonly used. Is it? I don't think I ever used an interface value in a switch. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop r

Re: [go-nuts] proposal: disallow implicitly comparing true with value of interface{} in a switch with no value

2018-04-21 Thread Jan Mercl
On Sat, Apr 21, 2018 at 3:30 PM wrote: How do you propose to formulate the exception to the existing rules? Note that this is essentially the same "problem": https://play.golang.org/p/vMc8hyQrigq package main import ( "fmt" ) func main() { var

[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread Kaveh Shahbazian
@Ankit That's what I thought. Yet the code is accessing the same underlying array. That is the part that worries me and -race does not complain. @Louki Still no complain from -race! https://play.golang.org/p/dUt0QE63RDK On Saturday, April 21, 2018 at 7:01:25 PM UTC+4:30, Louki Sumirniy wrote: >

Re: [go-nuts] On Accepting Interfaces and Structs

2018-04-21 Thread Kaveh Shahbazian
You might be right. Probably I am fixating on something that I do not understand well and just have a not positive feeling about it. But two things: 1 - Other packages (will) have implementations that satisfies first.cloner so there might be: type cloner interface { Clone() (*third.State,

Re: [go-nuts] Re: http "alt" attribute value for img tag?

2018-04-21 Thread Nigel Tao
package main import ( "fmt" "log" "strings" "golang.org/x/net/html" ) func main() { const src = ` message ` doc, err := html.Parse(strings.NewReader(src)) if err != nil { log.Fatal(err) } var f func(*html.Node) f = func(n *html.Node) { if n.Type == html.ElementNode && n.Data == "img" { for

[go-nuts] Re: On Accepting Interfaces and Structs

2018-04-21 Thread Louki Sumirniy
I only just finally wrapped my head around this stuff and forgive me if I have missed the point of the question but this is what my code has: type AbstractType alias/struct {} type abstractthing interface { DoSomething(interface{}) } func (a *AbstractType) DoSomething(b AbstractType) { } an

[go-nuts] Re: proposal: disallow implicitly comparing true with value of interface{} in a switch with no value

2018-04-21 Thread Louki Sumirniy
Your syntax is wrong. I think you mean this: var someInterfaceValue interface{} // do something that puts a value in above variable switch someInterfaceValue { case true: // do something default: // do something else } On Saturday, 21 April 2018 16:30:22 UTC+3, b97...@gmail.com wrot

[go-nuts] Re: Accessing Slices Made From Same Array Concurrently

2018-04-21 Thread silviucapota
Hi Kaveh, Change the line: *ptr = append(*ptr, []byte(fmt.Sprint*f("%02d"*, k1))...) to *ptr = append(*ptr, []byte(fmt.Sprintf(*"%15d"*, k1))...) The buckets will overlap (more than 10 bytes) and you will get the race triggered in the detector Silviu On Saturday, 21 April 2018 12:40:04 UTC-4

[go-nuts] Allow name : type declarations?

2018-04-21 Thread Hugh Fisher
I'm a new Go programmer (learning in my spare time) and decided to share my initial fumbles and what? why? moments while they're still fresh. First suggestion: allow a colon to be inserted between the name(s) and type in declarations. For example x : int func random(): real Back in th