Re: [go-nuts] minicrypt released

2025-05-19 Thread roger peppe
My initial reaction is this: you assert that this is easy to use but don't say anything about how to use it or explain _why_ it's easy to use, or even exactly what it is (is it a command line program, a graphical app or what?). It might be worth addressing those issues if you want more feedback!

Re: [go-nuts] Experience Report: Using Coroutines for Parsing

2025-03-26 Thread roger peppe
nd goroutine in my stack dumps, which was always a bit > surprising. > > - Jason > > > On Monday, November 18, 2024 at 10:22:10 PM UTC roger peppe wrote: > >> On Mon, 18 Nov 2024 at 18:02, Romain Doumenc >> wrote: >> >>> Hi Roger, >>>

Re: [go-nuts] Efficiently switch io.Reader to another decoder on error

2025-01-14 Thread roger peppe
Tangentially related to this thread, a while back, I wrote a Go implementation of the base64 command that is agnostic about which encoding it reads (and can write all the possible encodings). It can be installed with: go install github.com/rogpeppe/misc/cmd/base64@latest It's arguably a little too

Re: [go-nuts] announcing gosim: simulation testing for Go

2024-12-10 Thread roger peppe
Impressive stuff! Some potentially interesting overlap with the new "synctest" package. Do you have any thoughts on that? On Tue, 10 Dec 2024 at 17:41, Jelle van den Hooff wrote: > Hi golang-nuts, > > I am excited to share Gosim: simulation testing for Go ( > https://github.com/jellevandenhooff

Re: [go-nuts] Re: zero in the new unique package

2024-12-04 Thread roger peppe
On Thu, 28 Nov 2024 at 23:36, 'Константин Иванов' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hello. > > May be because all zero-size values have the same pointer: > https://go.dev/play/p/n0dKQFN2EpR > Because the values have no memory location. > I think that's *part* of the story:

Re: [go-nuts] Experience Report: Using Coroutines for Parsing

2024-11-18 Thread roger peppe
On Mon, 18 Nov 2024 at 18:02, Romain Doumenc wrote: > Hi Roger, > > Glad you found this interesting, and thank you for reading ! > > One can obviously always use methods on a structure instead of > coroutines (in the example I provided, the state could be stored in > th

Re: [go-nuts] Experience Report: Using Coroutines for Parsing

2024-11-18 Thread roger peppe
Interesting! Thanks for sharing. This is related to something that I've been planning to explore for a while now: using iterators themselves and their associated coroutines accessed via `iter.Pull`, to do parsing. That is, instead of gaining access to the underlying coroutine machinery by use of "

Re: [go-nuts] atomic variables?

2024-11-08 Thread Roger
tion between threads.* > > On Thursday, November 7, 2024 at 3:13:38 PM UTC-8 Ian Lance Taylor wrote: > >> On Thu, Nov 7, 2024 at 2:54 PM Roger wrote: >> > >> > True or false, it's better to avoid loading atomic variables >> unnecessarily? >> >&g

[go-nuts] atomic variables?

2024-11-07 Thread Roger
Hi, True or false, it's better to avoid loading atomic variables unnecessarily? -- 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...@googlegr

Re: [go-nuts] tuples! tuples! tuples!

2024-04-30 Thread roger peppe
V] {return func(yield func(v V) bool)) { > yield(f("1234"))}}* > > > *If it wouldn't be valid, why not? If it's OK, what would it print?* > My understanding is that how helpful type inference can be is not a > question of specificat

Re: [go-nuts] tuples! tuples! tuples!

2024-04-29 Thread roger peppe
On Sun, 28 Apr 2024 at 12:10, Andrew Harris wrote: > Bouncing out from some recent discussions on the github issue tracker, it > seems like there's some interest in tuples in Go. I thought the discussion > in #66651 led to some interesting ideas, but it's also beginning to drift. > Maybe this is

Re: [go-nuts] tuples! tuples! tuples!

2024-04-28 Thread roger peppe
I agree with Ian that the named field syntax is too close to structs. For me, tuples start to make sense in Go mainly because they map directly to and from the tuple-like values we already pass to and from functions, and specifically in the context of a variadic type parameter language feature tha

Re: [go-nuts] GO111MODULE=off go get deprecated?

2024-03-11 Thread roger peppe
It's not quite what you're after, but FWIW the gohack command ( github.com/rogpeppe/gohack) knows enough to download arbitrary Go modules including the VCS checkout. You might find it useful, I guess. For example: % gohack get -vcs golang.org/x/mod creating golang.org/x/mod@v0.16.0 golang.org/x/m

