Re: How about Go's &Struct instead of new?

2009-11-12 Thread Bill Baxter
On Thu, Nov 12, 2009 at 5:32 PM, xx wrote: >> In Go (from what I understand), a struct is stack allocated with >>    x := Struct(); >> and heap allocated with >>    x := &Struct(); > > It's a nice trick, but I don't find it intuitive. Getting address of an > object (re)allocates it? Literal that

Re: How about Go's &Struct instead of new?

2009-11-12 Thread xx
> In Go (from what I understand), a struct is stack allocated with >x := Struct(); > and heap allocated with >x := &Struct(); It's a nice trick, but I don't find it intuitive. Getting address of an object (re)allocates it? Literal that has different address each time?

Re: How about Go's &Struct instead of new? addendum

2009-11-12 Thread Justin Johansson
Justin Johansson Wrote: > Currently in my D projects I use static opCall to eliminate "new" (at least > for > classes) such as: > > class Foo > { > int x; > Foo( int x) { this.x = x; } > static Foo opCall( int x) { return new Foo( x); } > } > > I'm not sure if this considered good D style

Re: How about Go's &Struct instead of new?

2009-11-12 Thread Justin Johansson
Bill Baxter Wrote: > I fear there could be a long parade of these "How about Go's " > topics, but anyway, here goes... > > Mostly just a syntax bikeshed, but this seemed like a nice way to > eliminate the "new" syntax that wasn't mentioned previously. > They also kind of round out the dec

How about Go's &Struct instead of new?

2009-11-12 Thread Bill Baxter
I fear there could be a long parade of these "How about Go's " topics, but anyway, here goes... In Go (from what I understand), a struct is stack allocated with x := Struct(); and heap allocated with x := &Struct(); For D that would be auto x = Struct(); // stack auto x = &Struct(