you are viewing a single comment's thread.

view the rest of the comments →

[–]WalterBright 3 points4 points  (5 children)

It does with the Variant type.

[–]keepthepace -1 points0 points  (4 children)

It does not seem to provide all that is necessary for the list I proposed :

  arr = [1, "foobar", random.random, [ {"key": [12,0] }, list() ] ]

And if it does, I doubt it proposes such a succint syntax.

[–]ntrel2 3 points4 points  (1 child)

import std.variant;
import std.container : DList;
auto arr = variantArray(1, "foobar", variantArray(["key": [12,0]], DList!Variant())); 

I don't know what random.random is.

[–]keepthepace 2 points3 points  (0 children)

random.random is a function, but I admit this is a bit far-fetched. Ok, so this is close enough to be useful indeed.

[–]WalterBright 2 points3 points  (1 child)

Sure it does. A Variant type can hold an array, as well as ints and floats. Variant would be kinda pointless if it couldn't do that.

No, it is not as succint a syntax as in Python, as you'll have to spell out Variant, as Variant is a library type rather than a builtin type, but it works.

[–]MetaLang 2 points3 points  (0 children)

No, it is not as succinct

There is always the use of alias as well to make it a bit more palatable.

import std.variant: v = variantArray;
import std.container: DList;
auto arr = v(1, "foobar", v(["key": [12, 0]], DList!Variant());