Re: [go-nuts] Re: Trying to understand := and named return values

2017-02-21 Thread 'Paul Borman' via golang-nuts
Named return values are perfectly fine, and I agree, probably should not be discouraged. For example, which is easier to write documentation for? func Run(cmd string) ([]byte, []byte, error) func Run(cmd string) (stdout, stderr []byte, _ error) What is not good is the following function: func

Re: [go-nuts] Given a `[]string` key list and a `map[string]interface{}`, can we find the value?

2017-02-12 Thread 'Paul Borman' via golang-nuts
Your code can panic. Take a look at: https://play.golang.org/p/MrPtar9oEK traverse2 has the type assertion. Notice how the call to traverse2 works but the following call to traverse panics. -Paul On Sun, Feb 12, 2017 at 12:06 PM, John Feminella wrote: > Thanks. I wound up doing this wit

Re: [go-nuts] Given a `[]string` key list and a `map[string]interface{}`, can we find the value?

2017-02-12 Thread 'Paul Borman' via golang-nuts
Take a look at the reflect package, or if you know that the only internal maps will be of type map[string]interface{} you can use type assertion to determine if the element is a map or some other type. On Sun, Feb 12, 2017 at 7:53 AM, wrote: > I would like to write a function which, given: > >

Re: [go-nuts] Re: Priority cases in select?

2017-01-25 Thread 'Paul Borman' via golang-nuts
Hi John, they are equivalent. I chose to not indent the second select. Your comment on the call to next being concurrent is the exact point of this program. It reveals the race condition between the first and second select and demonstrates that even if hi and lo are both ready, or hi became ready

Re: [go-nuts] Re: Priority cases in select?

2017-01-25 Thread 'Paul Borman' via golang-nuts
I originally was thinking on the lines of what John said, but I proved it wrong, see https://play.golang.org/p/JwX_cxaR99 for the code. You can't run it in the playground, but on my MacPro I get output like: $ GOMAXPROCS=1 go run r.go Failed after 1137702 Failed after 699376 Failed after 757658 ^

Re: [go-nuts] Struct Compatibility in unix.Syscall

