Re: [go-nuts] Re: why not support explicit delete in golang?

2021-05-28 Thread Jesse McNelis
On Fri, May 28, 2021 at 4:51 PM cheng dong wrote: > Thank you for the clarification. > sorry to break the general rule, i'm new to golang-nuts > > as to the question, i figured out i used wrong words, what i need in fact > is1. a hint to tell compiler that some object are safe to alloc on

Re: [go-nuts] Re: why not support explicit delete in golang?

2021-05-27 Thread Jesse McNelis
On Fri, May 28, 2021 at 12:56 PM cheng dong wrote: > to avoid false delete object, we could add some checking code in > markDelete just like what we do with raceenable. > one complicate case is internal pointer, we could recursively mark delete > or mark delete internal pointer by hand ? > This

Re: [go-nuts] prevent unnecessary escape to heap

2021-02-04 Thread Jesse McNelis
On Fri, Feb 5, 2021 at 12:32 PM Steve Roth wrote: > > How can I implement a writeByte function, against an unknown io.Writer > implementation, that doesn't allocate heap memory? > > As you've correctly stated, because the call to .Write() is via an interface the compiler can't tell whether any

Re: [go-nuts] rin: return if nil syntactic sugar

2020-08-31 Thread Jesse McNelis
On Mon, Aug 31, 2020 at 3:31 PM Zakaria wrote: > If the objections on the too magical handle part, why not cut that part > and retain the check part? > > Most of the time the we just forward the error on to the next level > anyway. Handling error is rarely done and should be explicit. > It's

Re: [go-nuts] political fundraising on golang.org!

2020-06-14 Thread Jesse McNelis
On Mon, Jun 15, 2020 at 8:12 AM andrey mirtchovski wrote: > Hi, > > I have a non-profit I'd like to support. Who do I ask to put a banner > on golang.org for me? > > (reductio ad absurdum) > This sounds like a great idea to me. It would probably need to be a non-profit that furthers the Go

Re: [go-nuts] Nondeterministic Behavior of for Loop Ranging Over a map

2020-05-26 Thread Jesse McNelis
On Tue, May 26, 2020 at 3:37 PM Paul Jolly wrote: > > Why the output of this code is nondeterministic? > > See https://golang.org/ref/spec#For_statements, specifically the "For > statements with range clause" subheading, specifically this bullet: > > > 3. The iteration order over maps is not

Re: [go-nuts] Type of function parameter changes

2020-05-16 Thread Jesse McNelis
Hi, You can simply do: func P(args ...interface{}) { print("\n", args...) } The problem you encountered was that you were passing the args as a single argument to print() The 'var args' syntax collects the arguments and puts them in a slice. So args in P() is a []interface{}. You then pass

Re: [go-nuts] Question re fcns that return multiple values

2019-08-05 Thread Jesse McNelis
On Tue, Aug 6, 2019 at 1:38 PM wrote: > For f1 defined as func f1(k1, k2, k3 int) (x1, x2 int) {..} > and f2 defined as func f2(x,y int) (xR int) {..} > > Why does the compiler complain about the call stmt > f2 ( f1 (1,2,3) ) ?? > I'm not sure what you're asking. The compiler

Re: [go-nuts] does struct pointer *a == *b make sense?

2018-11-22 Thread Jesse McNelis
On Fri, Nov 23, 2018 at 2:06 PM Youqi yu wrote: > > type T { > Name string > } > a := {Name:"test"} > b :={Name:"test"} > *a == *b > Hi, all, I am beginner at golang, I have a question that when compare struct > equality, I was told to use reflect.DeepEqual or make my own function. but > the

Re: [go-nuts] cannot take the address of method()

2018-09-23 Thread Jesse McNelis
On Mon, Sep 24, 2018 at 5:33 AM, Tamás Király wrote: > Hi, > > can anyone explain why the following does not work? > i want to have the return value's address not the method itself. > > package main > > func main() { > //first > addressofstring := () > } > > func method() string { > return

Re: [go-nuts] Having difficulty converting []byte to float

2018-05-17 Thread Jesse McNelis
On Fri, May 18, 2018 at 12:26 PM, wrote: > Hello all. I am creating a custom exporter for FreeNAS > https://github.com/Maelos/freenas_exporter and am stuck on the conversion of > the string of bytes provided by the commands output to a float. Here is my > code, what

Re: [go-nuts] multiple-value f1() in single-value context

