On Tue, Feb 27, 2018 at 4:01 PM, wrote:
> var j int = 42
> var p *int
> p=&int(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 function) because it doe
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 assign the results of the
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 I have tried, and my results
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 := &method()
> }
>
> func method() string {
> return
On Fri, Nov 23, 2018 at 2:06 PM Youqi yu wrote:
>
> type T {
> Name string
> }
> a := &T{Name:"test"}
> b :=&T{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
> th
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 slice. You can check it's l
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 (b *B) private() {}
>
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 = &num
>
> c := make(chan int)
>
> go func(
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 goroutines, this is an inco
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 what types of values
can b
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 used to signal condi
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
--
You received
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 closing a closed channel cau
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:
> https://play.golang.org/p/SyyWOY3fXz
>
> My
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}
https://play.golang.org/
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 function in a different proce
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 + 1 //In this line it's clear t
On Fri, Dec 15, 2017 at 8:18 AM, Ivan Kurnosov wrote:
> Why does this code not compile: https://play.golang.org/p/f5fMvO8Ns7
> func f(items ...interface{}) {
> fmt.Println(items)
> }
The spec also says:
"If the final argument is assignable to a slice type []T, it may be
passed unchanged as the
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 assignable - it may be p
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.
perhaps you wanted to use co
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.
https://play.golang.org/p/s0
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
> 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.
So
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 to do the wrong thing
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 you a new number that
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 while reading the tar
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.
https://github.com/spkg/bo
On Wed, Oct 12, 2016 at 1:26 PM, wrote:
> These are the only two places that access commitIndex. I didn't acquire the
> lock when reading commitIndex since I think its OK to read a stale value in
> my case.
Remember that locking is communication.
Saying, "I never poll the http server, it's ok if
On Wed, Oct 12, 2016 at 11:05 PM, wrote:
> Seems like a function
> pointer is more universal (I don't even need an object to be a receiver) but
> maybe an interface is more idiomatic?
An interesting pattern from the http pkg is that a function type can
also implement an interface.
https://golan
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 that I
> only want to d
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 Output" works?
>
You c
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 from the transmission."
ht
On Tue, Dec 13, 2016 at 7:43 PM, wrote:
> Hi gophers,
>
> How to prevent json unmarshal from type conversion. From the below sample
> code i got the input string converted to float64
Note that the variable 'input' is being assigned a json encoded number
and not a json encoded string.
Using a jso
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 this message because you are
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.
>
> https://play.golang.org/p/t2u2GGp565
>
> I find this une
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 unclear.
--
You received t
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
> (https://godoc.org/github.com/gorilla/websocket#Conn.ReadMessage
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 you have a requirement that
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
closed then you're not
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 is > 16384.
> When its lower
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[""] a
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 {
>> typ _type
>>
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 to convert []T to a []
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 following struct to repres
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 overlooked something and there
On Sat, Aug 13, 2016 at 7:29 AM, Anmol Sethi wrote:
> Keyed fields seem to be always better than unkeyed fields in a composite
> literal.
> Under what circumstances would I want to use unkeyed fields?
Keyed fields are better than unkeyed fields since keyed fields are
covered by the Go1 compatibi
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 destination file to the srcFil
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 that isn't an Element b
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 https://play.golang.org/p/qGraa8yQ
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 is happening.
> Any i
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 file
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, capacity and a pointer to
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))
> } else {
> data["user"], _ = sto
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 global or on the stack
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) // Does someFunc nee
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 nil channel.
In a select a
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 t
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 spec
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 langu
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 imp
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 pa
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
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 stack(i
63 matches
Mail list logo