Re: [go-nuts] assert library with generics?

2024-02-26 Thread roger peppe
I'm biased because I had a big hand in designing the API, but I get a lot of pleasure from using this package: https://pkg.go.dev/github.com/go-quicktest/qt It does a lot more than just "equals" and "not equals" but it's still relatively small and low-dependency. And the error messages when i

Re: [go-nuts] Type parameter embedded field

2024-01-09 Thread roger peppe
On Fri, 5 Jan 2024 at 05:58, 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi, > > I think the reason this has not happened is that it makes code using such > a type invalid, depending on the type-argument - in ways not captured by > the constraint. For example: > > type X

Re: [go-nuts] [ANN] type-safe templates

2023-09-12 Thread roger peppe
This is very cool, thanks! On Sun, 10 Sept 2023 at 16:20, Jonathan Amsterdam wrote: > The latest version of github.com/jba/templatecheck[0] > supports templates that > cannot have type errors at execution time. > > Once you've parsed your template `t`

Re: [go-nuts] Would it be possible to make this work in the future?

2023-08-29 Thread roger peppe
> We would have to have careful definitions of what kinds of code are permitted in a case with multiple types. ISTM that we already have such a careful definition with generics: given a case in a `switch x.(type)` statement of the form `T1, T2, ..., Tn`, where `x` is of type `S`, we could define t

Re: [go-nuts] Interface embedding

