| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
November 25, 2009 News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Found on Reddit: This looks a lot like D: http://research.swtch.com/2009/11/go-data-structures.html New features in Java, some of them look like D: http://code.joejag.com/2009/new-language-features-in-java-7/ Bye, bearophile | ||||
November 25, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Wed, 25 Nov 2009 03:03:59 +0300, bearophile <bearophileHUGS@lycos.com> wrote:
> Found on Reddit:
>
> This looks a lot like D:
> http://research.swtch.com/2009/11/go-data-structures.html
>
> New features in Java, some of them look like D:
> http://code.joejag.com/2009/new-language-features-in-java-7/
>
> Bye,
> bearophile
Looks like go has arrays that support slices. Do they support appending? If so, what's their behavior and how do they solve stomping issues?
| |||
November 25, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Denis Koroskin wrote: > On Wed, 25 Nov 2009 03:03:59 +0300, bearophile <bearophileHUGS@lycos.com> wrote: > >> Found on Reddit: >> >> This looks a lot like D: >> http://research.swtch.com/2009/11/go-data-structures.html >> >> New features in Java, some of them look like D: >> http://code.joejag.com/2009/new-language-features-in-java-7/ >> >> Bye, >> bearophile > > Looks like go has arrays that support slices. Do they support appending? If so, what's their behavior and how do they solve stomping issues? There's no built-in means to grow a slice. An example given in "Effective Go" appends to slices without regard to stomping or dissolving sharing: http://golang.org/doc/effective_go.html Slices are obese pointers storing the pointer/length/capacity troika. I think D is in better shape here. Andrei | |||
November 26, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Denis Koroskin | Wed, 25 Nov 2009 12:27:59 +0300, Denis Koroskin wrote:
> On Wed, 25 Nov 2009 03:03:59 +0300, bearophile <bearophileHUGS@lycos.com> wrote:
>
>> This looks a lot like D: http://research.swtch.com/2009/11/go-data-structures.html
>
> Looks like go has arrays that support slices. Do they support appending? If so, what's their behavior and how do they solve stomping issues?
Arrays are values and cannot be resized after creation.
var array [10]int;
Arrays can be sliced like in D:
var slice []int = array[5:7];
The length of this slice is len(slice) == 7 - 5 == 2. The *capacity*
of this slice is cap(slice) == 10 - 5 == 5.
You can slice a slice beyond its length, up to capacity:
var slice2 []int = slice[4:5];
Effectively slice is a tail of an array, with optional subdivision into sub-head and sub-tail.
There is no array nor slice concatenation, nor any other way to change slice length except slicing.
| |||
November 26, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Sergey Gromov | Sergey Gromov:
> var slice []int = array[5:7];
Is []int better than int[] ?
[5:7] is a slice syntax a bit better than [5..7] (and it's used in Python). But in D [5:7] is the literal for an AA...
Bye,
bearophile
| |||
November 26, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | Thu, 26 Nov 2009 11:58:23 -0500, bearophile wrote:
> Sergey Gromov:
>> var slice []int = array[5:7];
>
> Is []int better than int[] ?
>
> [5:7] is a slice syntax a bit better than [5..7] (and it's used in Python). But in D [5:7] is the literal for an AA...
You could change to syntax for AAs to be 5 -> 7 since D doesn't use -> for lambdas :) And even when D starts supporting them, they could use => instead.
| |||
November 26, 2009 Re: News/info on Go and Java | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | Thu, 26 Nov 2009 11:58:23 -0500, bearophile wrote: > Sergey Gromov: >> var slice []int = array[5:7]; > > Is []int better than int[] ? Well, try to read aloud int[5][10]. I come up with "Integer, five of them, ten times." While [10][5]int is "Array of ten arrays of integers." It's *much* clearer. > [5:7] is a slice syntax a bit better than [5..7] (and it's used in Python). But in D [5:7] is the literal for an AA... In Go, it'd be map[int]int{5:7}. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply