[go-nuts] Re: Proposal: return if any not nil

2018-02-17 Thread Krzysztof Kowalczyk
Even simpler: r, err := try os.Open("blah.text") Similar to Swift and what Rust used to have. "try foo()" means: if "foo()" returns an error, return the error to the caller. If function returns multiple values, it would return zero value for non-error values. I believe now Rust has the follow

[go-nuts] Question about casting

2018-02-17 Thread Bill Wood
HI, Go newbie here... not sure if this is a dumb question or not :) I have a simple program: package main import "fmt" type any interface{} type myInt int func plus(a, b any) any { return a.(myInt) + b.(myInt) } func main() { s := plus(myInt(3), myInt(2)) fmt.Printf("%v, %T\n", s, s) } Outp

Re: [go-nuts] Re: All Forms of Wishful Generics

2018-02-17 Thread Lars Seipel
On Sat, Feb 17, 2018 at 01:10:29AM -0800, dc0d wrote: > There are other things too, that I would like to have in Go; like a faster > FFI/CGO, or safe packages by restricting features so that a Go package > cannot harm the hosting machine or application, like Safe Tcl Go already has a NaCl backe

[go-nuts] Re: Go 1.10 is released

2018-02-17 Thread Dmitriy Cherchenko
I like how the Go team isn't trying to support very old operating systems. We should focus on modern systems and expect people to try to stay up to date. Thank you! On Friday, February 16, 2018 at 11:36:22 AM UTC-8, Andrew Bonventre wrote: > > Hello gophers, > > We just released Go 1.10. > > Yo

Re: [go-nuts] Re: Proposal: return if any not nil

2018-02-17 Thread Nathan Fisher
I think for me the benefit of a new statement is that it doesn't result in changes to existing formatting/behaviour. Rather it provides a familiar syntax and style semantic and results in no change to an existing code base (e.g. it's opt in). The problems I see with allowing 1 liner conditionals a

[go-nuts] printing a struct fields that implements an error interface

2018-02-17 Thread Joseph Lorenzini
Hi all: Per documentation: "If an operand implements the error interface, the Error method will be invoked to convert the object to a string, which will then be formatted as required by the verb (if any)" And this is so even if the struct implements the stringer interface. So if I print the s

Re: [go-nuts] Warning: Failure to Cross-Compile

2018-02-17 Thread bucarr
Okay. I've deleted the env variable GOBIN. Next time I'm offered to install goreturn I'll select it and see what happens. Thank you, Ian! On Saturday, February 17, 2018 at 11:50:15 AM UTC-7, Ian Lance Taylor wrote: > > > > My GOBIN = C:\Users\AKC\Go_Projects\bin > > Don't set GOBIN. As the

Re: [go-nuts] Warning: Failure to Cross-Compile

2018-02-17 Thread Ian Lance Taylor
On Sat, Feb 17, 2018 at 9:50 AM, wrote: > > Precisely (as an example, same failure notice): > > > VS Code with the lukehoban plugin installed. The plugin gives me this > message: > > "The Go extension is better with the latest version of "goreturns". Use "go > get -u -v sourcegraph.com/sqs/goret

Re: [go-nuts] Warning: Failure to Cross-Compile

2018-02-17 Thread bucarr
Precisely (as an example, same failure notice): VS Code with the lukehoban plugin installed. The plugin gives me this message: "The Go extension is better with the latest version of "goreturns". Use "go get -u -v sourcegraph.com/sqs/goreturns" I click "install" and get this: Installing 1 t

Re: [go-nuts] Warning: Failure to Cross-Compile

2018-02-17 Thread Ian Lance Taylor
On Sat, Feb 17, 2018 at 8:54 AM, wrote: > Newbie here. Learning to program in Go... > > Just upgraded from 1.8.1 --> the wonderful 1.10; easy to do and smooth > (thank you Go Team!!!). Compiling is faster still! Question for the > congregants: > > I write my Go code on a Windows 10 box using V

[go-nuts] Warning: Failure to Cross-Compile

2018-02-17 Thread bucarr
Newbie here. Learning to program in Go... Just upgraded from 1.8.1 --> the wonderful 1.10; easy to do and smooth (thank you Go Team!!!). Compiling is faster still! Question for the congregants: I write my Go code on a Windows 10 box using VS Code. Env variable GOOS set to 'freebsd' (my tar

Re: [go-nuts] context.Context and worker pools

2018-02-17 Thread andrey mirtchovski
thanks to both for your replies! On Fri, Feb 16, 2018 at 4:43 PM, 'Bryan Mills' via golang-nuts wrote: > Pool the resources, not the workers. > > For example, if your resource is “memory footprint of in-flight requests”, > use a semaphore instead. (There is a “worker pool” example in the package

[go-nuts] Re: All Forms of Wishful Generics

2018-02-17 Thread matthewjuran
> > Competition is good, only when the Go team feels the heat of competition > they will think about working on their type system seriously. I think everybody here is aware that some people really want generics and that generics would probably be useful for everybody. Instead of restating tha

Re: [go-nuts] How can I fetch the default locale (server locale not from the request) in Golang

2018-02-17 Thread Anish P
Thanks for the details. Had a look earlier at the code mentioned by Jibber-Jabber as you mentioned. Will post the status as soon as I try this out. Cheers Anish On Sat, Feb 17, 2018 at 9:55 AM, wrote: > Java’s Locale.getDefault returns (if not overridden) the values from the > system property “

Re: [go-nuts] Re: Proposal: return if any not nil

2018-02-17 Thread Michael Jones
The notion of "return X if Y" is fun...it means I'm waking up to SNOBOL in 2018. Fantastic flashback but awkward here. Changing formatting to allow single line "if X { trivial Y }" seems natural. On Sat, Feb 17, 2018 at 6:05 AM, wrote: > The OP's idea is the best one so far. What about the foll

[go-nuts] Re: Proposal: return if any not nil

2018-02-17 Thread charraster
The OP's idea is the best one so far. What about the following. r, err := os.Open("blah.txt") *return* nil *if* r == nil, err *if* err != nil basically every return field could be followed by an optional if clause with an expression that must evaluate to bool. The return only happens if all opt

[go-nuts] Re: All Forms of Wishful Generics

2018-02-17 Thread dc0d
Indeed it's a form of package/block level code-specialization, so called generics. There is a proposal for package level generics by me too. My main concern here was to have this feature without invalidating current Go code bases, by allowing the rebinding of Type Aliases

[go-nuts] Re: All Forms of Wishful Generics

2018-02-17 Thread dc0d
Agreed. But it's not necessarily a "obsolescence" vs "being crushed (...)" thing. With the brainpower behind Go, sure the best things will happen. I'm not saying that Go has to add generics (or not). In fact generics is just one of the things that I would like to see in Go. There are other thi

Re: [go-nuts] Re: ioutil.ReadAll()

2018-02-17 Thread Patrik Iselind
Den 2018-02-14 kl. 11:42, skrev Axel Wagner: Why are the things mentioned so far not sufficient? The presented reasons are enough. I was just seeing things the wrong way and it took quite a while to get my head on straight. After some consideration i have repaired my views and everything is