| Thread overview | |||||
|---|---|---|---|---|---|
|
December 17, 2011 Array concat quiz | ||||
|---|---|---|---|---|
| ||||
A small quiz. This Python2 code:
m1 = [["A'", "B'"]]
print m1
m2 = m1 + [[]]
print m2
Prints:
[["A'", "B'"]]
[["A'", "B'"], []]
What does this D2 program print?
import std.stdio;
void main() {
string[][] m1 = [["A'", "B'"]];
writeln(m1);
string[][] m2 = m1 ~ [[]];
writeln(m2);
}
Bye,
bearophile
| ||||
December 17, 2011 Re: Array concat quiz | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | Don't forget that string is an alias for immutable(char)[]. The immutable isn't important here, but the fact that strings are arrays is. char[][][] is the real type here. | |||
December 17, 2011 Re: Array concat quiz | ||||
|---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 12/17/2011 02:43 AM, bearophile wrote:
> A small quiz. This Python2 code:
>
> m1 = [["A'", "B'"]]
> print m1
> m2 = m1 + [[]]
> print m2
>
>
> Prints:
>
> [["A'", "B'"]]
> [["A'", "B'"], []]
>
>
> What does this D2 program print?
>
> import std.stdio;
> void main() {
> string[][] m1 = [["A'", "B'"]];
> writeln(m1);
> string[][] m2 = m1 ~ [[]];
> writeln(m2);
> }
>
> Bye,
> bearophile
I do not think that this is very sensible (array-array appends are more natural than array-element appends, so disambiguation should go the other way). Is it documented anywhere or is it just an implementation artefact?
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply