Re: [go-nuts] Generics: after type lists

2020-08-13 Thread Patrick Smith
Sorry, I accidentally sent the previous message before it was complete. Please ignore that one. On Tue, Aug 11, 2020 at 8:31 PM Ian Lance Taylor wrote: > To me the point of your String example is: Go already has various ways > of writing generic code. You can use interfaces, methods, and type >

Re: [go-nuts] where is go code generate type info?

2020-08-13 Thread xie cui
how can i see the code genrate by compiler, and where is the compiler code to generate these code(which file, which function). i am just curious. On Friday, August 14, 2020 at 1:32:25 PM UTC+8 Volker Dobler wrote: > The value returned by reflect.TypeOf is not computed during > compile time but d

Re: [go-nuts] Generics: after type lists

2020-08-13 Thread Patrick Smith
On Tue, Aug 11, 2020 at 8:31 PM Ian Lance Taylor wrote: > To me the point of your String example is: Go already has various ways > of writing generic code. You can use interfaces, methods, and type > assertions. You can use reflection. The generics design draft adds > another way: parametric po

Re: [go-nuts] where is go code generate type info?

2020-08-13 Thread Volker Dobler
The value returned by reflect.TypeOf is not computed during compile time but during run time. The code for package reflect is generated by the compiler during compile time but this is not interesting to understand reflection at all as it is the same code generation like for lets say net/http. The

[go-nuts] [ generics ] Concrete example of comparables and generic function types

2020-08-13 Thread Beka Westberg
Hello! I just ran into a problem that is solved really nicely with the new generics proposal and I thought someone might find it interesting :D I was trying to implement a library for doing ascii art programmatically. The main struct is basically an image.Image except it works with bytes instea

Re: [go-nuts] where is go code generate type info?

2020-08-13 Thread xie cui
the return of reflect.TypeOf should be generate by compile, i am trying to understand it, so i need to know where is code generate it in compiler. i need to know compiler parts. and i am curious about what is do in user code also. please tell me about it. i will be appriciated. On Thursday, Au

[go-nuts] Re: Go Benchmarks And Escape Analysis

2020-08-13 Thread jake...@gmail.com
0.00429 ns/op seems suspiciously low. I suspect that there could be a problem with your benchmark. Could you post the code. ( On this mailing list please just send code as plain text or as a link to the Go playground.) On Thursday, August 13, 2020 at 9:18:52 PM UTC-4 Patrick wrote: > I'm new

[go-nuts] Go Benchmarks And Escape Analysis

2020-08-13 Thread Patrick
I'm new to go, and have being looking at escape analysis by benchmarking some code that I created. What I see is the escape analysis shows that certain variables escape to the heap. parameter path leaks to {heap} with derefs=2 But the result of the benchmark test shows 0 allocations. 100

