[go-nuts] Re: Is there a memory leak on Rob Pike's demo codes?

2018-04-08 Thread Jason E. Aten
These days one would use context.Context to cancel the 2nd and 3rd place workers. Workers would select on the send including the channel from the cancellable Context. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this grou

[go-nuts] Regexp: Matching a new line but *not* start of string, from a Reader

2018-04-08 Thread Paul Lalonde
A ^ normally matches either the start of string or the start of a new line (with the m flag). I'd like to match only starts of lines, but not starts of strings, ideally without changing the regexp. My source data is in a ReadSeeker, and if I use Regexp.FindReaderSubmatchIndex() I can get the fi

Re: [go-nuts] Order of evaluation question

2018-04-08 Thread Dan Kortschak
I think it is, though this is a bit lawyery. > Otherwise, when evaluating the operands of an expression, assignment, > or return statement, all function calls, method calls, and > communication operations are evaluated in lexical left-to-right > order. This does not mention type conversions, so t

[go-nuts] Order of evaluation question

2018-04-08 Thread bupjae
Consider the following program: https://play.golang.org/p/_RjR5dCQ_KW package main import ( "bufio" "strings" "fmt" ) const data = "short\nthisisverylonglong\n" var in = bufio.NewScanner(strings.NewReader(data)) func next() []byte { in.Scan() return in.Bytes() } func main() { in.B

Re: [go-nuts] math type algo question and Go's int size

2018-04-08 Thread Dan Kortschak
For 64 bit word size: https://stackoverflow.com/questions/11376288/fast -computing-of-log2-for-64-bit-integers/11398748#11398748 This can be derived from examples in https://graphics.stanford.edu/~sea nder/bithacks.html which gives the 32 bit version. However, the math/bits package gives you Len,

[go-nuts] Re: Interface Literals

2018-04-08 Thread matthewjuran
Here’s a way to do a similar thing now: https://play.golang.org/p/CtEYUo6MuqN func main() { x := []int{5, 1, 4, 2, 3} sort.Sort(ClosureSort(func() int { return (len(x)) }, func(i, j int) bool { return x[i] < x[j] }, func(i, j int) { x[i], x[j] = x[j], x[i] })) fmt.Prin

[go-nuts] Re: Interface Literals

2018-04-08 Thread kduda via golang-nuts
Seven years later, I had the same idea as Js. Before: type intslice []int func (x intslice) Len() int { return len(x) } func (x intslice) Less(i, j int) bool { return x[i] < x[j] } func (x intslice) Swap(i, j int) { x[i], x[j] = x[j], x[i] } func main() { x := intslice{5, 1, 4, 2, 3} sort.Sort

[go-nuts] math type algo question and Go's int size

2018-04-08 Thread Darko Luketic
Yeah I'm not a math wiz and the older I get the harder I find maths. But sometimes you can't evade maths in programming. So here's my question for math wizards. Essentially, I'm trying to write an url shortener. And I found this package I agree with (don't re-invent the wheel) https://github.com/n

[go-nuts] Re: Concurrent and blocking stack

2018-04-08 Thread matthewjuran
1. What are a stack and queue? 2. What does “concurrent and blocking” mean for a data structure? 3. What does accessing one var from concurrent goroutines look like? We can answer these for you if you don't know the answer. Matt On Sunday, April 8, 2018 at 12:37:26 AM UTC-5, Xen wrote: > > Hi

[go-nuts] Re: Concurrent and blocking stack

2018-04-08 Thread Stefan Nilsson
That's a tough one. If your interviewer is an excellent engineer without an ego, you may want to point out that it might be better to keep concurrency and data structures separated. Perhaps you could even tell the story of the deprecated Java Vector class. If your interviewer want you to show t