Re: [go-nuts] Getting a pointer in a type switch gives a *interface {} if case lists several options

2016-06-22 Thread Marvin Renich
* raidopah...@gmail.com [160621 18:02]: > I have encountered some unexpected and inconsistent behavior with type > switches. Can someone shed some light as to why Go behaves this way? > > Take a look at https://play.golang.org/p/YPV5YPtWF8 > > I would expect both of the

Re: [go-nuts] Re: How to create reusable HTML components using default html/template package

2016-08-08 Thread Marvin Renich
* Paulo Janeiro [160808 11:14]: > I understand what your point, but I'm just trying to see if this is > something easy to do by myself or if I should start looking into a framework > Nevertheless, I'm using Phoenixframework (Elixir). > Here we could define a layout

Re: [go-nuts] Re: is it possible to speed up type assertion?

2017-02-02 Thread Marvin Renich
* T L [170202 04:20]: > > > On Thursday, February 2, 2017 at 4:58:32 PM UTC+8, Axel Wagner wrote: > > > > Hi, > > > > I can not really reproduce your results. I rewrote your code to use the > > builtin benchmarking: http://sprunge.us/IfQc > > Giving, on my laptop: > > > >

Re: [go-nuts] Re: is it possible to speed up type assertion?

2017-02-02 Thread Marvin Renich
* Marvin Renich <m...@renich.org> [170202 09:22]: > > BenchmarkIface is testing the wrong thing; the value is swamped by the > implicit conversion of d (type T) to the function argument of type I. Or, maybe it is testing the correct thing. That is the problem with microben

Re: [go-nuts] Short vs. long variable declarations

2017-01-28 Thread Marvin Renich
* Will Faught [170127 21:58]: > Variable shadowing is rarely, if ever, a problem for me too; but what about > for newcomers? > > I think my copy/paste point stands, though; everyone has those problems, at > least occasionally. I agree with you. See my earlier post for my

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