2018-02-27 Thread Jesse McNelis
On Wed, Feb 28, 2018 at 12:23 PM, Alex Dvoretskiy wrote: > Hello Golang-nuts > > Why it is not allowed to pass function result like this to return?: > > https://play.golang.org/p/YPeaeW_4WZ6 > > > Or it is allowed without declaring temporary variables i3, i4? You need to

Re: [go-nuts] Re: Cannot take the adress of.....

2018-02-26 Thread Jesse McNelis
On Tue, Feb 27, 2018 at 4:01 PM, wrote: > var j int = 42 > var p *int > p=(j) //this doesn't work > fmt.Println(*p) > Yep, this is true. You can't take the address of the return value of a function or a conversion (which is conceptually just a

Re: [go-nuts] Is this a bug or am I missing something?

2017-12-18 Thread Jesse McNelis
On Tue, Dec 19, 2017 at 4:10 PM, Sasan Rose wrote: > Hi Jess > > Apologies for my bad example. Please kindly see my reply to Dave's post. > Thanks I fixed your example so that the slice called 'combination' isn't shared with every slice in every iteration of the loop.

Re: [go-nuts] Is this a bug or am I missing something?

2017-12-18 Thread Jesse McNelis
On Tue, Dec 19, 2017 at 8:54 AM, Sasan Rose wrote: > Please take a look at https://play.golang.org/p/BL4LUGk-lH solutionNew = make([]int, 0) solutionNew = append(solution, 2) Is a strange thing to do, you create a new slice using make([]int, 0) and then never use it.

Re: [go-nuts] Variadic assignable values and covariance

2017-12-14 Thread Jesse McNelis
On Fri, Dec 15, 2017 at 11:08 AM, Ivan Kurnosov wrote: > Jesse, > > what you quoted is an optimisation for the "Otherwise, the value passed is a > new slice of type []T with a new underlying array whose successive elements > ". > > Your quote says: if the final argument is

Re: [go-nuts] Inconsistency in gofmt

2017-12-12 Thread Jesse McNelis
On Wed, Dec 13, 2017 at 11:01 AM, Pablo Rozas Larraondo wrote: > Hello, > > I'm curious to know if this is intended: > > https://play.golang.org/p/t353t8ZvL1 This is intentional. gofmt uses spacing to group expressions based on precedence of operators. eg. (i+2)/2 +

Re: [go-nuts] Any way to run functions in independent threads/processes in go?

2017-12-10 Thread Jesse McNelis
On Sun, Dec 10, 2017 at 6:38 PM, shockme wrote: > Hi, > > I'd like to know if there is any way to run go functions in independent > threads/process, just like multiprocessing.Pool.apply. > Go has goroutines to allow for running code on different threads. Running a Go

Re: [go-nuts] interface{} as type []interface{}

2017-11-09 Thread Jesse McNelis
On Fri, Nov 10, 2017 at 10:27 AM, Trig wrote: > Is it possible to have an interface{} as type []interface{}? Yep, you can store a slice of interface{} in an interface{} eg. // interface{} holding an []interface{} holding ints var a interface{} = []interface{}{1,2,3,4,5}

Re: [go-nuts] function variable scope

2017-11-04 Thread Jesse McNelis
On Sun, Nov 5, 2017 at 3:47 AM, wrote: > Hi, > > Newbie here. I am trying to understand the scope of variables in go - I ran > across an interesting situation and want to learn what is going on. Why do > these two functions yield different results: >

Re: [go-nuts] is this code thread safety?

2017-11-02 Thread Jesse McNelis
On Thu, Nov 2, 2017 at 4:54 PM, sheepbao wrote: > > the close function is thread safety? how about call `closed` at the same > time. It's not safe. Multiple goroutines can enter the 'default' case in that select and close() the channel multiple times. "Sending to or

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

2017-10-31 Thread Jesse McNelis
On Wed, Nov 1, 2017 at 3:42 AM, wrote: > Today you can't, Ayan. > It's very consistent, you can't compare an interface value reliably to any untyped constant. Because there is no way for the compiler to figure out what type it should take. https://play.golang.org/p/4Fn0YNE2md

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

2017-10-30 Thread Jesse McNelis
On Tue, Oct 31, 2017 at 2:25 AM, wrote: > I found this a little bit non sequitur - if I want to call interface > function I have a perfect business to check if underlying object is not nil > before call just to avoid panic on call. Besides underlying nil in interface > may be

Re: [go-nuts] const struct