2016-12-06 Thread 'Paul Borman' via golang-nuts
Are the extra 4 bytes padding at the end of the structure? You can have C print the offset of each element and then use unsafe.Offsetof to find the same for the Go structure. I am sure you will quickly discover where the extra 4 bytes are (the C structure is probably padding to a word boundary or

Re: [go-nuts] bug? if true &&& true &&& false {

2016-10-31 Thread 'Paul Borman' via golang-nuts
Sounds like a golint sort of thing. On Mon, Oct 31, 2016 at 1:26 PM, Jan Mercl <0xj...@gmail.com> wrote: > > On Mon, Oct 31, 2016 at 8:45 PM wrote: > > > the triple ampersands is parsed as : > > true && &true > > Correct. That's what the specs prescribe. > > > No syntax error is reported :/ &&&

Re: [go-nuts] What is called reference values in Golang?

2016-10-21 Thread &#x27;Paul Borman&#x27; via golang-nuts
Well, from that standpoint, any structure that has a pointer is a reference type. On Fri, Oct 21, 2016 at 8:50 AM, T L wrote: > > > On Friday, October 21, 2016 at 11:37:21 PM UTC+8, Paul Borman wrote: >> >> I think you should clarify that this is because T *only* contains >> pointers. If T were

Re: [go-nuts] What is called reference values in Golang?

2016-10-21 Thread &#x27;Paul Borman&#x27; via golang-nuts
I think you should clarify that this is because T *only* contains pointers. If T were: type T struct { i int p *int } then it would suddenly become non-reference type, as defined in this thread, as a change to i will not be noticed by other copies of a given T. -Paul On Fri, Oct

Re: [go-nuts] Reusable regex in Golang for rule system.

2016-10-20 Thread &#x27;Paul Borman&#x27; via golang-nuts
Check out time.Parse : t := time.Parse("2006-01-02", inputString) year := t.Year() month := t.Month() day := t.Day() On Thu, Oct 20, 2016 at 5:06 AM, David Sofo wrote: > > Hi, > I ma new to Go Regex. > > I want to have a set of reusable rules of regex in gola

Re: [go-nuts] spec:

2016-10-10 Thread &#x27;Paul Borman&#x27; via golang-nuts
In your representation, P means "identifiers are different", so the resulting false means the identifiers are the same, which is what the OP asked. On Mon, Oct 10, 2016 at 8:47 AM, Jan Mercl <0xj...@gmail.com> wrote: > > On Mon, Oct 10, 2016 at 5:39 PM T L wrote: > > > Two identifiers are differ

Re: [go-nuts] Adding YAML to the stdlib

2016-09-23 Thread &#x27;Paul Borman&#x27; via golang-nuts
I would like to point out that Go itself is maintained by The Community. Sure Google has employees dedicated to Go (we use it internally, of course), but Go has been, since the beginning, and open source project with serious contributions from within and without Google. On Fri, Sep 23, 2016 at 11:

Re: [go-nuts] [ANN] go-scp: a scp client library in go

2016-09-20 Thread &#x27;Paul Borman&#x27; via golang-nuts
For cancellation you run the actual operation in a goroutine and return results on a channel. You can then select on the Deadline from the context and the returned result. If the deadline hits, you just shut down the SSH session. Does that make sense? -Paul On Tue, Sep 20, 2016 at 3:36 PM,

Re: [go-nuts] [ANN] go-scp: a scp client library in go

2016-09-20 Thread &#x27;Paul Borman&#x27; via golang-nuts
I would suggest just putting your package out there and see how it is received. At some point, if it becomes the defacto package, moving it might make sense. I actually wrote an internal SCP package that works with a ssh multiplexer built on top of crypto/ssh. For various reasons, I am not in a

Re: [go-nuts] Re: Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread &#x27;Paul Borman&#x27; via golang-nuts
In theory the compiler can be smart enough, if it knows that the string passed to fmt.Println is not stored and re-used someplace, but I do not believe that is currently true. It probably has at least 2 copies, one to the string in your code and a second one to make it a []byte to pass to the io.

Re: [go-nuts] Re: Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread &#x27;Paul Borman&#x27; via golang-nuts
A string is immutable, a byte slice is not. Suppose you have: b := []byte("hello world") s := string(b) fmt.Println(s) b[0] = 'H' fmt.Println(s) What is printed? hello world hello word Using the OPs function: b := []byte("hello world") s := fastBytesToString(b) fmt.Println(s) b[0] = 'H' fmt.

Re: [go-nuts] Fast conversion. Tell me why I shouldn't.

2016-09-19 Thread &#x27;Paul Borman&#x27; via golang-nuts
As long as no one modifies the bytes in the byteslice. Go can no longer enforce that the string is immutable with this hack. On Mon, Sep 19, 2016 at 2:35 PM, wrote: > I don't like the extra allocation and copies involved when casting from > byte slice to string or vice versa just because one ty

Re: [go-nuts] [ANN] go-scp: a scp client library in go

2016-09-19 Thread &#x27;Paul Borman&#x27; via golang-nuts
Adding an scp package is a nice addition. You might want to consider simple names like: Send - Sends from []byte to file on remote host SendDir - Send files in dir to a remote host SendFile - Sends the contents of a file to the remote host Fetch - Fetches the contents of a file on remote host int

Re: [go-nuts] Multiple-reader single-writer map access - is this lockless workaround safe?

2016-09-13 Thread &#x27;Paul Borman&#x27; via golang-nuts
arget, that is a side effect of an implementation and architecture detail.* On Tue, Sep 13, 2016 at 7:57 AM, Alan Donovan wrote: > On 13 September 2016 at 10:33, 'Paul Borman' via golang-nuts < > golang-nuts@googlegroups.com> wrote: > >> That said, a map is represe

Re: [go-nuts] Multiple-reader single-writer map access - is this lockless workaround safe?

2016-09-13 Thread &#x27;Paul Borman&#x27; via golang-nuts
I think it is pretty common to make your map/list "read only" and to update it by a replace. That does not get you away from the need for a mutex, however. There is still a reader and writer: Reader: v := m[key] Writer: m = newMap Those two operations are not safe together. You still nee

Re: [go-nuts] Re: Another divide by zero (float) question

2016-09-13 Thread &#x27;Paul Borman&#x27; via golang-nuts
float32(0) is a constant, a typed constant. The following statement is valid: const z = float32(0) So it is following the part of the spec that Ian pointed out. -Paul On Mon, Sep 12, 2016 at 5:15 PM, wrote: > I see - so if I understood correctly the spec for constants disallowing > divid

Re: [go-nuts] Generation of Strings - generation

2016-07-15 Thread &#x27;Paul Borman&#x27; via golang-nuts
It wasn't clear to me what the OP wanted. Did they just want to print them? Did they want to use them? For use, I think the channel is probably the most straightforward to use, but the OP didn't want any channels at all. The underlying array that slices refer to could also be made smaller, for

Re: [go-nuts] Generation of Strings - generation

2016-07-15 Thread &#x27;Paul Borman&#x27; via golang-nuts
BTW, the solution I provided does change one digit at a time, working just like an odometer. The OP privately said that even the reporting channel was undesired in my solution, so I sent the OP a link to one that allocated a slice and then filled it in, rather than sending it down a channel. The

Re: [go-nuts] Generation of Strings - generation

2016-07-12 Thread &#x27;Paul Borman&#x27; via golang-nuts
Something like https://play.golang.org/p/dZjaaorPcb ? On Tue, Jul 12, 2016 at 1:54 PM, The MrU wrote: > Hi, > > I have this code https://play.golang.org/p/9o5TReZ7jT3 > > > My idea was to generate all possible combinations pretty much this: > > aaa > bbb >

Re: [go-nuts] Improvement in text/template/parse/lex.go

2016-07-11 Thread &#x27;Paul Borman&#x27; via golang-nuts
n, Jul 11, 2016 at 1:02 PM, Caleb Spare wrote: > Hey Paul, nice results. The benchmark results would be easier to > interpret if you provided benchcmp output instead. > > On Mon, Jul 11, 2016 at 12:27 PM, 'Paul Borman' via golang-nuts > wrote: > > I was looking at tex

Re: [go-nuts] Re: Improvement in text/template/parse/lex.go

2016-07-11 Thread &#x27;Paul Borman&#x27; via golang-nuts
Yes, you are correct, if the template is only {{}}'s with no text then there is no benefit, but no penalty, either (i.e., no down side in performance). Once there is any reasonable amount of text (as all templates I have written are), the speed up is noticeable. -Paul On Mon, Jul 11, 2016 at

[go-nuts] Improvement in text/template/parse/lex.go

2016-07-11 Thread &#x27;Paul Borman&#x27; via golang-nuts
I was looking at text/template/parse/lex.go and noticed it seemed to be very inefficient in how it searched for {{ in its input. I rewrote lexText to us strings.Index rather than calling l.next() for every single rune in the string. The results were up to a 9x speed improvement, depending on the

Re: [go-nuts] function with goroutine returned will kill its goroutine?

2016-07-06 Thread &#x27;Paul Borman&#x27; via golang-nuts
You probably should say all goroutines are terminated when main exits (or os.Exit is called or the program abnormally terminates), lest someone complain that their defer functions were not run. On Tue, Jul 5, 2016 at 12:29 PM, Christoph Berger < christoph.g.ber...@gmail.com> wrote: > In addition

Re: [go-nuts] Re: Relaxing rules on slice comparison: would it make sense?

2016-06-30 Thread &#x27;Paul Borman&#x27; via golang-nuts
It would be very surprising to people to use a slice as a key to map, say []int{1,2} and then find that using another []int{1,2} does not find that entry. While I think it would be nice to have == on slices, I must agree with Ian and authors that it is better left unsaid. -Paul On Thu, Jun 3

Re: [go-nuts] Detecting address family of net.IP

2016-06-17 Thread &#x27;Paul Borman&#x27; via golang-nuts
Yes, To16 gives you a 16 byte version of an IP address, which can be IPv4 or IPv6. Normally it is sufficient to just call To4 to determine if it is an IPv4 address or not and assume if it is not it must be an IPv6 address: func IsIPv4(ip net.IP) bool { return ip.To4() != nil } func IsIPv6(ip net.

Re: [go-nuts] Detecting address family of net.IP

2016-06-16 Thread &#x27;Paul Borman&#x27; via golang-nuts
Do you mean like To4 and To16 that are defined on net.IP? switch { case ip.To4() != nil: // is an IPv4 address case ip.To16() != nil: // is an IPv6 address default: // is something else } On Wed, Jun 15, 2016 at 11:29 PM, wrote: > Hi, > > In many software projects I have to get the