2017-02-22 Thread Marvin Renich
On Tue, Feb 21, 2017 at 1:46 PM, wrote: > Seems like named returns + if/for/switch initializers = a shadowing > nightmare. I wish the Go compiler emitted a loud warning on shadowing, as > this is a dangerously subtle problem out there. * Ian Lance Taylor [170221

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

2017-02-22 Thread Marvin Renich
* John Souvestre [170222 11:16]: > Ø does it sounds good to disable (in specs) named return vars shadowing ? > > This would help, I don't think this is a good solution. It also breaks Go 1 compatibility. > but the := problem isn’t limited to return variables. > I think

Re: [go-nuts] Understanding go routine heap

2016-08-20 Thread Marvin Renich
* Konstantin Shaposhnikov [160820 06:34]: > The code might be race free for the current Go implementation but I don't > think this behaviour is documented. > > https://golang.org/ref/mem doesn't mention sync.WaitGroup at all. So > wg.Done() doesn't necessarily happen

Re: [go-nuts] Re: Understanding go routine heap

2016-08-22 Thread Marvin Renich
* Joubin Houshyar [160822 09:47]: > > > On Saturday, August 20, 2016 at 2:29:41 AM UTC-4, Yulrizka wrote: > > func process() *foo { > > var result *foo > > > > var wg sync.WaitGroup > > wg.Add(1) > > go func() { > > defer wg.Done() > > result

Re: [go-nuts] Re: Is uint(v) when v is minus because a huge number supposed behavior?

2017-02-26 Thread Marvin Renich
* peterGo [170225 22:40]: > On Saturday, February 25, 2017 at 10:21:49 PM UTC-5, Felix Sun wrote: > > https://play.golang.org/p/TmxMmltHGH > > > > package main > > > > import ( > > "fmt" > > ) > > > > func main() { > > var f int = -1 > > fmt.Println("become huge number:",

Re: [go-nuts] exec.Command

2016-10-05 Thread Marvin Renich
* hadiesmail...@gmail.com [161005 05:46]: > hi > > in the second arg in function exec.Command(), what i must put it?? > > and any my question is : > > i want run a cmd command.for example : cls > > how can i run this method? The second argument is a variadic

Re: [go-nuts] Re: The site at localhost:1234 can't be reached.

2016-09-17 Thread Marvin Renich
* Dave Cheney [160917 15:58]: > Move http.ListenAndServe to the top of the main() function, outside the > http.HandleFunc call and it will work. Don't you mean bottom? At the top, the ListenAndServe will not return, so the HandleFunc call will never be made, so you will always

Re: [go-nuts] differences between pointer and value slice in for-range loop

2016-09-19 Thread Marvin Renich
* Fei Ding [160918 02:58]: > Thanks, Marvin, I've learned a lot from your reply. And, I've written more > code, like: > > a, b, c := 1, 2, 3 > > slice1 := []int{a, b, c} > > for _, n := range slice1 { > > go func(n *int) {fmt.Println(*n)}() > > } > > > It seems that pass

Re: [go-nuts] Randomizing contents of a file

2016-09-20 Thread Marvin Renich
* Unknown User [160920 06:43]: > Hi All, > > I am trying to print the contents of a file randomizing the lines. > The following code works, but does not exit even after all the lines are > read. > What needs to be done to correct it? Try this

[go-nuts] playground URL to fetch code only

2016-09-20 Thread Marvin Renich
Is there a way to take a playground URL, such as https://play.golang.org/p/Vg6f0gSs3l, and modify it (e.g. with a query string) so that you can retrieve just the code as text without the surrounding html? Something like curl 'https://play.golang.org/p/Vg6f0gSs3l?text' If not, would such a

Re: [go-nuts] Re: playground URL to fetch code only

2016-09-20 Thread Marvin Renich
* Ivan Anfilatov [160920 10:36]: > https://play.golang.org/p/Vg6f0gSs3l.go > > compile - post request to https://play.golang.org/compile in body request - > source > response - json Thanks, Ivan! ...Marvin -- You received this message because you are subscribed to

Re: [go-nuts] playground URL to fetch code only

2016-09-20 Thread Marvin Renich
* Nicolas Martyanoff [160920 10:07]: > curl 'https://play.golang.org/p/Vg6f0gSs3l.go', i.e. just appending '.go' will > do the trick. Excellent! Thank you! ...Marvin -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To

Re: [go-nuts] differences between pointer and value slice in for-range loop

2016-09-17 Thread Marvin Renich
* Fei Ding [160916 23:30]: > Link here: https://play.golang.org/p/cdryPmyWt5 > > The code above is going to check the differences between pointers and > values in a for loop, while go statement is also used at the same time. For > code: > > values :=

Re: [go-nuts] Re: Understanding go routine heap

2016-08-22 Thread Marvin Renich
* Joubin Houshyar <jhoush...@gmail.com> [160822 12:36]: > On Monday, August 22, 2016 at 10:27:06 AM UTC-4, Marvin Renich wrote: > > * Joubin Houshyar <jhou...@gmail.com > [160822 09:47]: > > > > > > Your firend is correct that using a WaitGroup here does

Re: [go-nuts] How to define two identical named types?

2016-10-02 Thread Marvin Renich
* Matt Harden [161001 23:34]: > I do think that T L has a point. The spec defines the syntax of the > language, and TypeSpec refers to a syntactical construct. It is not > possible in the syntax of the language to create two named types that > originate in the same

Re: [go-nuts] why "iota"?

2016-11-09 Thread Marvin Renich
* liyu1...@gmail.com [161109 08:26]: > I don`t know how to speak 'iota' too,I have to say "i---o---t---a" when I > talk with somebody. > > 在 2013年4月28日星期日 UTC+8上午8:52:36,mb0写道: > > > > > Wikipedia says it's a greek alphabet that looks like i, and I am seeing > > > APL used

Re: [go-nuts] Are short variable declarations necessary?

2016-11-09 Thread Marvin Renich
* T L [161109 05:18]: > On Friday, October 21, 2016 at 11:26:46 PM UTC+8, T L wrote: > > Thanks, gri, this is almost the answer I want. > > > > I still have two small questions about the short form. > > 1. would it be good to allow all identifiers in a short form are old ones

Re: [go-nuts] Are short variable declarations necessary?

2016-11-09 Thread Marvin Renich
* T L [161109 11:57]: > yes, := can be avoided totally. > but := really has some benefits. > > The contradiction is the short form is 80% good with 20% bad side effects. I disagree. I saves three characters and in doing so adds much more cognitive load to distinguish

[go-nuts] html/template modifies template outside of actions

2016-11-11 Thread Marvin Renich
In this code (at https://play.golang.org/p/HVxzsn0_eC) package main import ( "fmt" "html/template" "os" ) var tmpl = ` {{range .}} {{.}}{{end}} ` var items = []string{"one", "two", "three"} func main() { var t, err = template.New("").Parse(tmpl) if err == nil {

Re: [go-nuts] html/template modifies template outside of actions

2016-11-11 Thread Marvin Renich
* Ian Davis <m...@iandavis.com> [16 06:04]: > On Fri, Nov 11, 2016, at 09:21 AM, Marvin Renich wrote: > > > the Execute method escapes the first character ('<' in " > "". This seems wrong to me, both logically and according to the > > documentatio

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

2016-10-21 Thread Marvin Renich
* T L [161021 01:47]: > This faq, "Why are maps, slices, and channels references while arrays are > values?", https://golang.org/doc/faq#references. > thinks maps, slices, and channels are references. I think the "references" > here means "reference values". That's not the

Re: [go-nuts] Re: converting slice of items into nested array

2016-12-08 Thread Marvin Renich
* Mikael Gustavsson [161208 03:55]: > There's no need to use maps, you want to follow this pattern: > > for i := range items { > if i==0 || !grouped(i-1, i) { > appendToResult > } > appendToGroup > } > > Here's the full example: https://play.golang.org/p/1e0rDDmq7b

Re: [go-nuts] Golang text template - time.Format epoch

2016-12-08 Thread Marvin Renich
* 'Sergey Krutsko' via golang-nuts [161208 02:12]: > Thanks Marvin! > > that's exactly what i need > > bwt, is there any way to get current timestamp inside the template (without > referencing to the data structure) ? > > something like that: > "timestamp:

Re: [go-nuts] Reset Slice with Make Every Time?

2017-01-10 Thread Marvin Renich
* Tomi Häsä [170110 02:23]: > On Tuesday, January 10, 2017 at 1:49:37 AM UTC+2, kortschak wrote: > > On Mon, 2017-01-09 at 15:12 -0800, Tomi Häsä wrote: > > > Is this the correct way of resetting a slice? I mean do I always > > > need to use make to reset a slice? > > > >

Re: [go-nuts] Golang text template - time.Format epoch

2016-12-07 Thread Marvin Renich
* skrutsko via golang-nuts [161207 08:30]: > Hello > > I have a field in my text template: "start":"{{.Start.Format "Jan 02, 2006 > 15:04:05 UTC"}}" > > But, I want to have output as epoch time. E.g. 148110633400 > > Could you please explain how to do this ?

Re: [go-nuts] Re: Building with "go install" vs "go build"

2017-04-18 Thread Marvin Renich
* Dave Cheney [170418 09:57]: > > Apparently Dave Cheney says to prefer "go install" over "go build"[3], > except when cross-compiling [4]. However, many of these posts are older, > and Golang moves at such a rapid clip that it's difficult to keep track of > what everybody is

Re: [go-nuts] memory gc when slice shortcut

2017-03-09 Thread Marvin Renich
* 代君 [170309 05:45]: > I have a []*Struct, at some times it length grow to 1000, after that, the > slice be shortcut to length of 10, and never grow to 1000 again. > > dose the memory of *Struct at slice's tail will never be gc? What Jan says is correct, but if your program

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-09 Thread Marvin Renich
* T L <tapir@gmail.com> [170709 04:56]: > On Friday, July 7, 2017 at 8:42:28 PM UTC+8, Marvin Renich wrote: > > Yes, the go routine establishes a happens-before relationship such that > > x is incremented before y, and the atomic Add of y and Load of y ensure > > t

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
* T L [170710 12:32]: > so this is guaranteed by go memory model? > > package main > > import "fmt" > import "sync/atomic" > > func main() { > var x, y int32 > > atomic.AddInt32(, 1) > atomic.AddInt32(, 1) > > if atomic.LoadInt32() == 1 { >

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
* T L [170710 12:35]: > so this is guaranteed by Go memory model? > > package main > > import "fmt" > import "sync/atomic" > import "unsafe" > > func main() { > var x, y int32 > > var p = unsafe.Pointer() > > atomic.AddInt32(, 1) >

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-10 Thread Marvin Renich
[Reply-To set; I don't need two copies of replies.] * T L [170710 12:31]: > so this is guaranteed by Go memory model? > > package main > > import "fmt" > import "sync/atomic" > > func main() { > var x, y int32 > go func() { > atomic.AddInt32(, 1) >

Re: [go-nuts] does Go memory model guarantee this program always prints 1?

2017-07-07 Thread Marvin Renich
* T L [170707 01:32]: > Then how about this? > > package main > > import "fmt" > import "sync/atomic" > > func main() { > var x, y int32 > go func() { > atomic.AddInt32(, 1) > atomic.AddInt32(, 1) > }() > > if atomic.LoadInt32() == 1 {

Re: [go-nuts] Slice capacity changes

2017-08-08 Thread Marvin Renich
* sno [170808 20:57]: > package main > > import ( > "fmt" > "reflect" > "unsafe" > ) > > func main() { > a := []byte("1234567") > printSliceDetails(a) > } > > func printSliceDetails(a []byte) { > sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer()) >

Re: [go-nuts] Slice capacity changes

2017-08-09 Thread Marvin Renich
[I'm subscribed; reply-to set.] * sno [170808 21:34]: > Hmm, interesting. However, wouldn't that mean that if I removed the > function and did the following: https://play.golang.org/p/enI6UmYoFJ the > escape analysis wouldn't happen? Why would escape analysis not

Re: [go-nuts] Re: use of builtin print for debug

2017-05-09 Thread Marvin Renich
* mhhc...@gmail.com [170509 07:10]: > Also i think go has already several patchers that you might get > inspiration from, not sure where they are located. Sorry : x Try man gofmt and look at -r. ...Marvin -- You received this message because you are subscribed to the Google

Re: [go-nuts] Re: use of builtin print for debug

2017-05-09 Thread Marvin Renich
[I set an explicit Reply-To header because I do not want duplicate emails. Please do not CC me; I read this list.] * mhhc...@gmail.com [170509 07:40]: > : ( thanks > > $ man gofmt > Aucune entrée de manuel pour gofmt > /no such entry/ One of many advantages of the Debian

Re: [go-nuts] Handling errors in functions

2017-06-21 Thread Marvin Renich
* suburb4nfi...@gmail.com [170621 08:44]: > Is it possible to give a default nil value to an error at the beginning of > a function and then just assign to it in case of need ? What I want to do > is something like the following : > > func GetSummonerByName(name

Re: [go-nuts] Handling errors in functions

2017-06-21 Thread Marvin Renich
* Marvin Renich <m...@renich.org> [170621 09:48]: > package main > > import ( > "fmt" > ) > > func Calc(a int) (r int, err error) { > if a == 0 { > err = fmt.Errorf("Bad argument") > return >

Re: [go-nuts] Re: issues about struct align

2017-05-23 Thread Marvin Renich
* Marvin Renich <m...@renich.org> [170523 08:58]: > Looking more closely at the MSDN docs for FwpmFilterAdd0 and > FWPM_FILTER0, if I were doing this, I might use «RawContext uint64» > instead of «ProviderContextKey GUID», which would be properly aligned > without manual

Re: [go-nuts] Save file handle into struct

2017-06-07 Thread Marvin Renich
* Tong Sun [170607 15:53]: > So, Here is the update version. > > 1. https://play.golang.org/p/txOIO1riwd > 2. https://play.golang.org/p/_Qk9n0mZPM > > The two version only differ on line 26 & 29. However, the second one will > get the following while trying to do

Re: [go-nuts] os.Args[0] for program executed by go

2017-06-01 Thread Marvin Renich
* Santhosh Ram Manohar [170601 14:03]: > > > On Thursday, June 1, 2017 at 10:45:56 AM UTC-7, Jan Mercl wrote: > > > > On Thu, Jun 1, 2017 at 7:41 PM Santhosh Ram Manohar > > wrote: > > > > > Args: []string{"self", "selftest"}, > > > > Here you

Re: [go-nuts] Timestamp issues

2017-09-15 Thread Marvin Renich
* xana...@gmail.com [170915 03:16]: > No the clients are connected to this app through websockets, they are using > javascript, following snippet is used to make the countdown: > let timeLeft = Math.ceil(((timestamp * 1000) - new Date().getTime()) / 1e3) Okay, so the clients

Re: [go-nuts] "html/dom" alternative to html/template for true separation of concerns?

2017-09-14 Thread Marvin Renich
* Karv Prime [170913 22:01]: > It = html/template > "The purpose" = the one I thought I could use it for and described above. I'm still not sure you understand the capabilities of html/template. This playground snippet might help you: https://play.golang.org/p/_1KSiZbwh-

Re: [go-nuts] Timestamp issues

2017-09-14 Thread Marvin Renich
* dr.ink [170914 10:26]: > Hello, I have an issue with generating timestamps in golang, this is how my > app works. First the app generates the timestamp like this > > timestamp := time.Now().UTC().Add(time.Second * > time.Duration(settings.TimeToLive)).Unix() > > this

Re: [go-nuts] Re: "html/dom" alternative to html/template for true separation of concerns?

2017-09-14 Thread Marvin Renich
* Karv Prime [170914 11:14]: > ... - yet > there's the disadvantage of the need to put artifacts into the markup which > then get replaced by the wanted content You have to do that anyway, you just use different artifacts. Each location where a substitution will occur

Re: [go-nuts] Timestamp issues

2017-09-15 Thread Marvin Renich
* xana...@gmail.com [170915 12:33]: > Yes, I have also tried this on separate devices and some were off and some > were exact to the second so this is definitely a frontend therefore > javascript issue and not an issue with golang. Not sure how to fix it but > this is not a

Re: [go-nuts] Re: "html/dom" alternative to html/template for true separation of concerns?

2017-09-14 Thread Marvin Renich
* Karv Prime [170914 13:16]: > I wouldn't agree on "there is not even a need for the wrapper" part. > If the HTML tags are produced entirely by code, it comes with its own > issues - suddenly there is a thing that wasn't in the markup - it would > probably reduce

Re: [go-nuts] Why bytes Buffer's ReadFrom method blocked when read from a UDP connection?

2017-09-20 Thread Marvin Renich
* Ricky Zhang [170920 08:26]: > UDP Server's code: > >listener, err := net.ListenUDP("udp", {IP: > net.ParseIP("127.0.0.1"), Port: 9981}) >data := make([]byte, 1024) >for { > n, remoteAddr, err := listener.ReadFromUDP(data) Here,

Re: [go-nuts] concurrent write-only to map ok?

2017-10-13 Thread Marvin Renich
* Alex Buchanan [171013 14:06]: > Basically, I want to spawn a goroutine per object, objects have unique IDs, > and I want each routine to write its results to a shared map. Nothing will > be reading from the map while the goroutines are running. You didn't give much

Re: [go-nuts] Scope of variables with closures

2017-10-11 Thread Marvin Renich
* Marvin Renich <m...@renich.org> [171011 08:19]: > > >> > //func fibo2() func() (x int) { > ^ > > Here, x is a placeholder name within a type literal; it is not within > the scope of fibo. ^ Typo; should be fi

Re: [go-nuts] Scope of variables with closures

2017-10-11 Thread Marvin Renich
* etienne.da...@gmail.com [171011 03:14]: > I was thinking of your answer, and I don't understand when you say: > > > within a func type literal such as `func() (x int)`, the scope of the > > parameters and results is restricted to the type literal itself. > > > Because

Re: [go-nuts] Re: error handling needs syntactical sugar

2017-09-08 Thread Marvin Renich
* Dorival Pedroso [170908 02:08]: > The "watch" strategy would, of course, allow us to do the important steps > you've mentioned (e.g. clean up and so on). > > For instance: > watch err != nil { > // do the important things > return err > } Except that "do the

Re: [go-nuts] Defer with anon func and func literal

2017-09-28 Thread Marvin Renich
* Karan Chaudhary [170928 08:50]: > I'm trying to find rationale for this: why is "defer foo(x)" treated > differently than "defer func() { foo(x) }" by the language designers? Here is what the language spec says: Each time a "defer" statement executes, the function value

Re: [go-nuts] Errors out of syscall

2017-10-02 Thread Marvin Renich
* Chris Hopkins [171002 10:52]: > out, err := os.Create(potential_file_name) > switch t := err.(type) { > case *os.PathError: > switch t.Err { > case os.ErrNotExist: > log.Fatal("Invalid filename", potential_file_name) > case os.ErrInvalid: >

Re: [go-nuts] Errors out of syscall

2017-10-02 Thread Marvin Renich
* Marvin Renich <m...@renich.org> [171002 11:31]: > * Chris Hopkins <cbehopk...@gmail.com> [171002 10:52]: > > out, err := os.Create(potential_file_name) > > switch t := err.(type) { > > case *os.PathError: > > switch t.Err { > > case

Re: [go-nuts] Problems with JSON Marshal/UnmarshalText aand maps

2017-11-28 Thread Marvin Renich
* Henrik Johansson [171128 07:43]: > But wouldn't unmarshal just overwrite in case of more trivial keys? > > So pointer receivers on the marshaling methods is better. > I think I tried it but something else blew up. While MarshalText can use a value or pointer receiver, it

Re: [go-nuts] Surprise About How Method Receivers Work

2017-12-18 Thread Marvin Renich
* jlforr...@berkeley.edu [171217 15:33]: > Here's what I believe is the explanation. The book says (slightly > edited) "If the receiver p is a variable of type Path but the method > requires a *Path receiver, we can use this shorthand: > > p.pr1() > > and the compiler

Re: [go-nuts] Re: Learning Go: suggestions for code review?

2017-12-13 Thread Marvin Renich
* Ben Hoyt [171213 09:45]: > > One minor thing may be that instead of using os.Args, I would use the > > flag's package. > > Good call. If you like the Plan 9 convention of -short style options, the standard library's flag package is good and simple. If you want the GNU

Re: [go-nuts] What are Parse Html token methods for email templates in golang?

2017-11-10 Thread Marvin Renich
* Josh Kamau [171110 03:47]: > You can use 'with' to achieve what you want. > Take a look at this example > > https://play.golang.org/p/incDGEmUJK > > On Wed, Nov 8, 2017 at 12:03 PM, wrote: > > I could not found such token system in golang or any

Re: [go-nuts] Puzzle: make a sync.Once fire more than once

2017-11-20 Thread Marvin Renich
* roger peppe [171120 09:35]: > This trick is used in the standard library (see net.http.envOnce.reset), and > for > testing purposes it's just about OK (though still dubious IMHO) but you should > never use it in production code, as you're writing atomic state with >

Re: [go-nuts] Puzzle: make a sync.Once fire more than once

2017-11-20 Thread Marvin Renich
* Carl Mastrangelo [171119 19:25]: > I was playing around with a puzzle trying to break the sync package and > found something cool. Can you think of a definition for f that causes > once.Do to execute the argument more than once? > > package main > > import ( >

Re: [go-nuts] Re: How to know if interface{} data is nil w/o reflecting?

2017-10-31 Thread Marvin Renich
* oju...@gmail.com [171031 12:34]: > Ian, with all due respect, I beg to differ. > > Let's look at that example posted 5 years back: > > http://play.golang.org/p/Isoo0CcAvr > > Yes, that is the proper behavior according to the rules, we have a FAQ > entry, fine, but ... put

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Marvin Renich
* Michael Jones [180430 13:54]: > Andrey, that's great! > > On the Fibonacci series evaluation, let's make sure that we're all doing > the same calculation. For completeness and safety, let's skip all library > values and derived values. Here are more-than-sufficient

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-05-01 Thread Marvin Renich
* andrey mirtchovski [180430 17:41]: > > math.Pow does not give as precise answers as the C++ std lib. > > math pow doesn't just multiply X by itself Y times, it uses a > different algorithm: > > https://golang.org/src/math/pow.go#L40 Sure, I understand that. However,

Re: [go-nuts] float accuracy when calculating Fibonacci numbers

2018-04-30 Thread Marvin Renich
* Yuval Lifshitz [180430 02:02]: > It seems like go and C++ are doing something different regarding floating > point arithmetic, but I cannot say one is better than the other. It is just > the that C++ consistently overshoots (hence truncation work), and go > consistently

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-24 Thread Marvin Renich
* dc0d [180124 14:44]: > > > > > If the channel is nil, there's nothing to lock. But also, there's no > > sending happening. > > > > So first the payload is computed and then the nil check happens? To add to what Axel said, it would be inconsistent to only evaluate

Re: [go-nuts] why can't change map when in for range statements?

2018-01-16 Thread Marvin Renich
* sheepbao [180115 21:24]: > I wrote this code, and why `map=nil` don't stop the loop? > > func mapTest() { > for k, v := range m { > println(k, v) > m = nil > } > } > > output: > > 1 1 > > 2 2 > > I don't understand when I set `m = nil`, the

Re: [go-nuts] how to add items to an array without append function.

2018-01-12 Thread Marvin Renich
* pradam [180112 01:45]: > I'm Newbie to golang, Welcome to Go! Many newbies often use "golang" rather than "Go" as the language name, and most old-timers usually ignore this incorrect usage, but golang is an artifact of the web site's hostname, golang.org. Also,

Re: [go-nuts] Re: Is my understanding on numeric literals right?

2018-01-12 Thread Marvin Renich
* 'Axel Wagner' via golang-nuts [180112 05:11]: > Hm, this thread has actually opened up a question I don't have a good > answer to. > > On Fri, Jan 12, 2018 at 9:47 AM, wrote: > > an untyped interger literal/constant is representable float64

Re: [go-nuts] strings.Split behavior

2018-02-20 Thread Marvin Renich
* buc...@gmail.com [180220 15:51]: > package main > > import ( > "fmt" > "strings" > ) > > func main() { > s := "this/that there/here that/this" > tmp := strings.Split(s, "/") > fmt.Println(tmp) > for _, s1 := range tmp { > if strings.Contains(s1, "that") { >

Re: [go-nuts] Type "slicing"

2018-08-01 Thread Marvin Renich
* Paul J. Lucas [180728 14:43]: > First, please forgive the length of the example code. It's as small a > distillation of my original code as I could manage that still > illustrates the issue. The code is here: > > https://play.golang.org/p/MjyFize1iOW > > [trimmed] > > The problem is

Re: [go-nuts] Re: looking for a flexible file path resolver

2018-08-07 Thread Marvin Renich
* DrGo [180806 18:37]: > There are situations where you need to check (and report back to the user) > for file existence no matter how you do that (using Stat or by attempting > to open or create it). I agree completely. However, doesn't os.Stat do what you want here simply and portably? If

Re: [go-nuts] why my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao [180814 10:53]: > Thank you for your detailed answer. > I thought it would crash in this line (b.Z = "zz") of code. But it dose not > happen and the program print "zz". > I don't understand why this program crash in return, not in b.Z = "zz". > Because I agree with your opinion, The

Re: [go-nuts] Re: go/format ouputs spurious newlines

2018-08-14 Thread Marvin Renich
* n...@mit.edu [180814 11:43]: > The documentation can be interpreted as you say. I do not see how you can interpret it otherwise. > If the resulting AST is subsequently inserted into a larger AST and then > serialized, the source that is output can be syntactically invalid. > > It is

Re: [go-nuts] Re: looking for a flexible file path resolver

2018-08-06 Thread Marvin Renich
* DrGo [180806 02:00]: > Thanks, > filepath.Abs does some of what I want, but as far as I could tell, it does > not handle resolving relative paths Does this code help out? if filepath.IsAbs(somepath) { somepath = filepath.Clean(somepath) } else { var wd, err = os.Getwd() if err !=

Re: [go-nuts] Re: go/format ouputs spurious newlines

2018-08-14 Thread Marvin Renich
* n...@mit.edu [180814 09:47]: > The documentation for parser.ParseExpr says that the position information > in the AST it returns "is undefined". I opserved the result as having > position information. This looks like a bug. > > https://play.golang.org/p/tpzqDF3EZ_S > > demonstrates this

Re: [go-nuts] why my program will panic?

2018-08-14 Thread Marvin Renich
* sheepbao [180813 23:45]: > go version > go version go1.10.2 darwin/amd64 > > test code: > > func TestPoint(t *testing.T) { > type A struct { > X int > Y string > } > type B struct { > X int > Y string > Z string > } > > a := A{X: 2,

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Marvin Renich
* Michael Jones [180830 11:44]: > The task to "translate a string through a table" is common. It is a single > computer instruction (TR) in the IBM 360 and was extended over time with > related instructions for conversion in and out of UTF-8, testing before and > after translation, and expanded

Re: [go-nuts] Re: Nil Channels and Case Evaluation

2018-01-23 Thread Marvin Renich
* dc0d [180123 08:45]: > Can anybody help me understand the reason? (It's in the spec. That's not > the reason) > > On Sunday, December 31, 2017 at 10:14:31 AM UTC+3:30, dc0d wrote: > > > > Assume there is this select statement: > > > > for { > > select { > >

Re: [go-nuts] How to bufio.Write with a length specified?

2018-01-18 Thread Marvin Renich
* Peng Yu [180118 18:37]: > Dan & Bruno, > > I didn't realize that it is as simple as that :) Thanks. > > Does it involve any extra copy of the byte slice? Or f.Write literally > access the memory of d and only access 2 bytes of data for writing to > the buffer? The blog

Re: [go-nuts] Re: panic propagation can be blocked by blocking defer function

2018-04-02 Thread Marvin Renich
* 'Bryan Mills' via golang-nuts [180402 15:10]: > This is indeed a subtle pattern, but it's not clear to me how often it > comes up in practice, and preventing deferred function calls from blocking > could result in all kinds of other unwanted side effects. I'd

Re: [go-nuts] Re: About a channel detail, bug, defect, or intended?

2018-03-26 Thread Marvin Renich
It seems that you understand why you are seeing the behavior you reported, but you are questioning whether the spec either does or should guarantee that reading from a channel with a goroutine waiting to send on that channel will fill the buffer as an atomic part of the read. As others have said,

Re: [go-nuts] Is this a bug?

2018-02-25 Thread Marvin Renich
The point to remember is that each value of a concrete type has exactly that one concrete type, while each value of an interface type has exactly one interface type and one concrete type. It is also important to note that there is a distinction between "assignability" and "type-assertiblity". *

Re: [go-nuts] Is there some kind of memory write protection mechanism?

2018-02-25 Thread Marvin Renich
* d...@veryhaha.com [180225 11:37]: > I think I get it. > Because the above program tries to modify the constant (or program) zone, > which is not allowed. > The following program works: But, note that the language spec does not guarantee it to work. The compiler is free to

Re: [go-nuts] Regarding contracts

2018-10-22 Thread Marvin Renich
> Ian Denhardt : > > But I think fundamentally folks have to > > make choice: do we want to be able to write `<` for user defined types, or > > do > > we want to be able to look at the `<` operator and know for certain that > > it's > > not calling a method? You can't have both. You can have

Re: [go-nuts] Regarding contracts

2018-10-22 Thread Marvin Renich
* Burak Serdar [181018 15:08]: > tbh, I am not trying to avoid operator overloading, I am trying to > avoid the contracts. With operator overloading, you can write: > > func F(a,b type T like(int,X)) { >if a ... >} > } > > provided X is a type that supports <. Are you trying to

Re: [go-nuts] Generics: an unwelcome conclusion and a proposal

2018-10-17 Thread Marvin Renich
* Ian Lance Taylor [181016 17:59]: > The contract system in the generics design draft does not have this > problem. It may have other problems, but it doesn't have this one. I haven't finished reading the draft (I got to the beginning of the Contract Details section when it was first mentioned

Re: [go-nuts] Regarding contracts

2018-10-25 Thread Marvin Renich
* Andy Balholm [181024 17:52]: > What I’m doing with structural contracts is basically the same as what > you’re doing with struct and interface types as contracts, except that > (I hope) the syntax is a little clearer. > > I added the support for operators basically to avoid having the >

Re: [go-nuts] Traverse directory without infinite loops while following links

2018-10-04 Thread Marvin Renich
* EricR [181004 13:33]: > Hi! I'm new to Go and need to do something with each file in directories. > Symlinks need to be followed. I've tried filepath and a few popular > libraries and they either crash with segfaults on my system, do not follow > symlinks or do not prevent infinite loops. >

Re: [go-nuts] Casting Back from nested Struct

2018-10-10 Thread Marvin Renich
* Chris Hopkins [181010 12:04]: > Hi, > I appreciate this is not possible, but realised I never understood why (so > have just been working around it). > Example code at: > https://play.golang.org/p/BgFL9T0KiC7 > > I can create a struct with other structs as a member. I then get all the >

Re: [go-nuts] Traverse directory without infinite loops while following symlinks

2018-10-07 Thread Marvin Renich
[I've set reply-to to include you (per your reply-to) but to exclude me; I prefer to read my list mail on the list rather than in my personal inbox.] * rob solomon [181006 15:17]: > I've been trying to do something simple like this, but I'm not interested in > following symlinks.  Here I just am

Re: [go-nuts] Character Replacement/Algorithm for Replacement

2018-08-30 Thread Marvin Renich
* Tamás Gulácsi [180830 01:17]: > An even faster lookup is creating a [256]byte array for the replacements, > having the 9 replacements candidates _position_ having the replacements, > all others the identity: > > // prepare the lookup table > var a [256]byte > for i := 0; i<256; i++ { >

Re: [go-nuts] Re: Are Go floats smarter?

2018-08-30 Thread Marvin Renich
* José Colón [180830 06:53]: > Very interesting. So would it be a good idea to use these types of untyped > constant calculations for financial applications, or instances where one > would use the math.big package? Not likely. You would have to know at compile time the exact values you wanted

Re: [go-nuts] "All types implement the empty interface"

2019-01-23 Thread Marvin Renich
* 伊藤和也 [190123 00:27]: > I found the explanation "All types implement the empty interface". > https://golang.org/ref/spec#Interface_types > So an empty interface also implements an empty interface? and again the > empty interface implements an empty interface and the empty inter... > What I

Re: [go-nuts] errgroup example without channels

2018-12-03 Thread Marvin Renich
* Mu11 [181203 11:47]: > I saw the example > of > errgroup in godoc, and it makes me confused that it simply assigns the > result to global results instead of using channels in each search routines. > Heres the code: > >

  1   2   >