Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Franco Marchesini
Now that I looked at the source, I learned. // Reader is the interface that wraps the basic Read method. // // Read reads up to len(p) bytes into p. It returns the number of bytes // read (0 <= n <= len(p)) and any error encountered. Even if Read // returns n < len(p), it may use all of p

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Jan Mercl
On Fri, Jun 30, 2017 at 2:42 PM Franco Marchesini < franco.marches...@gmail.com> wrote: > Aside from the correction, however, I did not understand why the method is called 2 times. HTH: https://play.golang.org/p/Na7GtgZ-_B -- -j -- You received this message because you are subscribed to

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Franco Marchesini
Aside from the correction, however, I did not understand why the method is called 2 times. Il giorno venerdì 30 giugno 2017 12:51:20 UTC+2, Franco Marchesini ha scritto: > > Yes, after Dave's answer I realized the mistake. > This is a solution. > > Il giorno venerdì 30 giugno 2017 11:42:45

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Franco Marchesini
Yes, after Dave's answer I realized the mistake. This is a solution. Il giorno venerdì 30 giugno 2017 11:42:45 UTC+2, Sebastien Binet ha scritto: > > > > On Fri, Jun 30, 2017 at 11:38 AM, Franco Marchesini > wrote: > >> 1. >> >> Because with 2 there is a problem. The

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Sebastien Binet
On Fri, Jun 30, 2017 at 11:38 AM, Franco Marchesini < franco.marches...@gmail.com> wrote: > 1. > > Because with 2 there is a problem. The method is called twice and is > inefficient. > what about checking your errors, then ? :) https://play.golang.org/p/K8j8D0AZe9 -s > Il giorno venerdì 30

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Franco Marchesini
1. Because with 2 there is a problem. The method is called twice and is inefficient. Il giorno venerdì 30 giugno 2017 11:31:31 UTC+2, Jan Mercl ha scritto: > > On Fri, Jun 30, 2017 at 9:48 AM Franco Marchesini > wrote: > > > Why after the execution the k value is 2? >

Re: [go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Jan Mercl
On Fri, Jun 30, 2017 at 9:48 AM Franco Marchesini < franco.marches...@gmail.com> wrote: > Why after the execution the k value is 2? What value of k do you expect instead and why? ( https://play.golang.org/p/wdWo3fahAS) -- -j -- You received this message because you are subscribed to the

[go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Dave Cheney
Oh, sorry, I know. It'll be because the first time through your reader returns , nil, and on the second time returns 0, io.EOF. So Read is called twice, but on the second time does no work. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

[go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Dave Cheney
Print out the size of p each time Read is called -- 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...@googlegroups.com. For more options,

[go-nuts] why rot13Reader example run twice?

2017-06-30 Thread Franco Marchesini
Hello, why the method Read of rot13Reader run twice? This is the code: package main import ( "fmt" "io" "os" "strings" ) type rot13Reader struct { r io.Reader } var k int func (rot *rot13Reader) Read(p []byte) (n int, err error) { k++ n,