Re: [go-nuts] How to use weak pointers?

2025-05-06 Thread Val Deleplace
tely > correct. It's not really intended for that kind of cache. I suppose the > docs could call that out more clearly. > > > On Apr 7, 2025, at 10:21 AM, Val Deleplace wrote: > > "The primary use-cases for weak pointers <https://pkg.go.dev/weak#Pointer>

[go-nuts] How to use weak pointers?

2025-04-07 Thread Val Deleplace
"The primary use-cases for weak pointers are for implementing caches" I'm trying to create objects and insert a weak pointer to each of them in a slice. The slice then contains the only reference to each object, thus it is possible for each pointer's value to b

[go-nuts] saving files on google app engine

2019-01-19 Thread Val
Hello Chris, I suspect you're trying to build a stateful server, which is highly discouraged on GAE. Scaling up and down to zero may kill instances any time, and you would lose your scoreboard, if it's in memory or in the local fs. And what about 2 instances with contradictory scoreboards? The s

Re: [go-nuts] copy is not very essential function? It can always be simulated by append?

2018-03-01 Thread Val
Jan, I think OP meant https://play.golang.org/p/_fuSb34q_ex -- 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 opt

[go-nuts] How to send multiple responses (file upload progress) to the client?

2018-01-07 Thread Val
Hello Jason Can you give us a bit more details about the components in your architecture? >From what I understand you have a go backend, a GCS bucket, and a client. So far, I've had best results for performance, security and simplicity with this combination: - backend generates a Signed upload UR

[go-nuts] Re: For loop in go templating

2017-12-12 Thread Val
Hi Josh You can add a custom func to iterate over an int : Playground This is similar to the sprig "until" func . On Tuesday, December 12, 2017 at 5:43:06 AM UTC+1, Josh Cox wrote: > > Why is there not a 'for

[go-nuts] golang.org/x/net/websocket, getting hot CPU while reading

2017-10-30 Thread Val
Hello Vladimir, first you must check errors returned by all calls of Receive and Send. Better break the loop if error is not nil. -- 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, s

[go-nuts] Re: sync.Map performance problem

2017-10-21 Thread Val
-concurrent-safe) map type, but to carefully lock a RWMutex <https://golang.org/pkg/sync/#RWMutex> before each access, which prevents data races. Cheers Val On Saturday, October 21, 2017 at 3:54:24 PM UTC+2, barce show wrote: > > how to understand this sentence > > For use cases tha

Re: [go-nuts] when to use Sync pool