[go-nuts] Re: [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread jake...@gmail.com
Am I correct in thinking this has NOT been added to the go2go playground yet? When I try the example it fails: https://go2goplay.golang.org/p/TiMsP2K_3DS Or am I making some stupid mistake? On Wednesday, August 12, 2020 at 10:31:51 PM UTC-4 Ian Lance Taylor wrote: > I just added a new section t

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Steven Blenkinsop
On Thu, Aug 13, 2020 at 7:35 PM, jimmy frasche wrote: > If I have > func F[type E interface{}, S constraints.Slice[E]]() S > are the following equivalent: > F[int, []int] > F[int] > F[[]int] > or are only 2 of the 3 permissible? Does that change if I swap the > type parameters? >From th

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread jimmy frasche
If I have func F[type E interface{}, S constraints.Slice[E]]() S are the following equivalent: F[int, []int] F[int] F[[]int] or are only 2 of the 3 permissible? Does that change if I swap the type parameters? On Thu, Aug 13, 2020 at 4:31 PM Michael Jones wrote: > > Yes, thank you. In inte

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Michael Jones
Yes, thank you. In intellectual shame I must say that I somehow understood that the generics needed to be "leaf" functions. Thank you for demonstrating my oversight. Happier now. Michael On Thu, Aug 13, 2020 at 3:47 PM Bakul Shah wrote: > On Aug 13, 2020, at 3:29 PM, Michael Jones > wrote: > >

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Steven Blenkinsop
On Thu, Aug 13, 2020 at 6:30 PM Ian Lance Taylor wrote: > > If I understand you correctly, we changed that when we added the > constraint type inference section. See the updated > > https://go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md#type-inference > secti

Re: [go-nuts] "Interfaces" with type lists are a strange beast

2020-08-13 Thread Peter McKenzie
On Sunday, August 9, 2020 at 4:17:06 AM UTC+12, Ian Lance Taylor wrote: > > On Fri, Aug 7, 2020 at 6:54 PM Robert Engels > wrote: > > > > I’d really like to see an example of generic code that takes both string > and numeric types that uses operators. Sorting/searching is one but as I > alre

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Bakul Shah
On Aug 13, 2020, at 3:29 PM, Michael Jones wrote: > > The all-or-none aspect would be sidestepped if it were allowed to define > "partial generics": > > func A (T1, T2) (...){} > > func B(T)(...){ A(T,int)(...){...} } > > Allowing B to exist just means running the whole generic thing iter

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Ian Lance Taylor
On Thu, Aug 13, 2020 at 3:09 PM roger peppe wrote: > > I do feel that the "all or nothing" nature of type parameter lists (if you > specify one type parameter, you must explicitly specify all of the others > too, even if they could otherwise be inferred) is likely to get in the way > here. I'd

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Michael Jones
The all-or-none aspect would be sidestepped if it were allowed to define "partial generics": func A (T1, T2) (...){} func B(T)(...){ A(T,int)(...){...} } Allowing B to exist just means running the whole generic thing iteratively until no resolution is changed. If the fixed point still has ge

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread roger peppe
That's interesting; thanks for the heads up. My initial reaction is that this perhaps feels a bit "clever", but perhaps this feeling will go away in time. Constraint type inference is useful when a function wants to have a type > name for an element of some other type parameter, or when a functio

Re: [go-nuts] Go1.15 + SQLite Driver + Windows + Ld.exe results in ld error "unrecognized option --high-entropy-va"

2020-08-13 Thread Corey Gilmore
Updating ld (via binutils) to 2.33.1 in fixed the issue. Looks like 2.33.1 is the newest available version via TDM-GCC. Thanks for the help! On Thursday, August 13, 2020 at 3:13:51 PM UTC-4 Ian Lance Taylor wrote: > On Thu, Aug 13, 2020 at 12:01 PM Corey Gilmore > wrote: > > > > Setup: > >

Re: [go-nuts] [generics] Was "no type contracts" considered?

2020-08-13 Thread Ian Lance Taylor
On Wed, Aug 12, 2020 at 9:58 AM Markus Heukelom wrote: > > > > On Mon, Aug 10, 2020 at 8:30 PM Ian Lance Taylor wrote: >> >> Go is a strictly typed languages, and constraints are the meta-types >> of type parameters. > > > I just realised there might be a distinction between strictly typed and >

Re: [go-nuts] go module name

2020-08-13 Thread Misha Gusarov
On 13 Aug 2020, at 21:01, Trig wrote: > Is there a way to get the go module name out of the go mod, if modules > used, besides opening the go.mod file directly (or another obvious name to > get the project name I'm not thinking of)? go list -m -- Misha -- You received this message because you

Re: [go-nuts] Go1.15 + SQLite Driver + Windows + Ld.exe results in ld error "unrecognized option --high-entropy-va"

2020-08-13 Thread Ian Lance Taylor
On Thu, Aug 13, 2020 at 12:01 PM Corey Gilmore wrote: > > Setup: > - Go 1.15 > - https://github.com/mattn/go-sqlite3 SQL driver > - Windows 10 (2004) > - Ld.exe (via MingW via TDM-GCC), version 2.25 > > Prior to go1.15, running "go run main.go" or "go build" would work without > issue. With go1.

Re: [go-nuts] map without default values

2020-08-13 Thread Michael Jones
Joe, your question is perfectly answered by Axel. I'll just share a few (personal) Go "style" comments: Go likes you to test explicitly for failure where that is possible: did the open fail, did the pipe break, etc.Multiple return values make this clear by avoiding the need for a "reserved" error

[go-nuts] Go1.15 + SQLite Driver + Windows + Ld.exe results in ld error "unrecognized option --high-entropy-va"

2020-08-13 Thread Corey Gilmore
Setup: - Go 1.15 - https://github.com/mattn/go-sqlite3 SQL driver - Windows 10 (2004) - Ld.exe (via MingW via TDM-GCC), version 2.25 Prior to go1.15, running "go run main.go" or "go build" would work without issue. With go1.15, the error "ld.exe: unrecognized option '--high-entropy-va'" occurs.

[go-nuts] go module name

2020-08-13 Thread Trig
Is there a way to get the go module name out of the go mod, if modules used, besides opening the go.mod file directly (or another obvious name to get the project name I'm not thinking of)? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsu

Re: [go-nuts] map without default values

2020-08-13 Thread 'Axel Wagner' via golang-nuts
No, there isn't, but you can check if the value exists: x, ok := m[k] if !ok { panic("does not exist") } You can also wrap that with methods, if you want to avoid the extra check. I disagree with you that panicking on a non-existent key is better - either in general, or in the majority of ca

[go-nuts] map without default values

2020-08-13 Thread Joe Marty
I'm very new to Go - apologies in advance if I'm missing something: I find it frustrating that there's no way to create a map that does *not* automatically return a zero value for undefined key access by default. I love the fact that Go doesn't return "nil" for this use case (I love Ruby, but I

[go-nuts] Re: using go build for compiling go source code into object files

2020-08-13 Thread Brian Candler
On Thursday, 13 August 2020 17:21:28 UTC+1, saurav deshpande wrote: > > 1. not able to use go cross compiler for compiling desired object file. I > tried setting goarch and goos but it doesnt work for me. > It works for the rest of us. For example: I compile macOS darwin binaries under Linux.

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread Ian Lance Taylor
On Thu, Aug 13, 2020 at 9:22 AM jimmy frasche wrote: > > Would the constraints package have Pointer[E], Slice[E], and so on? Good question. I don't know. We can certainly add them if we see people using them. > What happens if you have > type SC(type E I) interface { > type []E > } >

Re: [go-nuts] Is there any plan for go plugin .so can be used by different version of go from compiled?

2020-08-13 Thread Ian Lance Taylor
On Thu, Aug 13, 2020 at 9:21 AM zhizhao wang wrote: > > If go plugin .so used by different version of go from compiled, the different > package error will occur. > So is there any plan to fix this problem? I am not aware of anybody working on this. It's a very hard problem. Ian -- You receiv

[go-nuts] executing command via ssh on different router models

2020-08-13 Thread mishanya alpseilsevv
Hi. My task is execute command on different routers and receive command output I'm using *golang.org/x/crypto/ssh* package Cisco works fine. But on HP output ends on prompt right before actual command. Maybe someone have experience executing commands via ssh on HP routers and can give me some

[go-nuts] Clean Architecture in Go - Dynamic Projection

2020-08-13 Thread Sarath Prabath Redlapalli Jaya
Hi All, We've a complex and nested Domain Object *User* type User struct { Profile *Profile // .. // .. } stored in a SQL database as id, user_name, email, image(*Profile*), category(Profile) Using Clean Architecture by having SQL Database behind an interface, how can we best implemen

Re: [go-nuts] How to handle large amount of data on the frontend using go template and cassandraDB?

2020-08-13 Thread Mhd Shulhan
Pada tanggal Kam, 13 Agu 2020 23.21, menulis: > > https://stackoverflow.com/questions/63393803/how-to-handle-large-amount-of-data-on-the-frontend-using-go-template-and-cassand?noredirect=1#comment112097067_63393803 > > I am using *golang* to load data from CassandraDB and send it to the view > co

Re: [go-nuts] [ generics ] Added constraint type inference to the design draft

2020-08-13 Thread jimmy frasche
I don't care for the (type T Equaler) example. It makes one thing look like another. The rest seems interesting. Obviating and generalizing the * syntax is certainly promising and a nice justification for type lists. Would the constraints package have Pointer[E], Slice[E], and so on? What happen

[go-nuts] Is there any plan for go plugin .so can be used by different version of go from compiled?

2020-08-13 Thread zhizhao wang
If go plugin .so used by different version of go from compiled, the different package error will occur. So is there any plan to fix this problem? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving e

[go-nuts] using go build for compiling go source code into object files

2020-08-13 Thread saurav deshpande
I have been trying to develop a basic kernel in golang, few problems I have faced are: 1. not able to use go cross compiler for compiling desired object file. I tried setting goarch and goos but it doesnt work for me. 2. I want to use sturctures and interfaces but dont know how should i use t

[go-nuts] How to handle large amount of data on the frontend using go template and cassandraDB?

2020-08-13 Thread xdxx2017
https://stackoverflow.com/questions/63393803/how-to-handle-large-amount-of-data-on-the-frontend-using-go-template-and-cassand?noredirect=1#comment112097067_63393803 I am using *golang* to load data from CassandraDB and send it to the view component, but it takes almost *2min to load 20k rows of d

Re: [go-nuts] where is go code generate type info?

2020-08-13 Thread Jan Mercl
On Thu, Aug 13, 2020 at 3:53 PM xie cui wrote: > ..., i know this type struct in generate by compiler, and i need to know > where is this code, and how to generate the struct fields and methods? To avoid the possibility of the XY problem, can you please tell more about the goal of "generating s

[go-nuts] Frontend languages utf-16 bubble

2020-08-13 Thread Kevin Chadwick
On 2020-08-13 14:16, Brian Candler wrote: > If you want a mutable string, look at []byte instead, and read the excellent > intro to slices at https://blog.golang.org/slices Does anyone think the frontend languages can be persuaded to meet the web standards and switch to Utf-8, rather than sticking

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Kevin Chadwick
On 2020-08-13 14:16, Brian Candler wrote: > > If you want a mutable string, look at []byte instead, and read the excellent > intro to slices at https://blog.golang.org/slices > Also worth remembering that unicode strings aren't necessarily bytes, so requiring verbose action for byte access, inst

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Brian Candler
Immutable strings are a useful language feature. For one thing, it makes them usable as map keys, without having to duplicate the entire contents. A copy-by-value is cheap (it copies only the pointer and length): b := a ... but you know that there are never any issues around aliasing, e.g.

[go-nuts] where is go code generate type info?

2020-08-13 Thread xie cui
package main import ( "fmt" "reflect" ) type Foo struct { A int } func (f *Foo) Test() { } func main() { f := &Foo{} t := reflect.TypeOf(f) fmt.Println(t) } when call reflect.TypeOf can get a struct desc the type, i know this type struct in generate by compiler, and i need to know where is th

Re: [go-nuts] Seperate debuginfo?

2020-08-13 Thread 'Ethan Pailes' via golang-nuts
I've worked on this some more now, and it turns out that while directly executing the result of `upx -9` breaks, you can use `upx --exact -9` to compress your exe and then `upx -d` to decompress it later. The decompressed executable works with the .debug file. On Wednesday, August 12, 2020 at 3:

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Sathish VJ
Why would the design not allow the contents of the string to be changed? I understand that the size and memory allocation for it is immutable. On Thursday, 13 August 2020 at 18:50:10 UTC+5:30 Jan Mercl wrote: > On Thu, Aug 13, 2020 at 3:02 PM Sathish VJ wrote: > > > Why is this not allowed?

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Jan Mercl
On Thu, Aug 13, 2020 at 3:02 PM Sathish VJ wrote: > Why is this not allowed? > > s := "hello" > s[0] = 'a' // compile error: cannot assign to s[0] > > https://play.golang.org/p/zyJXwhEeKPo Strings are immutable: once created, it is impossible to change the contents of a string.

Re: [go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Harald Weidner
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/0LvsxCC

[go-nuts] Re: best way to know executable version without running it

2020-08-13 Thread Sathish VJ
Maybe you are asking how to get build version information into the executable. If yes, then use -ldflags. https://pmcgrath.net/include-version-information-in-golang-app On Thursday, 13 August 2020 at 15:12:36 UTC+5:30 seank...@gmail.com wrote: > go version -m > > On Thursday, August 13, 2020

[go-nuts] Assigning byte to string location is not allowed

2020-08-13 Thread Sathish VJ
Why is this not allowed? s := "hello" s[0] = 'a' // compile error: cannot assign to s[0] https://play.golang.org/p/zyJXwhEeKPo -- 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

Re: [go-nuts] "Interfaces" with type lists are a strange beast

2020-08-13 Thread roger peppe
On Wed, 12 Aug 2020 at 16:43, 李晓辉 wrote: > Maybe `type list` equals to `sum type` > > type SignedInteger interface { >type int, int8, int16, int32, int64 > } > > can replaced by > > type SignedInteger int|int8|int16|int32|int64 > Yes, I've had that thought too (and mentioned it as feedba

[go-nuts] Re: best way to know executable version without running it

2020-08-13 Thread seank...@gmail.com
go version -m On Thursday, August 13, 2020 at 10:30:56 AM UTC+2 santhoshth...@gmail.com wrote: > Hi All, > > What is best way to know a executable version without executing it through > golang? > > I tried with reading the executable file through a scanner and matching > every line with regex

[go-nuts] best way to know executable version without running it

2020-08-13 Thread thatipelli santhosh
Hi All, What is best way to know a executable version without executing it through golang? I tried with reading the executable file through a scanner and matching every line with regex (like ngnix regx) but this is not working for all executables. Do you have any idea? -- You received this mes