3 ms·
Tried to contribute to a Go project a few months ago and got bitten by https://github.com/golang/go/issues/67296 https://github.com/golang/go/issues/67296 due t
by a-french-anon 2y ago
Tried to contribute to a Go project a few months ago and got bitten by https://github.com/golang/go/issues/67296 https://github.com/golang/go/issues/67296 due to questionable doc quality. I was pretty disappointed to find that natural sort isn't builtin since Go was the Unicode language in my mind (Go runes, made by some Plan 9 thus UTF-8 creators).
Go has a lot of good points, but I immediately felt "dirty" when using it. Like that time when I tried to wrap a closure variable over itself ("my_closure = new closure calling my_closure") and needed to use a temporary variable because closure captures are always by reference: if you want to build abstractions, you got to think them better; as it stands, this is the worst of both worlds I know (C++ makes capture type explicit and customizable, Common Lisp was designed by wizards who knew what to do cf https://www.tfeb.org/fragments/2023/02/22/how-to-understand-closures-in-common-lisp/ https://www.tfeb.org/fragments/2023/02/22/how-to-understand-...).
- foldr 2y agoWe may have different definitions of 'temporary variable', but you don't need what I would think of as a temporary variable to make a self-calling closure: toCapture := 99 var myClosure func() int myClosure = func() int { return myClosure() + toCapture } // nonsense myClosure() It would be nice if Go would just allow the use of function definition syntax inside functions, though. Seems like a small and non-breaking change that could easily be made.
- dfawcus 2y agoOne can sort of get a non reference capture, by passing the same name as a argument; but yes it would be nice if one could somehow say capture by value. foo := 1 closure := func(foo int) func() int { return func() int { return foo += 1 } }(foo) x := closure() // 2, w/o altering outer foo If not something like the above, I'm not sure what you're trying to express. Possibly what 'foldr' suggested, or that with mine such that one passes in the initial closure function as a argument?