2017-09-08 Thread Jesse McNelis
On Fri, Sep 8, 2017 at 2:52 PM, DrGo wrote: > Sorry if this was asked before, but I could not find any relevant posts. > > Any reason why this struct literal (made up of fields that can be declared > const) is not allowed? https://golang.org/ref/spec#Constants describes

Re: [go-nuts] A question about evaluation of channel’s send statement

2017-09-05 Thread Jesse McNelis
On Wed, Sep 6, 2017 at 2:26 AM, T L wrote: > > I mean it can be viewed as a bug for inconsistency. > But from the memory model view, it can also not be viewed as a bug. > It's not a bug. The code is clearly expecting some ordering between internal operations within two

Re: [go-nuts] A question about evaluation of channel’s send statement

2017-09-04 Thread Jesse McNelis
On Tue, Sep 5, 2017 at 10:34 AM, Marlon Che wrote: > Hi everyone! > Please help me figure out the two different results of following code: > > package main > > import ( > "fmt" > "time" > ) > > func main() { > var num = 10 > var p = > > c := make(chan

Re: [go-nuts] Struct overloading method issue

2017-09-02 Thread Jesse McNelis
On Sat, Sep 2, 2017 at 12:50 AM, BeaT Adrian wrote: > Hello, I ran into a strange scenario and I wanted to know if there is a > better solution for it > > type A struct{} > > func (a *A) private() {} > func (a *A) Public() { >a.private() > } > > type B struct {A} > > func

Re: [go-nuts] Regexp documentation error?

2017-08-11 Thread Jesse McNelis
On Fri, Aug 11, 2017 at 9:03 PM, Jens Hausherr wrote: > I see, > > I was just confused by the fact that fmt.Printf("%q/%v") apparently renders > a nil array as an empty array ([]) while rendering other nil values (e.g. > pointers) as . Yep, a nil slice is also an empty

Re: [go-nuts] Isn't it better just to panic when you send/recv on a nil channel instead of forever blocking?

2017-05-04 Thread Jesse McNelis
On Fri, May 5, 2017 at 1:35 PM, Ronald wrote: > > So the question: > > Isn't it better just to throw a panic when user send/recv on a nil > channel instead of forever blocking it? If not, what is the benefits? There is value in the ability to have a select case be a

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

2017-04-18 Thread Jesse McNelis
On Tue, Apr 18, 2017 at 10:04 PM, Tad Vizbaras wrote: > I am just curious what is the reason behind not making zero maps more > useful? Is it space? The problem is that maps are mutable. var a map[int]int a[1] = 1 // could be fine and useful. var a map[int]int someFunc(a)

Re: [go-nuts] Re: one GC implementation question

2017-03-22 Thread Jesse McNelis
On Wed, Mar 22, 2017 at 8:51 PM, T L wrote: > > More accurately, I think it should be: from the POV of a programmer, it's > globals, and things reachable from each goroutine. > The only way to reach a value is through a variable in scope and the only variables in scope are

Re: [go-nuts] Map value assignment inside if loop

2017-03-11 Thread Jesse McNelis
On Sat, Mar 11, 2017 at 10:14 PM, priyank pulumati wrote: > Hello, > Go newbie here > > func (data map[string] interface {}) { > if len(data) == 0 { > data := make(map[string]interface{}) > data["user"], _ = store.GetUser(context.Get(req, "userid").(string)) > }

Re: [go-nuts] A naive question, why not move the len and cap fields of string and slice types into the underlying types?

2017-03-03 Thread Jesse McNelis
On Fri, Mar 3, 2017 at 6:49 PM, T L wrote: > After all, the len and cap fields of any value of string and slice values > are immutable. > This is slices and strings are currently. A string value contains a length and a pointer to some bytes. A slice contains a length,

Re: [go-nuts] Re: Serve large files

2017-02-28 Thread Jesse McNelis
Try using os.Open to get a *File (which implements io.Reader), and then > io.Copy to the response from the file. > You should use https://golang.org/pkg/net/http/#ServeFile that's what it does. It will also handle requests with range headers for allowing the client to fetch just a part of the

Re: [go-nuts] Beginner Question : Reassignment of counter variable inside for loop in https://github.com/golang/mobile/tree/master/example/flappy

2017-02-22 Thread Jesse McNelis
On Thu, Feb 23, 2017 at 8:59 AM, Victor Kovacs wrote: > > // The ground. >> for i := range g.groundY { >> i := i >> // The top of the ground. >> newNode(func(eng sprite.Engine, n *sprite.Node, t clock.Time) { >> > > While this solves the issue I would like to understand what

Re: [go-nuts] is this race condition normal?

2017-02-18 Thread Jesse McNelis
On Sun, Feb 19, 2017 at 3:59 PM, Marwan abdel moneim wrote: > i'm reading a book about concurrency, and was doing some baby steps > so i'm trying to manage a variable changes to be locked when a process > starts and freed when it ends > > this is the initial code

Re: [go-nuts] Why can't interface parameters auto-convert types that implement that interface?

2017-02-07 Thread Jesse McNelis
On Wed, Feb 8, 2017 at 5:41 PM, wrote: > satisfies the interface, but requires a type assertion. However, > > func (e E) Less(e2 Element) bool { > return e.value < e2.value > } > If this version of Less() satisfied the interface Node what happens when I pass something

Re: [go-nuts] File transfer,but file size is zero

2017-02-07 Thread Jesse McNelis
On Tue, Feb 7, 2017 at 9:01 PM, Robert Hsiung wrote: > Hi all: > I tried to upload file via SFTP,but the file size is zero when it is > done.Any suggestions? Thanks so much. > // Copy the file > > dstFile.WriteTo(srcFile) > > } > You're writing the empty

Re: [go-nuts] Multiplexing blocking call on Go routine

2017-01-04 Thread Jesse McNelis
On Thu, Jan 5, 2017 at 9:51 AM, wrote: > Hey guys, > > So for some time now I have been trying to build a high performance Pub/Sub > server in Go. I am using gorilla websocket library, which in it self has a > Read, Write methods >

Re: [go-nuts] I see the usage of interface{} everywhere why don't it get declare in standard library and given a common name?

2016-12-30 Thread Jesse McNelis
On Fri, Dec 30, 2016 at 9:24 PM, San wrote: > I have a question. > Since the usage of the blank interface is so popular. > Why does it not get declared in the standard library? > Giving it a name has been discussed many times. What would be a good name for it is still

Re: [go-nuts] Unexpected type switch case listing & equality behaviour for float64

2016-12-30 Thread Jesse McNelis
On Sat, Dec 31, 2016 at 3:26 AM, Uwe Dauernheim wrote: > It seem a float64 of value 0.0 as types interface{} can't be compared equal > to 0 in an exhaustive case clause type list, but can be compared equal in > almost any other scenario. > >

Re: [go-nuts] Correct naming of Go !

2016-12-27 Thread Jesse McNelis
On Wed, Dec 28, 2016 at 12:26 AM, Ken Nakagama wrote: > Hi Everyone > > Across the ether of the Internet, Go! is referred to and keyworded > differently. Go! is a completely different language. https://en.wikipedia.org/wiki/Go!_(programming_language) -- You received

Re: [go-nuts] gob ignores default values, bug or feature?

2016-12-10 Thread Jesse McNelis
On Sat, Dec 10, 2016 at 5:49 PM, Hoping White wrote: > Hi, all > > I find that gob encoding ignores fields when they have zero values. > I wonder if this is a bug or an feature? > " If a field has the zero value for its type (except for arrays; see above), it is omitted

Re: [go-nuts] Thinking OO virtual function in Go

2016-11-22 Thread Jesse McNelis
On 23 Nov. 2016 9:03 am, "Tong Sun" wrote: > > So, once again, thinking in OO, I'll define all of the common variables in base class, and common functionalities in virtual functions. How to make that idea work in Go? > > For the above specific code, how to easily make "func

Re: [go-nuts] Thinking OO virtual function in Go

2016-11-22 Thread Jesse McNelis
On Wed, Nov 23, 2016 at 8:16 AM, Tong Sun wrote: > Hi, > > How to architect the OO's virtual function in Go? > > Please take a look at this (not working) Go program > https://play.golang.org/p/qrBX6ScABp > > Please think of the "func Output()" as a very complicated function

Re: [go-nuts] Ignoring UTF-8 BOM when decoding JSON

2016-09-23 Thread Jesse McNelis
On Fri, Sep 23, 2016 at 9:37 PM, Mark Richman wrote: > > Is there any way to tell Decode() to ignore the BOM, or do I have to peek at > the first 3 bytes and skip them somehow? > What you need is an io.Reader that skips the BOM. Luckily someone wrote a package for that.

Re: [go-nuts] Newbie Struggling w/ Hashing

2016-09-19 Thread Jesse McNelis
On 20 Sep 2016 9:03 a.m., "Robert Solomon" wrote: > > FileReadBuffer := make([]byte,ReadBufferSize); > for { // Repeat Until eof loop. > n,err := TargetFile.Read(FileReadBuffer); > if n == 0 || err == io.EOF { break } > check(err," Unexpected error

Re: [go-nuts] Re: Why + and += operators for string but not slices?

2016-09-16 Thread Jesse McNelis
On 17 Sep 2016 12:31 p.m., wrote: > > Context enables homonyms in spoken languages and overloaded or polymorphic notation in mathematics. Types do the same in programming languages. The rationale for + over join() or cat() for string is equally applicable to slices. 1+1 give

Re: [go-nuts] Why a **T value can't call methods of *T and T if a *T value can call methods of T?

2016-08-22 Thread Jesse McNelis
On Tue, Aug 23, 2016 at 3:11 PM, T L wrote: > If a programmer will call it anyway, she/he doesn't care efficiency. What > she/he cares is the convenience and cleanness. > ppt.f() is surely cleaner than (*ppt).f(), right? > It shouldn't be convenient or look clean

Re: [go-nuts] Why a **T value can't call methods of *T and T if a *T value can call methods of T?

2016-08-22 Thread Jesse McNelis
> Why a **T value can't call methods of *T and T if a *T value can call methods > of T? How many levels of auto dereferencing should there be? Should *T still have the same method set as *T? It's reasonable to set a sensible limit because pointer chasing is an expensive operation.

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

2016-08-12 Thread Jesse McNelis
On Sat, Aug 13, 2016 at 4:41 AM, Vasily Korytov wrote: > Hi, > > I have an interface{} variable that can be either string or a list of string > (yes, that's bad design, I know). Your code below indicates that you're storing a []interface{} not an []string. > Have I

Re: [go-nuts] Is there a function in standard lib to convert []T to a []interface{}?

2016-08-04 Thread Jesse McNelis
On Thu, Aug 4, 2016 at 3:33 PM, T L wrote: > > With some special memory optimizations for slice, I think it is possible to > make efficient conversions from []T to []interface. > For example, we don't need to convert every element in []T to interface{}, > we can just use

Re: [go-nuts] Is there a function in standard lib to convert []T to a []interface{}?

2016-08-03 Thread Jesse McNelis
On 4 Aug 2016 12:36 a.m., "T L" wrote: > > Often, I need converting a []T to []interface{} to use the []interface as a variable length parameter. > But converting a []T for []interface{} in a for loop is neither clean nor efficient. > > So is there a function in standard lib

Re: [go-nuts] Will the real value allocated on heap copied when assigning an interface value to another?

2016-07-31 Thread Jesse McNelis
On Sun, Jul 31, 2016 at 5:10 PM, T L wrote: > By reading Ross Cox's article: http://research.swtch.com/interfaces > I got an interface value is represented by a struct as the following: > >> >> type interfaceStruct struct { >> value *_value >> inter *struct { >>

Re: [go-nuts] Using "map index expressions" as the value for a range loop

2016-07-07 Thread Jesse McNelis
On 8 Jul 2016 12:19 a.m., "Jan Mercl" <0xj...@gmail.com> wrote: > > I did not expect the result I've got: https://play.golang.org/p/ECno0PVdBF > > It seems like a bug to me. > Looks fine to me. The k in m[k] is the value of k before the assignment. So the value at m["foo"] is assigned to m[""]

Re: [go-nuts] why is my program retaining memory when len([]byte)>16384 ?

2016-07-03 Thread Jesse McNelis
On Mon, Jul 4, 2016 at 3:35 AM, mhhcbon wrote: > Hi, > > I have this program which reads file, flate encode then flate decode the > data. > > I noticed that when i used different size for the slice of []byte to read > data, the program will retain memory when the size

Re: [go-nuts] golang poll/epoll/select

2016-06-25 Thread Jesse McNelis
On 25 Jun 2016 11:08 p.m., "Michael Soulier" wrote: > > Sure, but when you read and get an EOF you return immediately, so the goroutine would be busy waiting when there's nothing to read, would it not? > You'll only get an EOF if the file descriptor has been closed, if it's

Re: [go-nuts] net.ListenUDP, ListenTCP & new go routine creation

2016-06-20 Thread Jesse McNelis
On 21 Jun 2016 12:42 a.m., "Manohar Kumar" wrote: > > I am mainly interested in Linux and have to make these calls in a part of the code where new OS thread creation isn't desirable. Please note that changing that aspect of the design itself is not an option for me. If