Re: [go-nuts] Mathematical operations - the generics way

2022-03-22 Thread Endre Simo
I found a working version meantime. // Max returns the bigger value between two numbers. func Max[T constraints.Ordered](x, y T) T { if x > y { return x } return y } // Abs returns the absolut value of x. func Abs[T constraints.Signed | constraints.Float](x T) T { if x < 0 { return -x } return x

Re: [go-nuts] Re: Is there a way to eliminate the code repetition in the code?

2022-03-22 Thread tapi...@gmail.com
Is it hard to add two predeclared constraints, convertibleFrom and convertibleTo, just like comparable? On Tuesday, March 22, 2022 at 11:07:41 PM UTC+8 Ian Lance Taylor wrote: > On Tue, Mar 22, 2022 at 6:01 AM tapi...@gmail.com > wrote: > > > > > > > > On Monday, March 21, 2022 at 3:29:44 PM U

Re: [go-nuts] Using LineToPC on mac

2022-03-22 Thread Ian Lance Taylor
On Tue, Mar 22, 2022 at 8:29 AM Yarden Laifenfeld wrote: > > Here is the output (I only printed the file names because the objs are huge): It does look like the main.go file is there. I don't have any other thoughts, sorry. Ian -- You received this message because you are subscribed to the Go

Re: [go-nuts] Using LineToPC on mac

2022-03-22 Thread Yarden Laifenfeld
Here is the output (I only printed the file names because the objs are huge): File: /Users/yarden/go/go1.18/src/os/env.go File: /Users/yarden/go/go1.18/src/io/fs/walk.go File: /Users/yarden/go/go1.18/src/runtime/write_err.go File: /Users/yarden/go/go1.18/src/runtime/lfstack.go File: /Users/yarden/

Re: [go-nuts] Using LineToPC on mac

2022-03-22 Thread Ian Lance Taylor
On Tue, Mar 22, 2022 at 7:46 AM Yarden Laifenfeld wrote: > > https://goplay.space/#6BZX0IDRm76 > This is my code, on elf files it works but macho it doesn't. I don't see any > difference between what I did and the implementation in cmd/internal/objfile. Yes, that looks OK to me. I don't have a

Re: [go-nuts] Re: Is there a way to eliminate the code repetition in the code?

2022-03-22 Thread Ian Lance Taylor
On Tue, Mar 22, 2022 at 6:01 AM tapi...@gmail.com wrote: > > > > On Monday, March 21, 2022 at 3:29:44 PM UTC+8 Henry wrote: >> >> Perhaps something like this? >> ```go >> func Convert[T, A any](src []T, converter func(T) A) []A { >> result := make([]A, len(src)) >> for index, a :=

Re: [go-nuts] Using LineToPC on mac

2022-03-22 Thread Yarden Laifenfeld
https://goplay.space/#6BZX0IDRm76 This is my code, on elf files it works but macho it doesn't. I don't see any difference between what I did and the implementation in cmd/internal/objfile. On Tuesday, March 22, 2022 at 4:30:28 PM UTC+2 Ian Lance Taylor wrote: > On Tue, Mar 22, 2022 at 3:32 AM Y

Re: [go-nuts] Using LineToPC on mac

2022-03-22 Thread Ian Lance Taylor
On Tue, Mar 22, 2022 at 3:32 AM Yarden Laifenfeld wrote: > > I'm trying to use the LineToPC function (in gosym) on a mach-o file but it > always fails, even though the __gopclntab section of my mach-o file does seem > populated. It works perfectly well on ELF files, and I also saw the tests for

[go-nuts] Re: Is there a way to eliminate the code repetition in the code?

2022-03-22 Thread tapi...@gmail.com
On Monday, March 21, 2022 at 3:29:44 PM UTC+8 Henry wrote: > Perhaps something like this? > ```go > func Convert[T, A any](src []T, converter func(T) A) []A { > result := make([]A, len(src)) > for index, a := range src { > result[index] = converter(a) > }

[go-nuts] Using LineToPC on mac

2022-03-22 Thread Yarden Laifenfeld
Hey! I'm trying to use the LineToPC function (in gosym) on a mach-o file but it always fails, even though the __gopclntab section of my mach-o file does seem populated. It works perfectly well on ELF files, and I also saw the tests for the function in the golang repo are specifically for ELFs. I