2023-08-29 Thread roger peppe
On Tue, 29 Aug 2023 at 13:35, Remko Tronçon wrote: > The Google Cloud Go library contains the following code (See > https://github.com/googleapis/google-cloud-go/blob/38a040e213cc8af5b01b3afe422481493f54382f/datastore/client.go#L36 > ) > > // datastoreClient is a wrapper for the pb.DatastoreC

Re: [go-nuts] Is it possible to switch on type T in a generic function?

2022-11-08 Thread roger peppe
If you're sure that T is an int or a string, then why not constrain it as such? https://go.dev/play/p/1kT6EacMHco You could go further and constrain it to allow any type with ordering defined: https://go.dev/play/p/il5koj1RPkh If you want to allow any kind of comparable key in your set, one could

Re: [go-nuts] How is the relationship between package version and tag, and what is the formation mechanism?

2022-09-30 Thread roger peppe
Hi, This is documented in the Go module documentation here: https://go.dev/ref/mod#vcs-version cheers, rog. On Thu, 29 Sept 2022 at 18:29, 'Jinchang Hu' via golang-nuts < golang-nuts@googlegroups.com> wrote: > When we use go list -m dependencyName@Version to get the specific > information

Re: [go-nuts] Type switch on generic parameter

2022-08-12 Thread roger peppe
See https://github.com/golang/go/issues/45380 for a proposal for a language feature that would allow this. In the meantime, you can convert to any, and type switch on that: func Foo[T allowedTypes](arg T) { switch t := any(arg).(type) { case int64: ... On Fri, 12 Aug 2022, 00:40 'Matt Ro

Re: [go-nuts] Preemptive interfaces in Go

2022-08-09 Thread roger peppe
One significant argument against preemptive interfaces is that you can't add a method to an interface type without breaking compatibility. Also, an interface is significantly less amenable to static analysis because it's not certain where a method call is implemented. One concern I have about the

Re: [go-nuts] zero value for generic types?

2022-04-21 Thread roger peppe
On Wed, 20 Apr 2022 at 23:29, Arthur Comte wrote: > Actually, even with proper error handling, I still need to return a value. > In some functions I can just return a variable that was defined in the > function, but that is not always available. In those cases, the only > solution I've found is t

Re: [go-nuts] Any recipe to stop a goroutine of a function other than of a channel?

2022-04-16 Thread roger peppe
- close and even throw out an error. > But I am surprised at why golang still has not provided a general feature > on that. > > Zhaoxun > > On Sat, Apr 16, 2022 at 10:14 PM roger peppe wrote: > >> Most network functions provide a way to provide a timeout or cancellation &

Re: [go-nuts] Any recipe to stop a goroutine of a function other than of a channel?

2022-04-16 Thread roger peppe
Most network functions provide a way to provide a timeout or cancellation explicitly. Listen is one such: see this method - if the context that it's passed is cancelled, the Listen call will return. https://pkg.go.dev/net#ListenConfig.Listen The most general way to stop waiting on timeout or cance

Re: [go-nuts] generics: parametric types unmarshaling

2022-04-15 Thread roger peppe
On Thu, 14 Apr 2022, 09:50 'Sebastien Binet' via golang-nuts, < golang-nuts@googlegroups.com> wrote: > hi there, > > I am playing a bit with generics. > I am trying to implement a parametrized "Read" function that unmarshals > bytes into some type value that implements an interface: > > type T1 st

Re: [go-nuts] Re: New edition of the Go Programming Language comming soon ?

2022-03-16 Thread roger peppe
On Tue, 15 Mar 2022 at 04:58, Rob Muhlestein wrote: > The essential issue is that there are a number of resources for people > "with prior programming experience" and literally none for people learning > Go as a first language. > It does have significant omissions (all programs in the book can e

Re: [go-nuts] Improving on unit test styles

2022-02-28 Thread roger peppe
On Fri, 25 Feb 2022, 18:46 'Markus Zimmermann' via golang-nuts, < golang-nuts@googlegroups.com> wrote: > Hi Gophers! > > We were unhappy with the common unit test styles and we think we found a > style that has clear advantages. An in-depth comparison can be found here > https://symflower.com/en/c

Re: [go-nuts] No time.Duration#UnmarshalText; is there a good reason?

2022-01-19 Thread roger peppe
On Wed, 19 Jan 2022 at 04:19, Ian Lance Taylor wrote: > On Mon, Jan 17, 2022 at 9:53 PM Corin Lawson > wrote: > > > > It seems obvious (to me) that the encoding.TextUnmarshaler interface > could be implemented for time.Duration (it is implemented for time.Time, > afterall). > > > > The fact that

Re: [go-nuts] Limits of type parameter inference in function calls

2021-11-08 Thread roger peppe
See https://github.com/golang/go/issues/41176. On Sun, 7 Nov 2021, 12:47 Florian Weimer, wrote: > * Axel Wagner: > > > One way to fix this is to change the signatures to > > > > func Contains[I Iterator[T], T comparable](c I, value T) bool > > func Contains2[I Iterator[T], T comparable](value T,

Re: [go-nuts] testing if strconv.Quote() would do change a string, without calling it

2021-10-14 Thread roger peppe
On Thu, 14 Oct 2021 at 04:58, 'Tim Hockin' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Thanks for confirming. I wrote that function and erased a good bit of the > overhead. > > bytes.Buffer for the no-escapes path and strconv.Quote otherwise. > Could you not use strconv.AppendQuote

Re: [go-nuts] Will the generics support be enabled by default in Go 1.18?

2021-10-13 Thread roger peppe
On Tue, 12 Oct 2021 at 01:42, Ian Lance Taylor wrote: > On Mon, Oct 11, 2021 at 2:36 AM peter.m...@gmail.com > wrote: > > > > I'm curious, was any consideration given to hiding generics behind a > flag in 1.18? The idea being it's such a complex feature that one could > imagine a backwards inco

Re: [go-nuts] Can generics help me make my library safer?

2021-10-09 Thread roger peppe
og >>> solution) >>> >>> Even with static checking there is no way to ensure that tablex has the >>> needed fields. Even if you could check this at compile time - it might be >>> different at runtime. >>> >>> I don’t think the juice is

Re: [go-nuts] Can generics help me make my library safer?

2021-10-06 Thread roger peppe
On Wed, 6 Oct 2021 at 12:44, Robert Engels wrote: > Personally, I think this is overkill (the entire concept not the rog > solution) > I tend to agree, but the bait was too irresistible :) I do think that using reflection in combination with generics the way I showed can be really useful. This

Re: [go-nuts] Can generics help me make my library safer?

2021-10-06 Thread roger peppe
On Wed, 6 Oct 2021 at 09:21, mi...@ubo.ro wrote: > Hi Ian , > > I've modified the example towards a more specific use case. The main idea > in the example below is to make code related to database operations(i.e > SELECT queries) safer and easier to read. A kind of > json.Unmarshal/Marshal for

Re: [go-nuts] Idea extending xerror.As

2021-09-19 Thread roger peppe
In some ways, the existing API is arguably more ergonomic than the originally proposed generic version, as it's possible to use `errors.As` in a switch statement (eg to test several possible types of error) which isn't possible with the multi-return `As` variant. A minor variant of the existing AP

Re: [go-nuts] Still "missing" priority or ordered select in go?

2021-05-06 Thread roger peppe
On Thu, 6 May 2021 at 14:41, 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote: > PS: And I'm not saying there is no argument. Maybe "select is not atomic" > is such an argument. But if there is an argument and/or if this is that > argument, I don't fully understand it myself. >

Re: [go-nuts] Still "missing" priority or ordered select in go?