2017-10-09 Thread Val
Good point, thank you Bryan. Also note that assigning a func value to p.New seems standard for the use case "if nil, then create one" (I don't know the perf implications). Cheers Val -- You received this message because you are subscribed to the Google Groups "go

Re: [go-nuts] go env GOPATH not reflecting $GOPATH

2017-09-02 Thread Val
I meant "instead of /home/dev/devSync/workspace". (Perks of replying with phone, couldn't see OP while typing.) -- 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 g

Re: [go-nuts] go env GOPATH not reflecting $GOPATH

2017-09-02 Thread Val
intended to save these moderately interesting headaches to many developers, which I find great so I encourage to go with the default path. Cheers Val -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop

Re: [go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
in the map :D > > https://play.golang.org/p/Rqn8LLI4li > https://play.golang.org/p/0TY_Bcugw8 > > On Monday, 28 August 2017 16:58:07 UTC+3, Val wrote: >> >> @Jakob sorry what I wrote was confusing, I meant : vertices have strong >> identity (same pointer), and triangle

Re: [go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
Good point. We actually do have quite a lot of code that does copy everything from one step of computation to next one, for clarity and separation of concerns. We're not afraid to do it one more time if needed, i.e. translating all fundamental Vertices to some "VerticesWithID", and then back.

Re: [go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
Thank you Sébastien, I may use some of it (Orientation, etc) in the project. Having a Point.ID is the straightforwardest way to go anyway. On Monday, August 28, 2017 at 4:03:44 PM UTC+2, Sebastien Binet wrote: > > Valentin, > > On Mon, Aug 28, 2017 at 3:58 PM, Val > > wrote:

Re: [go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
unsafe#Pointer> rules). > > Apart from that, Egon gave a couple of good suggestions :) > > On Mon, Aug 28, 2017 at 3:02 PM, Jakob Borg > wrote: > >> In that case, maybe use *Triangle pointers instead of Triangle values, >> and let that address be the identity for map

Re: [go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
onday, August 28, 2017 at 1:42:35 PM UTC+2, Jakob Borg wrote: > > On 28 Aug 2017, at 13:13, Val > wrote: > > > > To achieve this, I consider normalizing the triplet so that all keys of > the map verify > > A < B < C > > for some arbitrary definition of <

[go-nuts] Sort 3 pointers?

2017-08-28 Thread Val
Hello, I have some geometry data modelling with type Triangle [3]*Vertex (The exact definition of Vertex is unimportant here, but I'd like to avoid adding more fields inside Vertex if possible.) Then I'd like to use a triplet of vertices as the entry point of a map containing more data like c

[go-nuts] Re: Best way to truncate a ridiculously long string in GO

2017-08-22 Thread Val
: > > Val, > > That's a lot of speculation! > > The original benchmark applies to the original question: > >prefix := verylongstring[:3] > > If we change the parameters of the benchmark then we expect to get > different results. For example, read the Go gc

[go-nuts] Re: Best way to truncate a ridiculously long string in GO

2017-08-22 Thread Val
4 500029.3 ns/op 3 B/op 1 allocs/op Cheers Val On Tuesday, August 22, 2017 at 1:01:36 PM UTC+2, peterGo wrote: > > A benchmark; > > https://play.golang.org/p/oUyeldDG5Q > > $ cat strslice_test.go > package main > > import ( >

[go-nuts] Re: append() gotcha!

2017-08-16 Thread Val
more variadic elements. I mean, while there are a few usages where it is written on purpose, it makes reading and reasoning much more difficult. Val On Wednesday, August 16, 2017 at 4:53:16 AM UTC+2, DrGo wrote: > > Hello, > > The following compiles as well as evades scrutiny by g

[go-nuts] Re: Go one-line installer

2017-08-01 Thread Val
Hello Steve, that looks very promising, thank you so much! I just tried on GCE, here is a gist . Possible quirk : $ go version go: cannot find GOROOT directory: /usr/local/go $ go doc fmt go: cannot find GOROOT directory: /usr/l

[go-nuts] Re: Sorting user defined collection in multiple ways

2017-07-21 Thread Val
Hello Srinivas The traditional way to achieve this in go (as showcased here and here ) is, to : - declare a named type of slice - implement 3 methods Len, Less, Swap

[go-nuts] Re: justforfunc: a Go YouTube series

2017-07-11 Thread Val
Thanks Francesc for sharing this. Marked as not spam. On Tuesday, July 11, 2017 at 2:07:25 AM UTC+2, Francesc Campoy Flores wrote: > > Hi gophers, > > Sorry to spam you, but I'll do it only once! Today I published the episode > 15 of a YouTube series >

[go-nuts] Re: How to turn on conditional logging?

2017-06-07 Thread Val
: _ = value==expected || fail("with", "some", "variadic", "info") Val On Wednesday, June 7, 2017 at 11:07:43 PM UTC+2, Chun Zhang wrote: > > Hi, All, > > I have some piece of code with very high cpu usage, logging is actually > pret

[go-nuts] Re: trying to learn xml unmarshaling

2017-06-07 Thread Val
This looks like OFX (Open Financial Exchange ) which indeed is probably not XML. On Wednesday, June 7, 2017 at 2:15:02 PM UTC+2, Tamás Gulácsi wrote: > > Where is SEVERITY tag closed? The text you copied here is not an XML. -- You receive

[go-nuts] Re: negative unsigned value?

2017-05-23 Thread Val
May 23, 2017 at 5:27:26 PM UTC+2, Val wrote: > > FWIW, consider first that : > > if false { > foo() > bar() > } > > is legal (and sometimes recommended by autorities, as opposed to > momentarily commenting out a block, and struggling with unused vars); > an

[go-nuts] Re: negative unsigned value?

2017-05-23 Thread Val
FWIW, consider first that : if false { foo() bar() } is legal (and sometimes recommended by autorities, as opposed to momentarily commenting out a block, and struggling with unused vars); and second that : func log(msg string, level uint) { if level < appLevel { triggerBigNetworkLogTo

[go-nuts] Re: Concurrent access to map

2017-05-16 Thread Val
a map to reorganize itself on read operations (say, to move recently or frequently accessed entries to optimized buckets), go builtin maps don't do that and it is safe to have multiple concurrent readers, as long as no writer wolf enters. HTH Val On Tuesday, May 16, 2017 at 7:10:56 AM UTC+

[go-nuts] Re: strings and when to use them

2017-05-10 Thread Val
ring, without ever copying the tokens characters : tokens are just "slices" of the source code. HTH, Val On Wednesday, May 10, 2017 at 7:15:01 PM UTC+2, Zachary Kaplan wrote: > > in golang, strings are immutable. thus, if i want to modify a string in > place, i'll need to

Re: [go-nuts] sort.SliceStable behaves incorrectly, but only sometimes!

2017-05-05 Thread Val
On Friday, May 5, 2017 at 11:57:58 AM UTC+2, Ondřej Kupka wrote: > > > Performing separate stable sorts on a partial key does not produce a > stable sort on the full key. > > I think that it does, when you sort from the last key to the first key. > > Intuitively I think too that it does, but I

[go-nuts] Re: Feedback welcome: "Shorten your URL"

2017-05-02 Thread Val
Actually, html/template is good for templating, with data formatting, etc. For a static static file, consider http.ServeFile <https://golang.org/pkg/net/http/#ServeFile> On Tuesday, May 2, 2017 at 10:03:19 AM UTC+2, Lutz Horn wrote: > > Hi Val, > > > I'll go with

[go-nuts] Re: Feedback welcome: "Shorten your URL"

2017-05-02 Thread Val
;https://golang.org/pkg/html/template/>. - why write func(handler *Handler) { handler.Index(w, req) }(handler) instead of handler.Index(w, req) ? Is there an expected benefit that I'm not seeing? I wish you a pleasant journey in go world. Cheers

Re: [go-nuts] Change imaginary part of a complex

2017-04-27 Thread Val
t; On Thu, Apr 20, 2017 at 3:20 AM Val > > wrote: > >> Hello folks >> To keep real part of a complex, and set its imag part, I'm doing >> c = complex(real(c), -5.0) >> >> Is there a more concise way, something like c.imag = -5.0 ? I know

[go-nuts] Re: Why sort.IsSorted implemented with decrement?

2017-04-20 Thread Val
note, a while ago I microbenchmarked accessing all the elements of a slice, forwards or backwards : both traversals had very similar timings (which is not true when accessing in a scrambled permutation order). Thus, I wouldn't expect the end-to-beginning loop to cause a performance penalty. Val On

[go-nuts] Change imaginary part of a complex

2017-04-20 Thread Val
Hello folks To keep real part of a complex, and set its imag part, I'm doing c = complex(real(c), -5.0) Is there a more concise way, something like c.imag = -5.0 ? I know this one doesn't compile, but I may be missing something obvious. -- You received this message because you are subscrib

Re: [go-nuts] Zero value of the map

2017-04-19 Thread Val
That's interesting, though quite different from the map implementation we're used to. Do you know (in any language) such an implementation, and would it really be as fast? Computing hash, accessing some bucket, and dealing with collisions seem unavoidable. But I have no idea of the extra cost

[go-nuts] Re: File diff based go test check

2017-04-13 Thread Val
;) to the program processing, which may need to be refactored to write to a configurable io.Writer <https://golang.org/pkg/io/#Writer>. HTH Val On Thursday, April 13, 2017 at 7:35:42 PM UTC+2, Tong Sun wrote: > > My program works on files, read from input and write to output. > &g

[go-nuts] Re: Number of OS threads used by Go runtime

2017-04-12 Thread Val
<https://lh3.googleusercontent.com/-8pwOfVtHuj8/WO3m1QBlWfI/Ah0/y7oABq2mdEgJaKuL7hBwKYZe50KsjlKQgCLcB/s1600/threads.png> For visualization of this value over time, you may use go tool trace https://making.pusher.com/go-tool-trace/ HTH, Val On Thursday, April 6, 2017 at 5:37:55

[go-nuts] Re: Best practice for Method Receivers

2017-04-03 Thread Val
also be a pointer receiver even though a >>> value receiver would be acceptable? >>> https://play.golang.org/p/rd_6BLol8O >>> >>> type Foo struct{ >>> ref []int >>> val int >>> } >>> >>> // would not set if met

Re: [go-nuts] Is it harmful to always return invalid values on a non-nil-error?

2017-04-01 Thread Val
I think it is useful and goes in the right direction. Val -- 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

[go-nuts] Re: Best practice for Method Receivers

2017-03-27 Thread Val
when method returns). If you wonder about passing value arguments (e.g. val int) or reference arguments (e.g. ref []int) : both are possible and may be mixed. But this is mostly unrelated to the pointerness of the receiver. HTH Val On Saturday, March 25, 2017 at 2:20:06 AM UTC+1, st ov wro

[go-nuts] Re: Converting Panic into Error

2017-03-24 Thread Val
ate/#Must>, just doing the opposite thing. Cheers Val On Friday, March 24, 2017 at 9:50:47 AM UTC+1, Henry wrote: > > Thanks for the reply, Andrei. Your solution works. > > Jerome's solution doesn't work. I think Jerome and I made the wrong > assumption that recov

[go-nuts] Re: Guetzli perceptual JPEG encoder for Go

2017-03-18 Thread Val
for Guetzli. Cheers Val On Friday, March 17, 2017 at 6:37:43 PM UTC+1, chais...@gmail.com wrote: > > https://github.com/chai2010/guetzli-go > https://github.com/google/guetzli > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" g

Re: [go-nuts] sort.Slice arguments

2017-03-08 Thread Val
to reslice in a new variable prior to sorting : fix 3 <https://play.golang.org/p/ZgHyGOLiQO> . Best regards Val On Wednesday, March 8, 2017 at 3:25:48 PM UTC+1, David Peacock wrote: > > On Wed, Mar 8, 2017 at 8:32 AM, Valentin Deleplace > wrote: > >> I did explain the expect

[go-nuts] sort.Slice arguments

2017-03-08 Thread Val
Hello fellows The following code (playground ) : // // I am in Philadelphia, and I want to visit other cities // itinerary := []string{"Philadelphia", "Chicago", "Boston", "Austin"} // // I am in Philadelphia, and I want to visit other

Re: [go-nuts] Re: efficiency of string <-> []byte conversion

2017-02-13 Thread Val
er-related question, so I would be more comfortable letting others speak. Cheers On Monday, February 13, 2017 at 11:30:21 PM UTC+1, Alex Flint wrote: > > Thanks Val. I actually did a search before posting this and turned up many > of those same links, but it seems like they're all just reason

[go-nuts] Re: efficiency of string <-> []byte conversion

2017-02-13 Thread Val
or string to []byte, conversion, under certain circumstances". Cheers Val [1] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20string$20copy|sort:relevance/golang-nuts/m46jaS6bgZg/R5hSOPFz5m0J [2] https://groups.google.com/forum/#!searchin/golang-nuts/byte$20slice$20str

Re: [go-nuts] Re: I know finalizers are not promised to be called, but is it too not promised?

2017-01-29 Thread Val
Hello Jesper if I understand this thread correctly, "make sure" should be rephrased by "make extra efforts for ...". Sorry for nitpicking (not trying to look pedantic or arrogant) Val On Sunday, January 29, 2017 at 4:28:09 PM UTC+1, Jesper Louis Andersen wrote: > > &

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

2017-01-25 Thread Val
nnels. And even if the relationship holds locally in the writing side, it has no strong implication on what other goroutines can see. I would say the hi and lo communications happen concurrently, hence the "wrong" results once in a while. Val -- You received this message because you

Re: [go-nuts] Can somebody explain the importance of 'select'?

2017-01-21 Thread Val
to use this idiom and I would rather discourage it because it's a code smell of possible busy loop. Cheers Val On Friday, January 20, 2017 at 6:59:33 PM UTC+1, John C. wrote: > > Thank you for the explanations. I also received a helpful note off list, > put here for posterity: &

Re: [go-nuts] Deadlocking on channels

2017-01-20 Thread Val
Did you try with the race detector enabled? What was the output? If not, you really should, and it's super easy to do. Any complain from the race detector is a bug that must be fixed, not a mere warning. Cheers Val On Friday, January 20, 2017 at 8:10:42 PM UTC+1, l...@pinkfroot.com

[go-nuts] Re: Procs lines in Trace web viewer

2017-01-12 Thread Val
t; second row (line). > > On Wednesday, January 11, 2017 at 3:08:07 PM UTC+3, Val wrote: >> >> Hello >> trying to analyze and optimize the work load of my goroutines, I'm using >> the Trace <https://golang.org/cmd/trace/> web viewer and visualize th

[go-nuts] Procs lines in Trace web viewer

2017-01-11 Thread Val
es it mean that each of my physical cores has 2 logical cores? Is it related to hyperthreading? Does it mean there "might be" some way of programming the tasks to better fill the second line, thus increasing overall speed? Thank you for insight! Val -- You received this message because

[go-nuts] Re: concurrent sqlite database access... how to handle?

2016-12-29 Thread Val
rned today in the archives that code involving recursive (reentrant) mutex locking is frowned upon, regarded as a code smell, a bad practice that is very bug-prone. Cheers Val On Thursday, December 29, 2016 at 7:43:19 PM UTC+1, Eric Brown wrote: > > Thanks Val, I actually tried that approach..

[go-nuts] concurrent sqlite database access... how to handle?

2016-12-28 Thread Val
Hello Eric You may use a map[string]*sync.Mutex where key is the DB filepath, and protect that map with a global mutex. Note that a mutex value must not be copied, often it is necessary to use pointers. -- You received this message because you are subscribed to the Google Groups "golang-nuts"

[go-nuts] Re: Looking for Golang counterpart to 'params' in Python

2016-12-13 Thread Val
Hello Betsy There is no "passing optional arguments by name" in go. This link [1] has an overview what what can or can't be done for optional params : - the *Functional options* technique. - or you may define a struct as parameter, then call it with only the fields you're interested in : [2] Thi

[go-nuts] Re: Golang-present as a standalone

2016-12-07 Thread Val
Hi, maybe you visited https://godoc.org/golang.org/x/tools/present , and are looking for https://godoc.org/golang.org/x/tools/cmd/present . Or maybe you would like an embedded graphical UI, instead of using a web browser? On Wednesday, December 7, 2016 at 7:42:29 PM UTC+1, Volker Dobler wrote: >

[go-nuts] Re: Sendgrid on App Engine urlfetch client instead of defaulthttp client

2016-11-29 Thread Val
Hi, note that there also exist a specialized group "google-appengine-go" : https://groups.google.com/forum/#!forum/google-appengine-go Tamás' answer looks good, good luck On Tuesday, November 29, 2016 at 1:46:35 AM UTC+1, vanmuld...@gmail.com wrote: > > I'm running my API backend in Go on App En

[go-nuts] Re: Best practice when creating temporary files

2016-11-21 Thread Val
defer os.RemoveAll(dir) On Monday, November 21, 2016 at 4:19:26 PM UTC+1, Ondrej wrote: > > That's my current code, I just wanted to double check that it's the proper > one (ie that the cleanup actually happens), since some of my temp files can > be fairly large. > &

[go-nuts] Why is src modified when concatenating slices with dst = append(dst, src[:i])

2016-11-20 Thread Val
Hello Bogdan You're asking a very legit question. Slices are powerful but using combinations of append and reslicing can be surprisingly subtle. Step1 is easy: slicing is basically creating a new header referencing a position in an existing array, it does NOT by itself modify src. Step3 is more

[go-nuts] Re: Best practice when creating temporary files

2016-11-18 Thread Val
Obtain a new temp file : tmpfile, err := ioutil.TempFile("", "") Obtain a new temp dir : dir, err := ioutil.TempDir("", "") I suggest you don't bother with cleanup. It should work on any OS. On Friday, November 18, 2016 at 11:21:23 AM UTC+1, Ondrej wrote: > > I have a tool that generates so

Re: [go-nuts] Reaching infinity

2016-11-17 Thread Val
os.Args[1:]... looks unused, I would remove it for sake of conciseness. -- 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.

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

2016-10-20 Thread Val
I like Alan's "useful definition" of a semantically reference type, which involves shared mutable state. About the string type, I also like the implementation detail that var string t = s is O(1) in memory and running time, i.e. it happens internally to "copy the reference, not the bytes" :

[go-nuts] Re: tidy way to write a repeat-until in golang

2016-10-09 Thread Val
Hi Garry, I like the use of a bool loop variable to show intent. So I added an entry in page Do-while-loop idiom in Go <http://www.programming-idioms.org/idiom/78/do-while-loop/1847/go>. Cheers Val On Sunday, October 9, 2016 at 5:15:51 AM UTC+2, Gary Scarr wrote: > > > I pre

[go-nuts] Re: How to initialize all members of a slice

2016-10-03 Thread Val
r default value before <https://play.golang.org/p/ZMJELAZD-Y> or after <https://play.golang.org/p/l7aCbuwB3h> unmarshaling. Cheers Val On Monday, October 3, 2016 at 6:39:08 AM UTC+2, Sarah Ahmed wrote: > > Hello, > I am trying to initialize the "State" to a defa

Re: [go-nuts] How Golang implements slice?

2016-09-13 Thread Val
gt;> started: >>> >>> func foo(s []int) { >>> s := []int{1,2,3} >>> foo(s) >>> fmt.Println(s) >>> } >>> >>> Everyone know it will print [1 2 3], not [1 2 3 100]. But what I am >>> interested in, is *whether the

[go-nuts] Re: difference between template.Execute and template.ExecuteTemplate()

2016-09-09 Thread Val
lt;https://play.golang.org/p/eHdsbrKDUE> ExecuteTemplate "phase3" <https://play.golang.org/p/9BWFzxpPrM> ExecuteTemplate "wrongName" <https://play.golang.org/p/A_mxV1XJjw> Cheers Val On Friday, September 9, 2016 at 2:18:44 PM UTC+2, mir.an...@gmail.com wrote: >

[go-nuts] time.After faster than goroutine?

2016-09-03 Thread Val
This is weird. With values higher than 100ms e.g. 5000ms, ch1 and ch2 often win. I've tried in Playground only (which has a cache), not on workstation yet. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop r

[go-nuts] Re: totalling a column in a html template.

2016-08-25 Thread Val
As you may have guesses, the html/package is not designed to perform such clever calculations. It handles only the html rendering logic. You have 2 pretty good fallbacks actually : either precalculate and feed values to the template (server-side), or use javascript (client-side). Cheers Val On

Re: [go-nuts] Unary +

2016-08-19 Thread Val
Hello Ian Leading zeroes do affect the value : https://play.golang.org/p/h0iE_8_yYK I personally regard this as a gotcha, and this feeling gets stronger when an experienced gopher overlooks it. I put an entry in my go-traps <http://go-traps.appspot.com/#addition> list. Cheers Val On Sa

[go-nuts] Re: Trivial file server responds with "Moved Permanently"?

2016-08-17 Thread Val
It is now "documented behavior" (issue is closed), there are 2 mentions of this special case here https://golang.org/pkg/net/http/#FileServer and here https://golang.org/pkg/net/http/#ServeFile On Wednesday, August 17, 2016 at 8:44:36 AM UTC+2, Howard Guo wrote: > > It is a known issue, file se

[go-nuts] Cast interface{} to []string

2016-08-12 Thread Val
Looks fine to me. You'll have to iterate anyway. You can save a little perf by allocating directly the right size for your temp slice, with make. Then use indexing instead of append. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe

[go-nuts] Re: Small complete examples which show the power of Go?

2016-08-10 Thread Val
ions quite versatile in practice, but they work only on built-in types (you won't have java-like custom iterables). Cheers Val On Wednesday, August 10, 2016 at 9:53:38 AM UTC+2, gary.wi...@victoriaplumb.com wrote: > > Hi, > > I'm giving a talk at work introducing Go

Re: [go-nuts] Speeding up multiple regexp matches

2016-07-28 Thread Val
Hello Tamás, would you provide an sample impl in playground, e.g. combining patterns "ab", "ac", "bc" into "(ab)|(ac)|(bc)" and then matching input string "zabc" ? We're expecting something like [true, false, true], or ["ab", "bc"], or equivalent. I tried but got stuck because : - returned

[go-nuts] Re: Speeding up multiple regexp matches

2016-07-27 Thread Val
share sample data so we can consider sensible approaches and run benchmarks. Cheers Val On Wednesday, July 27, 2016 at 10:11:35 AM UTC+2, Raj wrote: > > Not specific to golang. Incidentally I am using go to develop this > particular tool. > > I have a piece of text that I want to

[go-nuts] Re: Can I use ... in switch? (example inside)

2016-07-27 Thread Val
ay.golang.org/p/IUqQKjKuHb On Wednesday, July 27, 2016 at 10:03:37 AM UTC+2, Val wrote: > > Like the Playground probably told you ... no. > What are you trying to achieve? > There are several valid ways to use switch > <https://golang.org/doc/effective_go.html#switch>, depend

[go-nuts] Re: Can I use ... in switch? (example inside)

2016-07-27 Thread Val
Like the Playground probably told you ... no. What are you trying to achieve? There are several valid ways to use switch <https://golang.org/doc/effective_go.html#switch>, depending whether each case is a condition, or a value, or a type. Cheers Val On Wednesday, July 27, 2016 at 5:02:33

[go-nuts] Re: Is there a way to implement this C macro in Go?

2016-07-25 Thread Val
This code "does the trick" (except in Playground) : https://play.golang.org/p/kJAfNFZUev $ go run macro.go dump(a + b) = 14 dump(b * a) = 40 $ go build -o macro $ ./macro dump(a + b) = 14 dump(b * a) = 40 Read current stacktrace, extract source file path, read source file, extract textual (u

[go-nuts] Texture codecs : DXT, PVRTC, ETC1

2016-07-18 Thread Val
or to call existing C libraries using cgo ? Note that my work consists purely in file manipulation, it is currently unrelated with how the GPU will handle the resulting compressed textures. Thanks in advance! Val [1] glimage <https://github.com/spate/glimage> and gla <https://github.com/spa

Re: [go-nuts] scheduling non determinism

2016-07-18 Thread Val
> > > For concurrent programs, obviously the program needs to be race-free -- no > reads of data that could hold different values based on grouting scheduling > of writes (using happens-before). > > Indeed, this is the definition of "racy" we're interested in. As Ian pointed out, this is disti

Re: [go-nuts] scheduling non determinism

2016-07-17 Thread Val
oven that the choice order has no side effects. - other? It's an open question for me, please share your ideas! Cheers Val On Sunday, July 17, 2016 at 6:25:32 PM UTC+2, Scott Cotton wrote: > > Hi, > > I'm well aware of the benefits of non-deterministic select for many use >

[go-nuts] [ANN] Nexer 1.1.1 code name: Billy

2016-07-17 Thread Val
Hello, ok but what is Nexer? -- 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, visit https://groups.goog

[go-nuts] Re: which approach to appending a slice to another slice by creating a new slice look best to you?

2016-07-11 Thread Val
I like 1. It's straight to the point, has no hidden costs, and doesn't inherit the subtlety of built-in "append". On Monday, July 11, 2016 at 6:06:03 AM UTC+2, Anmol Sethi wrote: > > https://gist.github.com/nhooyr/7b773ea98f0d08e698d4fe706b4f5b2a > -- You received this message because you are

[go-nuts] Re: Go 1.7 Release Candidate 1 is released

2016-07-08 Thread Val
Great menu, thanks. In the Release Notes DRAFT, "IsExist*s*" should be fixed to "IsExist", both in text and link. Cheers On Friday, July 8, 2016 at 6:50:34 AM UTC+2, Chris Broadfoot wrote: > > Hello gophers, > > We have just released go1.7rc1, a release candidate for Go 1.7. > It is cut from rel

[go-nuts] Re: log.Logger, Why is this not an interface?

2016-07-08 Thread Val
I can speak only for myself, but I had to do precisely this for the first time yesterday and it went pretty smooth. Global logger declaration : // Tests may instrument logger var logger = stdlog.New(os.Stderr, "", 0) Then, it the test suite : buffer := new(bytes.Buffer) logger = stdlog

Re: [go-nuts] Re: Singleton pattern for a client handle

2016-06-30 Thread Val
Indeed. I find it weird that the authors care more about lazy init (not strictly required for singletons) than about ensuring properly that multiple instanciation cannot happen. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe fro

[go-nuts] Re: Unused var written in closure

2016-06-26 Thread Val
If such an implicit closure struct is implicitly what happens under the hood, then this is a very good explanation of the behavior. And indeed taking the address of err is regarded as a use . Thanks Andrew, thanks folks! On Sunday, June 26, 2016 at 3:49:51 P

[go-nuts] Unused var written in closure

2016-06-25 Thread Val
ror g := func() { err = f() } g() } Is the function binding regarded as a "use"? Or does escape analysis decide to not check too deep about never-read variables? Whether expected or not, I supposed this compiler behavior won't change, because of the Go1 compatibilit

Re: [go-nuts] How to init a global map

2016-06-24 Thread Val
orted read-only accessors e.g. func (c *MyCustomContainer) Get(key string) Value Cheers On Friday, June 24, 2016 at 3:29:25 PM UTC+2, Tong Sun wrote: > > *(Thanks a lot for all your help Val!)* > > One last question, which I wasn't able to find myself from > https://blog.

Re: [go-nuts] Shuffle Items in a Slice

2016-06-24 Thread Val
The playground caches everything, so running multiple times the same program will just serve the previously generated output. Also in the playground everything is frozen at some point in the past : the clock, the randomness sources, and you can't make outgoing requests to import randomness from

[go-nuts] Re: Shuffle Items in a Slice

2016-06-24 Thread Val
2 implementations here : http://www.programming-idioms.org/idiom/10/shuffle-a-list/1564/go As for the map iteration trick, the runtime doesn't guarantee to randomize anything, although it often tries to, so developers don't rely on some specific order. I've seen (in the past) some map iteration

Fwd: [go-nuts] How to init a global map

2016-06-23 Thread Val
Sorry, last link should be: https://play.golang.org/p/_n56yMhlRt Writing all this on smartphone is possible but tedious and error-prone! -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails fro

Fwd: [go-nuts] How to init a global map

2016-06-23 Thread Val
Even in OO style (e.g. java), you would not be able to write Set s = null; s.init( list(1,2,3) ); This is (more or less) the same problem with value receiver. However, map is a reference type, so once the map has been created you really can use value receiver : https://play.golang.org/p/FePU2I-

Re: [go-nuts] How to init a global map

2016-06-23 Thread Val
https://play.golang.org/p/DTtGs3FiwZ -- 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, visit https://gro

[go-nuts] How to init a global map

2016-06-23 Thread Val
Assigning a value to the receiver will only affect local variable. Try pointer receiver. -- 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...@g

[go-nuts] can't get Content-Type and Content-Disposition to force browser to display "file->save..." dialog in the web browser

2016-06-23 Thread Val
The commented line seems to have typo strconv.Ito Maybe the typo prevents proper recompilation, and server goes on with old code? -- 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, s