Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Viktoriia Kapyrina Yelizarova
Well, reflection is one of the things I love in language and it is a "must". On the other hand, the automation is exactly what common libraries do, I can not find any reason to make a loops if they are repeated actions which might be implemented in general library. array_intersect is a commo

[go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread ahuigo
There is an example: https://go.dev/play/p/guzOWRKi-yp ``` func (c *cachedFn[string, V]) Get0() (V, error) { // var s any var s string s = "abc" // error: cannot use "abc" (untyped string constant) as string value in assignment fmt.Printf("cache key: %#v, %T\n", s, s) // cache key: 0, uint8 retur

[go-nuts] Shrinking pprof data for PGO through quantization.

2023-11-09 Thread 'Adam Azarchs' via golang-nuts
It's great that we have PGO support in go now, and it's relatively easy to use. One thing that is of mild concern to me is that typically one will be checking the default.pgo file in to the repo, and git is notoriously not great at handling binary blobs that are updated frequently. Its "diff

Re: [go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread 'Axel Wagner' via golang-nuts
Yes, this has come up before. On Fri, Nov 10, 2023 at 7:09 AM ahuigo wrote: > There is an example: https://go.dev/play/p/guzOWRKi-yp > > ``` > func (c *cachedFn[string, V]) Get0() (V, error) { > // var s any > var s string > s = "abc" // error: cannot use "abc" (untyped string constant) as strin

[go-nuts] go run, add string value definition with space

2023-11-09 Thread Tong Sun
go run command-line-arguments -X definition add string value definition of the form importpath.name=value I used to use this to override my variable values, in the form of go run -ldflags="-X main.var1=val1 main.var2=val2" Now, the new problem is that I need to have space in the strin

Re: [go-nuts] Shrinking pprof data for PGO through quantization.

2023-11-09 Thread 'Michael Pratt' via golang-nuts
Hi Adam, Thanks for sending this, lots of interesting ideas here! I've been meaning for a long time to have more concrete guidelines for how much data collection is enough for good results, to include on https://go.dev/doc/pgo. I also think it would be valuable to provide tooling that can help m

Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Mike Schinkel
Hi Vicktoriia, Go has reflection: https://pkg.go.dev/reflect And in its various packages it also has many (though not all) of the types of functions mentioned above that PHP has: - https://pkg.go.dev/slices & https://pkg.go.dev/golang.org/x/exp/slices - https://pkg.go.dev/maps & https://

Re: [go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread ahuigo
Btw, please ignore the type logic in my code, I wrote this piece of code just to illustrate the oddities of generics in struct methods. Regardless of whether its type is int, string, any, *or the exact uint8, this error is very strange.* // it doesn't work func (c *cachedFn[uint8, V]) Get0() (V

[go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread ahuigo
Instead of reflect library. I'd like to recommend this generic library https://github.com/samber/lo. It's very convenient than reflect, and I've been using it for a long time. If you are not familiar about how to use it, ask GPT4(GPT3.5 does't know it) On Friday, June 20, 2014 at 4:47:38 PM UTC+

Re: [go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread tapi...@gmail.com
The uint8 in cachedFn[uint8, V] is the type parameter name, it can be arbitrary valid identifier. It shadows the predeclared uint8 identifier. On Friday, November 10, 2023 at 12:25:05 PM UTC+8 ahuigo wrote: > Btw, please ignore the type logic in my code, I wrote this piece of code > just to ill

Re: [go-nuts] Re: I think in Golang, Array, Slice, and Map , all of them are very difficult to use。

2023-11-09 Thread Volker Dobler
On Thursday, 9 November 2023 at 18:35:38 UTC+1 Viktoriia Kapyrina Yelizarova wrote: ] array_intersect is a common example of automation. It makes no sense to right it again and again as it is common operation which works the same way. Except that almost all implementations of array_intersect

Re: [go-nuts] Generic type for struct method: constraint problem && cannot use (untyped string constant) as string value

2023-11-09 Thread 'Axel Wagner' via golang-nuts
I agree that it is an unfortunate error message, but to be clear, it is entirely correct - you are defining a new type called `uint8` and it is indeed not possible to assign an untyped integer constant to that, as its underlying type is a type parameter (constrained on any). I'm pretty sure there