digitalmars.D.learn - Create a List or Dictionary.
- Sunny (7/7) Jun 18 2018 Hello, I'm having a problem, how can I create a List or
- rikki cattermole (3/12) Jun 18 2018 https://dlang.org/spec/arrays.html#dynamic-arrays
- Cym13 (22/29) Jun 18 2018 If I read you well it seems the simplest equivalent code would be:
Hello, I'm having a problem, how can I create a List or Dictionary in D? var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> (); In Google did not find anything, tell me please how to get out of this situation?
Jun 18 2018
On 18/06/2018 11:44 PM, Sunny wrote:Hello, I'm having a problem, how can I create a List or Dictionary in D? var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> (); In Google did not find anything, tell me please how to get out of this situation?https://dlang.org/spec/arrays.html#dynamic-arrays https://dlang.org/spec/hash-map.html
Jun 18 2018
On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:Hello, I'm having a problem, how can I create a List or Dictionary in D? var musicList = new List <(string URL, string Artist, string Title, string Cover, string Duration)> (); In Google did not find anything, tell me please how to get out of this situation?If I read you well it seems the simplest equivalent code would be: struct MusicItem { string URL; string Artist; string Title; string Cover; string Duration; } MusicItem[] musicList; You could technically use tuples to get to the same point but I don't really see a point, structs fit that purpose very well. Then you can: musicList ~= MusicItem(url, artist, title, cover, duration); musicList = [musicItem1, musicItem2]; or for dictionnaries: MusicItem[string] musicDictionnary = [ "shortID1": MusicItem(foo, bar, baz, bak, biz, sub), "shortID2": MusicItem(foo, bar, baz, bak, biz, sub), ]; etc.
Jun 18 2018
On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote: Yes, this is what need, thank you very much for your help. :-)On Monday, 18 June 2018 at 11:44:43 UTC, Sunny wrote:[...]If I read you well it seems the simplest equivalent code would be: struct MusicItem { string URL; string Artist; string Title; string Cover; string Duration; } MusicItem[] musicList; You could technically use tuples to get to the same point but I don't really see a point, structs fit that purpose very well. Then you can: musicList ~= MusicItem(url, artist, title, cover, duration); musicList = [musicItem1, musicItem2]; or for dictionnaries: MusicItem[string] musicDictionnary = [ "shortID1": MusicItem(foo, bar, baz, bak, biz, sub), "shortID2": MusicItem(foo, bar, baz, bak, biz, sub), ]; etc.
Jun 18 2018
On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote:On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote: Yes, this is what need, thank you very much for your help. :-)I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/[...]
Jun 19 2018
On Tuesday, 19 June 2018 at 09:07:46 UTC, Cym13 wrote:On Tuesday, 19 June 2018 at 05:52:00 UTC, Sunny wrote:I read about D here - https://www.tutorialspoint.com/d_programming/index.htm figured it all out, but with a convenient implementation of the sheets there was a problem.On Monday, 18 June 2018 at 13:23:37 UTC, Cym13 wrote: Yes, this is what need, thank you very much for your help. :-)I recommend that you take the D tour if you can, it explains all those fundamental features quite well I think. https://tour.dlang.org/[...]
Jun 19 2018
On 06/19/2018 11:50 AM, Sunny wrote:I read about D here - https://www.tutorialspoint.com/d_programming/index.htmI'd advise against using that tutorial. Last time I looked at it, it seemed to be of low quality [1]. And the better parts seemed to be stolen from Ali Çehreli's "Programming in D", which is available for free, too: http://ddili.org/ders/d.en/ [1] https://forum.dlang.org/post/onstqa$255e$1 digitalmars.com
Jun 19 2018