[go-nuts] Re: Why can't an interface type be a receiver

2022-04-04 Thread Sam Hughes
So, for what it's worth: https://karthikkaranth.me/blog/functions-implementing-interfaces-in-go/ Otherwise, yeah. I'd love to be able to define interfaces with extra methods for implementors, but if you arrange your code around "traits", microstructs intended to present a possibly unergonomic

Re: [go-nuts] Why is it forbidden to add methods to an existing type?

2022-04-04 Thread Sam Hughes
Uh, you should check the code: github.com/jackc/pgtype/blob/master/float8.go If you know what you have and what you're dealing with, and if you actually check the error result, you do get safety. If you don't know what you've got, or if you're iterating through the values, then you end up hitti

Re: [go-nuts] Bring back slices.BinarySearchFunc with a predicate

2022-04-04 Thread 'Axel Wagner' via golang-nuts
Sorry, the predicate should be var b T pred := func(a T) bool { return cmp(a, b) >= 0 } On Tue, Apr 5, 2022 at 7:27 AM Axel Wagner wrote: > Hm I must say, I also don't really understand removing the predicate-based > one. It is easy, when you have a comparison function, to get to a predicate: >

Re: [go-nuts] Bring back slices.BinarySearchFunc with a predicate

2022-04-04 Thread 'Axel Wagner' via golang-nuts
Hm I must say, I also don't really understand removing the predicate-based one. It is easy, when you have a comparison function, to get to a predicate: pred := func(a, b T) bool { return cmp(a, b) >= 0 } But not the other way around, so a predicate is more general. I used the predicate version of

Re: [go-nuts] build unoptimized std lib for debugging

2022-04-04 Thread Ian Lance Taylor
On Mon, Apr 4, 2022 at 5:16 PM arthurwil...@gmail.com wrote: > > > > On Monday, April 4, 2022 at 7:00:49 PM UTC-5 arthurwil...@gmail.com wrote: >> >> On Monday, April 4, 2022 at 6:14:30 PM UTC-5 Ian Lance Taylor wrote: >>> >>> On Mon, Apr 4, 2022 at 3:49 PM arthurwil...@gmail.com >>> wrote: >>> >

Re: [go-nuts] build unoptimized std lib for debugging

2022-04-04 Thread arthurwil...@gmail.com
On Monday, April 4, 2022 at 7:00:49 PM UTC-5 arthurwil...@gmail.com wrote: > On Monday, April 4, 2022 at 6:14:30 PM UTC-5 Ian Lance Taylor wrote: > >> On Mon, Apr 4, 2022 at 3:49 PM arthurwil...@gmail.com >> wrote: >> > >> > >> > >> > On Sunday, April 3, 2022 at 10:35:04 PM UTC-5 Ian Lance

Re: [go-nuts] build unoptimized std lib for debugging

2022-04-04 Thread arthurwil...@gmail.com
On Monday, April 4, 2022 at 6:14:30 PM UTC-5 Ian Lance Taylor wrote: > On Mon, Apr 4, 2022 at 3:49 PM arthurwil...@gmail.com > wrote: > > > > > > > > On Sunday, April 3, 2022 at 10:35:04 PM UTC-5 Ian Lance Taylor wrote: > >> > >> On Sun, Apr 3, 2022 at 6:21 PM arthurwil...@gmail.com > >

Re: [go-nuts] build unoptimized std lib for debugging

2022-04-04 Thread Ian Lance Taylor
On Mon, Apr 4, 2022 at 3:49 PM arthurwil...@gmail.com wrote: > > > > On Sunday, April 3, 2022 at 10:35:04 PM UTC-5 Ian Lance Taylor wrote: >> >> On Sun, Apr 3, 2022 at 6:21 PM arthurwil...@gmail.com >> wrote: >> > >> > I'm trying to build an unoptimized version of the standard library for >> > d

[go-nuts] Re: Why can't an interface type be a receiver

2022-04-04 Thread Simon Archer
I think that playground is broken. *./prog.go:22:9: undefined: translatableImpl./prog.go:27:11: undefined: translatableImplGo build failed.* I fixed it like this: https://go.dev/play/p/vZlwZIe9Ras On Monday, April 4, 2022 at 1:27:46 PM UTC-4 Ron Green wrote: > in case anyone get's here

[go-nuts] Bring back slices.BinarySearchFunc with a predicate

2022-04-04 Thread Sudhir Jonathan
The earlier method signature for slices.BinarySearchFunc was very useful: It was of the form ``` slices.BinarySearchFunc(array, func(e T) bool) ``` which returned the smallest index at which predicate would return true. This was incredibly useful to do inequality operation binary searches - l

Re: [go-nuts] build unoptimized std lib for debugging

2022-04-04 Thread arthurwil...@gmail.com
On Sunday, April 3, 2022 at 10:35:04 PM UTC-5 Ian Lance Taylor wrote: > On Sun, Apr 3, 2022 at 6:21 PM arthurwil...@gmail.com > wrote: > > > > I'm trying to build an unoptimized version of the standard library for > debugging. > > You can just use > > go build -gcflags=all="-N -l" > > Th

Re: [go-nuts] Convert string to time.Duration

2022-04-04 Thread vika...@gmail.com
Thanks all for the hint and the snippets. I am all set now. On Tuesday, 5 April 2022 at 00:13:46 UTC+10 tay...@fastmail.com wrote: > Take a look at time.ParseDuration and its example: > https://pkg.go.dev/time#ParseDuration > > On Sun, Apr 3, 2022, at 3:48 PM, vika...@gmail.com wrote: > > I am l

Re: [go-nuts] Looked at using Go ... nil/SEGV really bothered me .. Go2 Proposal?

2022-04-04 Thread Sam Hughes
I was really annoyed that, apparently, I accidentally deleted the message you're replying to, immediately after writing it. I agree with you about being possibly surprised by values of outside of an expected range. The benefit of the above is merely that accessing it is guaranteed to be checked

[go-nuts] Re: Why can't an interface type be a receiver

2022-04-04 Thread Ron Green
in case anyone get's here and is confused... you can wrap the additional functionality in the struct and use the interfaces from before https://go.dev/play/p/e8aS0PZC6Zh On Monday, February 2, 2015 at 2:55:30 PM UTC+2 oju...@gmail.com wrote: > The code start to get smart when you combine inter

[go-nuts] [security] Go 1.18.1 and Go 1.17.9 pre-announcement

2022-04-04 Thread Julie Qiu
Hello gophers, We plan to issue Go 1.18.1 and Go 1.17.9 on Thursday, April 7th. These minor releases include a PRIVATE security fix to the standard library. Following our security policy, this is the pre-announcement of those releases. Thanks, Julie on behalf of the Go team -- You received th

Re: [go-nuts] Convert string to time.Duration

2022-04-04 Thread taylor
Take a look at time.ParseDuration and its example: https://pkg.go.dev/time#ParseDuration On Sun, Apr 3, 2022, at 3:48 PM, vika...@gmail.com wrote: > I am looking to convert a *string* (say 4) to type *time.Duration*. > > I've looked around but could not find a way to do so. > > // https://go.de

[go-nuts] Re: Java to Go converter - 2

2022-04-04 Thread alex-coder
*Another use case for automatically translating codewritten in Java to Golang is Exception Handling.The next example is likely to be about multithreading.Example in Java:* package com.builder.start.here; public class CatchException { public static void main(String[] args) { try