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
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, 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
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
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
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
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
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
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
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
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
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
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
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.
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.
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
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 +
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
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}
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:
>
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
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
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
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
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
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
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
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
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
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)
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
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))
> }
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,
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
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
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
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
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
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
>
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
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.
>
>
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
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
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
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
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.
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
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
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
> 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.
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
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
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
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 {
>>
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[""]
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
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
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
58 matches
Mail list logo