2021-05-04 Thread roger peppe
On Mon, 3 May 2021 at 20:24, Øyvind Teig wrote: > I see that, which is great. But I still don't understand why > https://go2goplay.golang.org/p/S_5WFkpqMP_H (By *rog*, 29Apr2021 > 23:52:05) seems not to print "Client 2". > That's because to try to emphasise the arbitrariness of the producers (an

Re: [go-nuts] Still "missing" priority or ordered select in go?

2021-04-29 Thread roger peppe
On Thu, 29 Apr 2021, 20:05 Øyvind Teig, wrote: > torsdag 29. april 2021 kl. 20:22:32 UTC+2 skrev rog: > >> I agree with Axel's take here. It seems, Øyvind, that you are concerned >> more with principle than practice here. Can you give an example of a real >> world case where you think that this m

Re: [go-nuts] Still "missing" priority or ordered select in go?

2021-04-29 Thread roger peppe
I agree with Axel's take here. It seems, Øyvind, that you are concerned more with principle than practice here. Can you give an example of a real world case where you think that this might actually matter? On Thu, 29 Apr 2021, 15:44 'Axel Wagner' via golang-nuts, < golang-nuts@googlegroups.com> wr

Re: [go-nuts] Re: Modules... why it has to be so painfull?

2021-04-09 Thread roger peppe
On Fri, 9 Apr 2021, 16:37 'gonutz' via golang-nuts, < golang-nuts@googlegroups.com> wrote: > Justin Isreael said > > "Changes to ProjectB should be immediately available when compiling > ProjectA." > > which is not true when you simply insert a replace in your go.mod file. > > My current problem i

Re: [go-nuts] Re: Update to generics proposal

2021-04-05 Thread roger peppe
On Mon, 5 Apr 2021, 21:58 yiyus, wrote: > A type and its underlying type support exactly the same operations > FWIW I don't believe that's the case. A type may have methods (each with at least one corresponding operation) that its underlying type does not. -- You received this message because

Re: [go-nuts] Re: Update to generics proposal

2021-04-04 Thread roger peppe
On Sun, 4 Apr 2021 at 00:48, Eltjon Metko wrote: > I was fully expecting for floodgates of comments to open again but it > seems we have reached a point of maturity in the generics proposal. > The new proposal really makes the intent much clearer both on the exact vs > underlying type match front

Re: [go-nuts] Finding error type for `errors.As` and `errors.Is`

2021-03-31 Thread roger peppe
On Wed, 31 Mar 2021 at 18:05, 'Michael Schaller' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi everyone, > > I often encounter deep error chains where errors are wrapped across > several Go packages and that makes it often hard to find a usable error > type to use with `errors.As` or

Re: [go-nuts] How to wait for HTTP server to start?

2021-03-29 Thread roger peppe
I often call net.Listen directly before calling Serve in a goroutine. That way you can connect to the server's socket immediately even though the server might take a while to get around to serving the request. Look at how net/http/httptest does it. On Sat, 27 Mar 2021, 14:13 cpu...@gmail.com, wr

Re: [go-nuts] Orderly exit

2021-02-24 Thread roger peppe
On Tue, 23 Feb 2021 at 12:10, Kevin Chadwick wrote: > I only instigate panic manually for one thing. Perhaps that will change, > but I doubt it. > > If I want to send out or write a log to disk then I will call panic rather > than os.exit, upon a log.fatal scenario. Think buffered go routine logg

Re: [go-nuts] Re: Few questions regarding Generics

2021-02-22 Thread roger peppe
On Mon, 22 Feb 2021 at 18:07, Khosrow Afroozeh wrote: > aha, thanks for your help! One problem down. > > The error message is pretty cryptic though, I’d assumed the type inference > would automatically take care of it, or complain about instantiation. > I think it should probably work, but curre

Re: [go-nuts] Error handling

2021-02-20 Thread roger peppe
On Sat, 20 Feb 2021, 16:31 L Godioleskky, wrote: > Rust lang, very early in its evolution, saw the need to create its > operator '?' to more efficiently manage error handling. But the guardians > of Go lang have resisted any changes to its clumsy method of error handling > despite it being a maj

Re: [go-nuts] big.Float.Cmp does not work as expected

2021-02-15 Thread roger peppe
Thanks for bringing this up. It surprised me too until I realised what was going on. The issue here is about the default precision that you're getting for those big.Float values. When you use big.NewFloat, the precision you get is exactly the same as that of a base64 float (53 bits). When you use

Re: [go-nuts] Possible to make base64 pick the decode encoding automatically?

2021-02-02 Thread roger peppe
In case you find it helpful, here's a clone of the base64 command that I wrote in Go. I did it precisely because I wanted to be able to decode any encoding scheme interchangeably. https://github.com/rogpeppe/misc/blob/master/cmd/base64/base64.go I agree that it might be useful to have some of thi

Re: [go-nuts] Re: Virtual time for testing

2021-02-01 Thread roger peppe
On Sat, 30 Jan 2021 at 20:12, Christian Worm Mortensen wrote: > Hi Mike, > > Thank you for your consideration. I think you exactly got the essence of > my question: How do I wait on all go routines to finish (or be blocked on > one or more channels) before advancing time. > This is an interestin

Re: [go-nuts] Re: Interface arguments to generic functions

2021-01-20 Thread roger peppe
On Wed, 20 Jan 2021 at 11:04, Brian Candler wrote: > What do you make of this? > https://go2goplay.golang.org/p/gN-FK2kbYK5 > > Using interface values, it seems possible to bypass a declared constraint > that two arguments have the same type. > This code is misleading. By passing the value to `r

Re: [go-nuts] [ANN] github.com/jba/codec, a fast encoder for Go

2021-01-20 Thread roger peppe
On Wed, 20 Jan 2021 at 13:31, Jonathan Amsterdam wrote: > The encoding scheme is described briefly in the README[0] and the code[1]. > > To answer your two specific questions, interfaces are represented as a > pair (typeNumber, value) where typeNumber maps to a registered type. (Like > gob, types

Re: [go-nuts] [ANN] github.com/jba/codec, a fast encoder for Go

2021-01-19 Thread roger peppe
This is interesting, thanks! Is there a full description of the encoding somewhere? (e.g. how are structs represented? what about interface values, etc? is the schema implicit or sent on the wire?) cheers, rog. On Tue, 19 Jan 2021 at 14:59, Jonathan Amsterdam wrote: > Uses code generation

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread roger peppe
FWIW I think that one possible approach to allowing methods (and potentially function values) with type parameters might be to allow instantiating them only with a limited set of "shapes" of data (for example, only pointer-like types). Then I think there's the possibility that the method or functio

Re: [go-nuts] Workaround for No parameterized methods in go generics draft

2021-01-14 Thread roger peppe
On Wed, 13 Jan 2021 at 20:38, Marcus Manning wrote: > > Regarding the the section of No parameterized methods in go generics > draft: > > package p1 // S is a type with a parameterized method Identity. type S > struct{} // Identity is a simple identity method that works for any type. > func (S) I

Re: [go-nuts] Generics and constraints question

2021-01-05 Thread roger peppe
You can do this with type-list interfaces: https://go2goplay.golang.org/p/wfHnVHOMcyK This is one of the harder parts of the proposal to understand IMHO, but perhaps it will become easier with familiarity. On Tue, 5 Jan 2021, 17:32 Brian Candler, wrote: > Question: how to make a generic functio

Re: [go-nuts] Generics - please provide real life problems

2021-01-03 Thread roger peppe
FWIW I'm certain that the lack of tuples in Go was a very deliberate decision - one of Go's more significant ancestors, Limbo, had tuples. Anonymous product types have their disadvantages too (you don't get to name the members, so code can end up significantly harder to understand), which I suspect

Re: [go-nuts] Generics Error - How to fix?

2021-01-01 Thread roger peppe
On Fri, 1 Jan 2021, 17:49 da...@suarezhouse.net, wrote: > First of all -- awesome, thanks!!! > > Question 1: the need for the additional typeOf function you added at the > end, would that be needed in a future implementation or would that be > deduced in the existing reflect.TypeOf in the futur

Re: [go-nuts] Generics Error - How to fix?

2021-01-01 Thread roger peppe
You need to declare the type parameters in the method definitions too. Something like this works OK: https://go2goplay.golang.org/p/ZUAVncRrmZW cheers, rog. On Fri, 1 Jan 2021 at 15:06, da...@suarezhouse.net wrote: > I thought I read the generics doc well but.. :-) Help is appreciated:

Re: [go-nuts] Generics - please provide real life problems

2020-12-31 Thread roger peppe
Here's one real life example that I came across recently. I have a CRUD API that supports a bunch of different entity types. They all support a superset of the same operations. Each method represents a single HTTP call. If the generics proposal was implemented, I'd be able to define a common inte

Re: [go-nuts] How to set the "godebug" environment variable from the go file?

2020-12-20 Thread roger peppe
On Wed, 16 Dec 2020, 21:29 Ian Lance Taylor, wrote: > On Wed, Dec 16, 2020 at 8:49 AM Sean wrote: > > > > hi all, > > i have a project I have to work with CGo. I want to disable some > > controls as they are not good enough right now. > > It works when I write "set godebug=cgocheck=0" on Windows

Re: [go-nuts] [generics] combining different instances of the same generic type

2020-12-02 Thread roger peppe
On Wed, 2 Dec 2020 at 09:15, roger peppe wrote: > Also your delayed blocks don't wait for the preceding set of futures to be >> exhausted before proceeding, I think they're all triggered once the initial >> set is completed > > > Each delayed block is trigg

Re: [go-nuts] [generics] combining different instances of the same generic type

2020-12-02 Thread roger peppe
or. type Doner interface { Done() <-chan struct{} } In fact, it's easy to define the whole of AsCompleted and AsCompletedDelayed in terms of the above type, with a small tweak to the Delayed type to avoid the direct dependency on F. func AsCompletedDelayed[D Doner](ctx context.Context, in

Re: [go-nuts] [generics] combining different instances of the same generic type

2020-12-01 Thread roger peppe
And again (no need to make a cancelable context) https://go2goplay.golang.org/p/3UFUaXijuX9 On Tue, 1 Dec 2020 at 22:59, roger peppe wrote: > Slightly simpler again: https://go2goplay.golang.org/p/mKdishv4nhT > > On Tue, 1 Dec 2020 at 18:44, roger peppe wrote: > >> I&#

Re: [go-nuts] [generics] combining different instances of the same generic type

2020-12-01 Thread roger peppe
Slightly simpler again: https://go2goplay.golang.org/p/mKdishv4nhT On Tue, 1 Dec 2020 at 18:44, roger peppe wrote: > I'm having difficulty understanding exactly what your code is trying to do > (and why), and that makes it hard to understand what > generic solution might

Re: [go-nuts] [generics] combining different instances of the same generic type

2020-12-01 Thread roger peppe
I'm having difficulty understanding exactly what your code is trying to do (and why), and that makes it hard to understand what generic solution might be appropriate. However, here's one alternative implementation that doesn't seem to run into the same kind of issues that you did. It changes the c

Re: [go-nuts] Go modules replace statements referencing legacy codebases

2020-11-07 Thread roger peppe
I don't quite understand why you're using replace directives here rather than just declaring the pseudo-version as a requirement. Why wouldn't that work? On Fri, 6 Nov 2020, 14:19 Jim Minter, wrote: > Hi, > > Using Go 1.14, I'm working on a parent codebase which, in its go.mod > file, has a num

Re: [go-nuts] Table driven tests and error/output testing

2020-10-20 Thread roger peppe
It looks like you're testing a top level command. You might want to consider using the testscript package, which provides a very concise way of end-to-end testing this kind of thing. e.g. mycommand -h cmp stdout expect-stdout -- expect-stdout -- Expected output See https://pkg.g

Re: [go-nuts] global goroutine data / thread local storage?

2020-09-26 Thread roger peppe
On Sat, 26 Sep 2020, 02:36 Alex Besogonov, wrote: > On Friday, September 25, 2020 at 4:43:45 PM UTC-7 Ian Lance Taylor wrote: > >> On Fri, Sep 25, 2020 at 10:35 AM Alex Besogonov >> wrote: >> > >> > Inheritable goroutine-locals would actually work just fine in Go. >> Moreover, Go actually has th

Re: [go-nuts] Find n-th root of a big number

2020-09-22 Thread roger peppe
Relevant issue: https://golang.org/issue/14102 On Tue, 22 Sep 2020 at 08:54, Nasir Hussain wrote: > The Amazing Rob Pike :D > > On Tue, Sep 22, 2020 at 12:13 PM Rob Pike wrote: > >> I'm not going to debug you program for you - you'll learn more doing it >> yourself, but I glanced at it and saw

Re: [go-nuts] unit test for function which has goroutine

2020-09-11 Thread roger peppe
On Thu, 10 Sep 2020 at 08:15, Yvonne Zhang wrote: > Hi, > I have a function streaming a zipreader to browser. It is like this. > func functionA()(body io.ReadCloser, err error){ > >// some logic to get a zipreader > >body, pipeWriter := io.Pipe() >zipWriter := zip.NewWriter(pipeWr

Re: [go-nuts] [generics] Allowing interfaces with type constraints

2020-09-10 Thread roger peppe
You can definitely use parametric interfaces in type assertion expressions, but you can't use interfaces with type lists. I'm not sure exactly what you're trying to do in your example, but ISTM that it could be somewhat simpler. You only need one type parameter: https://go2goplay.golang.org/p/4E0Zn

Re: [go-nuts] Dynamic composition of interfaces at runtime?

2020-09-02 Thread roger peppe
On Wed, 2 Sep 2020 at 10:56, Jesper Louis Andersen < jesper.louis.ander...@gmail.com> wrote: > Usually, my experience is that these highly dynamic interfaces is an > indication you want to approach the problem from a different angle. You > will converge on something that gets closer and closer to

Re: [go-nuts] Re: [ generics] Moving forward with the generics design draft

2020-08-24 Thread roger peppe
On Mon, 24 Aug 2020 at 12:57, 'Richard Oudkerk' via golang-nuts < golang-nuts@googlegroups.com> wrote: > > Applying the same rule to type lists and type switches you should be able > to write > > type Comparer[T any] interface { > Compare(T) int > } > > type CompareConstraints

Re: [go-nuts] Re: [ generics] Moving forward with the generics design draft

2020-08-23 Thread roger peppe
On Mon, 24 Aug 2020 at 06:35, Denis Cheremisov wrote: > I probably didn't read what you have wrote in the first message carefuly > enough. Does it mean something like that will work > > type SomeTypes interface { > type int, float32, float64 > } > > func Min[T SomeTypes](x, y T) T

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
; > >> > >> Ian > >> > >> On Fri, Aug 21, 2020 at 2:43 PM Axel Wagner > >> wrote: > >> > > >> > also, of course, you could still use operators with them, while now > also knowing the exact semantics of those operators (e.g. in regards t

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
On Fri, 21 Aug 2020 at 23:03, Axel Wagner wrote: > On Fri, Aug 21, 2020 at 11:46 PM Ian Lance Taylor wrote: > >> Yes, there are various such possibilities. >> >> What jimmy frasche said above is correct: nothing changes in the case >> of a type switch of a type parameter. The code now knows the

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
ri, Aug 21, 2020 at 11:42 PM Axel Wagner < > axel.wagner...@googlemail.com> wrote: > >> > >> > >> > >> On Fri, Aug 21, 2020 at 11:30 PM roger peppe > wrote: > >>> > >>> On Fri, 21 Aug 2020 at 22:10, jimmy frasche > wrote: > >>>>

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
s on []T when T is a known type such as byte. On Fri, Aug 21, 2020 at 2:07 PM roger peppe wrote: > > > > > > On Fri, 21 Aug 2020 at 01:28, Ian Lance Taylor wrote: > >> > >> After many discussions and reading many comments, we plan to move > >> fo

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
On Fri, 21 Aug 2020 at 01:28, Ian Lance Taylor wrote: > After many discussions and reading many comments, we plan to move > forward with some changes and clarifications to the generics design > draft. > > 1. > > We’re going to settle on square brackets for the generics syntax. > We’re going to dr

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
y9z>. > I agree that's a concern, but I think that should be a reason to fix error messages when aliases are used, not to use a named type. > On Fri, Aug 21, 2020 at 7:08 PM roger peppe wrote: > >> >> >> On Fri, 21 Aug 2020 at 15:24, Ian Lance Taylor wrote: &g

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
On Fri, 21 Aug 2020 at 15:24, Ian Lance Taylor wrote: > On Fri, Aug 21, 2020, 12:37 AM 'Axel Wagner' via golang-nuts < > golang-nuts@googlegroups.com> wrote: > >> Just to clarify, the intent is to make the declaration in the spec `type >> any = interface{}`, not `type any interface{}`, correct? T

Re: [go-nuts] [ generics] Moving forward with the generics design draft

2020-08-21 Thread roger peppe
On Fri, 21 Aug 2020 at 01:28, Ian Lance Taylor wrote: > After many discussions and reading many comments, we plan to move > forward with some changes and clarifications to the generics design > draft. > > 1. > > We’re going to settle on square brackets for the generics syntax. > We’re going to dr

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

2020-08-15 Thread roger peppe
On Sat, 15 Aug 2020 at 04:57, Patrick Smith wrote: > On Thu, Aug 13, 2020 at 11:25 PM Patrick Smith > wrote: > > I tried out a few different implementations, evaluating the polynomial > > instead of finding roots, > > at https://go2goplay.golang.org/p/g8bPHdg5iMd . As far as I can tell, > > ther

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

2020-08-14 Thread roger peppe
Nice example! Presumably if you wanted to do actual Porter-Duff though, you'd want some arithmetic rather than just comparison. One observation: you don't actually need the "comparable" constraint on many of the core entities there (e.g. Rect and Op) because they don't actually use any compare ope

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

2020-08-14 Thread roger peppe
On Thu, 13 Aug 2020 at 23:30, Ian Lance Taylor wrote: > 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 >

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] "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

Re: [go-nuts] Non-alphanumerics in template field names?

2020-08-01 Thread roger peppe
You could use the "index" built-in function instead of the dot operator: {{index . "foo:bar"}} On Fri, 31 Jul 2020, 17:16 Bob DuCharme, wrote: > I have seen that a map key name of "foo:bar" works just fine... unless I > reference it in a template. {{.foo:bar}} gives me a segmentation violation

Re: [go-nuts] json.Unmarshal with disallowUnknownFields

2020-07-30 Thread roger peppe
You could write a function to do that for you. On Thu, 30 Jul 2020, 09:45 Brian Candler, wrote: > I want to do a json.Unmarshal of []byte data whilst also getting the > disallowUnknownFields behaviour. Is there any tidier way than this > ? > > dec := json.

Re: [go-nuts] Generics and parentheses

2020-07-18 Thread roger peppe
On Sat, 18 Jul 2020, 13:25 Jan Mercl, <0xj...@gmail.com> wrote: > On Sat, Jul 18, 2020 at 1:39 PM roger peppe wrote: > > > I didn't say there was exactly one construct for each kind of name > definition. In current Go, when a name is defined, it's defined inside a

Re: [go-nuts] Generics and parentheses

2020-07-18 Thread roger peppe
On Sat, 18 Jul 2020 at 11:05, Jan Mercl <0xj...@gmail.com> wrote: > On Sat, Jul 18, 2020 at 11:12 AM roger peppe wrote: > > Thanks for taking time to think about it. > > > A few reasons that I'm not keen on your $, @ proposal: > > > > - elsewhere in Go, w

Re: [go-nuts] Generics and parentheses

2020-07-18 Thread roger peppe
On Thu, 16 Jul 2020, 14:38 Jan Mercl, <0xj...@gmail.com> wrote: > On Thu, Jul 16, 2020 at 3:12 PM 'Axel Wagner' via golang-nuts > wrote: > > > I dislike the idea of using $ and @ because I don't want to add new > symbols to the language, if it can be avoided. In general I'd argue that Go > tends

Re: [go-nuts] [generics] Issues with identifying the matched predeclared type

2020-07-08 Thread roger peppe
On Wed, 8 Jul 2020 at 00:33, Steven Blenkinsop wrote: > On Tue, Jul 7, 2020 at 10:44 AM, roger peppe wrote: > >> >> In my description, there's no assumption that doing it over the type >> parameter implies a refinement of the previously set type constraints. In

Re: [go-nuts] [generics] Issues with identifying the matched predeclared type

2020-07-07 Thread roger peppe
On Tue, 7 Jul 2020 at 21:05, Tobias Gustafsson < tobias.l.gustafs...@gmail.com> wrote: > Den tisdag 7 juli 2020 kl. 16:45:21 UTC+2 skrev rog: >> >> On Tue, 7 Jul 2020 at 10:36, Tobias Gustafsson >> wrote: >> >>> Hi all, >>> >>> Thanks for the response on this subject! >>> >>> Yes, a kind of type

Re: [go-nuts] [generics] Issues with identifying the matched predeclared type

2020-07-07 Thread roger peppe
a normal type switch, >> because there's no way to avoid nesting type switches (in a normal type >> switch, it's possible to assign the specialized value to another variable >> with wider scope, but that's not possible in general with generic type >> switches).

Re: [go-nuts] [generics] Issues with identifying the matched predeclared type

2020-07-06 Thread roger peppe
erface{type X}) and could be omitted. It depends how commonly used this might be. On Tue, 7 Jul 2020 at 04:51, Steven Blenkinsop wrote: > On Mon, Jul 6, 2020 at 6:29 PM, roger peppe wrote: > >> >> I've also been playing around in this area. I've bee

Re: [go-nuts] [generics] Issues with identifying the matched predeclared type

2020-07-06 Thread roger peppe
On Mon, 6 Jul 2020 at 17:46, wrote: > Hi! > > I've spent some time lately to try out the go2go tool and the new generics > proposal by converting a small hack I did some years ago for immutable data > structures (https://github.com/tobgu/peds) which, in it's current shape, > depends on code gener

Re: [go-nuts] Re: [generics] Generics pave the way to some kind of polymorphism implementation?

2020-07-04 Thread roger peppe
When you say "polymorphism", I think you might mean "inheritance"? (Go-with-generics already has two kinds of polymorphism) I don't really understand what you're trying to accomplish here. Perhaps you could explain your motivation a bit more? On Fri, 3 Jul 2020, 21:22 Aleksandar Milovanović, wr

  1   2   3   4   5   >