Re: [go-nuts] how to declare type as interface{}
Hello, > but this doesn't work: > > if err := json.NewDecoder(resp.Body).Decode({}{}); err != nil { > t.Fatal(err) > } You can use new(interface{}). See https://play.golang.org/p/s85MwlDygBG Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200903222503.GA4288%40hweidner.de.
Re: [go-nuts] Assigning byte to string location is not allowed
Hello, > Why is this not allowed? > > s := "hello" > s[0] = 'a' // compile error: cannot assign to s[0] Because strings are immutable in Go. See https://golang.org/ref/spec#String_types You can construct a new string, or convert to byte slive and back. https://play.golang.org/p/0LvsxCCTM2G Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200813131930.GA15579%40hweidner.de.
Re: [go-nuts] Generics and parentheses
Hello, > A typical computer keyboard provides four easily accessible pairs of > single-character symmetrical "brackets": parentheses ( and ), square > brackets [ and ], curly braces { and }, and angle brackets < and >. Go uses > curly braces to delineate code blocks, composite literals, and some > composite types, making it virtually impossible to use them for generics > without severe syntactic problems. Angle brackets require unbounded parser > look-ahead or type information in certain situations (see the end of this > e-mail for an example). This leaves us with parentheses and square > brackets. Another option would be the introduction of a new two-letter "bracket" operator, for example <: and :> . This could be parsed without symbol/type information and even without the "type" keyword. That said, I'm fine with any syntax. Thank you for your work on generics! Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200714223122.GA6955%40hweidner.de.
Re: [go-nuts] Re: [generics] some questions
Hello, > But the following code also fails to compile, bug? > > package main > > type Int interface { > type int > } > > func Foo(type T Int) ([]T) {} // undefined: MyInt > > func main() { > type MyInt int > Foo([]MyInt(nil)) > } It compiles if you move "type MyInt int" out of the func main scope. See https://go2goplay.golang.org/p/_sWi72-0rD1 Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200618121650.GA16023%40hweidner.de.
Re: [go-nuts] [generics] A Channel of a Generic Structure
Hello, > Here is the playground: https://go2goplay.golang.org/p/CVvUuNJVX-M > I am unable to make this example to compile. This one compiles: https://go2goplay.golang.org/p/2rmaCymukdv Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200617213655.GB10193%40hweidner.de.
Re: [go-nuts] Re: [generics] Generic functions calls little confusing to readers
Hello, > There is an existing case which doesn't seem to bother many people: > > foo.Bar() > > Is this calling function Bar in package foo, or method Bar on variable > foo? It could also be a call of a function within the struct value foo. foo.Bar(baz) can have at least four meanings: 1. calling a function Bar in package foo with parameter baz 2. calling a method Bar on value foo with parameter baz 3. calling a function Bar in struct value foo with parameter baz 4. converting a variable (or constant) baz to type Bar in package foo and with generics 5. instanciating a generic type Bar in package foo with type parameter baz > Sometimes I come across this - when looking at someone else's code, it's > not always instantly obvious whether "settings" is a package or a > variable. Normally you don't need to look far though. Those ambiguities have always been there. To read foreign code, you have to look up the symbols from left to right. Most editors can help you with this. That said, I am fine with the current generics proposal. Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200617174731.GA10193%40hweidner.de.
Re: [go-nuts] go run requires internet connection?
Hello, On Wed, Apr 08, 2020 at 06:00:19AM -0700, Tanmay Das wrote: > go run helloworld.go > > Strangely the code didn't run. In fact, the terminal prompt never exited. I > kept running the same command over and over again but no luck. You can run "go run -x helloworld.go" to see what the toolchain is doing. Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200408164326.GA12138%40hweidner.de.
Re: [go-nuts] Разбить массив чисел на два массива
Hello, > I'm not sure if that is a good idea > https://play.golang.org/p/Mj77pgsaVsB This is why three-index slices were added in Go 1.2. https://play.golang.org/p/_sJ9OKWsvMz https://golang.org/doc/go1.2#three_index Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20191201210651.v4a2cjgorkeqnap2%40hweidner.de.
Re: [go-nuts] How many Go compilers are out there?
Hello, On Thu, Apr 25, 2019 at 08:54:57AM -0700, Ian Lance Taylor wrote: > On Thu, Apr 25, 2019 at 8:29 AM JuciÊ Andrade wrote: > > > > These are the ones I am aware of: > > > > . GC toolchain > > . GCC > > . gopherjs > > > > By Go compiler I mean any tool that understands Go source files and > > generates executable code. > > There is also llgo (though I'm not sure if that one still works) and GoLLVM. There is also Joy, another Go-to-JS Compiler. https://mat.tm/joy/ EmGo and TinyGo are two Embedded Go (cross) compilers. https://github.com/ziutek/emgo https://github.com/tinygo-org/tinygo The SSA interpreter and gomacro are also somewhat related to a Go compiler. https://godoc.org/golang.org/x/tools/go/ssa/interp https://github.com/cosmos72/gomacro Regards, Harald -- 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...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20190508120306.esfver4pqjezkxn7%40hweidner.de. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] undefined and implementation defined behavior in Go
Hello, > I was trying to get a list of undefined and implementation defined > behaviors of the Go language from the specification, but it was not easy. > I tried to search for "undefined behavior" and "implementation defined > behavior" without success. [...] > Is this list complete? The language spec also contains once "unspecified", twice "implementation-defined" and three times "implementation-specific". The exact order in which goroutines are executed is also undefined, see "method 3" of this funny blog article: https://blog.merovius.de/2018/01/15/generating_entropy_without_imports_in_go.html I would also consider the order in which init() functions of the same package are executed undefined. The spec says they are executed "in the order they appear in the source, possibly in multiple files, as presented to the compiler". However, I believe a command like "go run *.go" can yield different orders, according to the shell, shell settings, or filesystem charset/collation settings. Regards, Harald -- 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...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: do you use binary-only packages?
Hallo, On Fri, Oct 19, 2018 at 11:45:04AM -0700, Ian Lance Taylor wrote: > > Unhelpfully, I imagine it unlikely that anyone distributing binary go > > packages reads golang-dev or golang-nuts. > > Is there a more likely place to reach such people? I believe the best ways to reach attention on such issues are currently the official Go blog and the the Golang Weekly Newsletter. At least I know of IT magazines here in Germany, that watch these sources and aquire content for their online platforms from there. Regards, Harald -- 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...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] SQL database connection
Hello, On Mon, Sep 19, 2016 at 01:37:14AM -0700, loc...@gmail.com wrote: > import( > _ "github.com/go-sql-driver" > ) The correct name of this package is: github.com/go-sql-driver/mysql Harald -- 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...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] flag: Stack overflow when return stringer with fmt.Sprint
Hello, On Thu, Sep 01, 2016 at 01:59:12AM -0700, Muhammad Shulhan wrote: > > type Slices []string > > > > func (sl *Slices) String() string { > > return fmt.Sprint(sl) > > } > runtime: goroutine stack exceeds 25000-byte limit > fatal error: stack overflow It is always dangerous to call fmt.Sprint() (or any other print method of the fmt package) from a String() method of a value that implements the Stringer interface. fmt.Sprint() might call the String() method itselfes, which leads to infinite recursion. >From the fmt documentation (https://golang.org/pkg/fmt/#pkg-overview): | [...] | 5. If an operand implements method String() string, that method will be | invoked to convert the object to a string, which will then be formatted as | required by the verb (if any). Wether this happens or not depends on the concrete execution path of fmt.Sprint(). Even if three of your four exampes work, I guess they could fail with future implementations of the fmt package. You should always pass basic types to fmt.Sprint(), e.g. func (sl *Slices) String() string { return fmt.Sprint([]string(*sl)) } Again, from the fmt documentation: | To avoid recursion in cases such as | | type X string | func (x X) String() string { return Sprintf("<%s>", x) } | | convert the value before recurring: | | func (x X) String() string { return Sprintf("<%s>", string(x)) } | | Infinite recursion can also be triggered by self-referential data | structures, such as a slice that contains itself as an element, if that type | has a String method. Such pathologies are rare, however, and the package | does not protect against them. Harald -- 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...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: In case you missed it: language benchmarks for Go 1.7, and language adoption
Hello, On Tue, Aug 30, 2016 at 04:41:29PM -0700, 'Eric Johnson' via golang-nuts wrote: > I looked at the k-nucleotide program, and was unable to figure out a way to > make it faster. > This is, of course, exactly what the test is suppose to be checking - the > speed of the built in map. Anyone else have any insight? The Java counterpart of this benchmark does not use the Java build-in maps, but imports a map implementation for fixed data types from the fastutil project. http://fastutil.di.unimi.it/ Those libraries are based on generated source code. I think something similar could be built for Go. Harald -- 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...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.