How to efficiently resolve Associative Arrays not being sorted?

2020-06-02 Thread BoQsc via Digitalmars-d-learn
I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? What are the ways to resolve this randomness in Associat

Re: How to efficiently resolve Associative Arrays not being sorted?

2020-06-02 Thread Luis via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 07:32:56 UTC, BoQsc wrote: I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? W

Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
Hello, I have a 2 level nested struct structure with nice descriptive field names. And I thought it will be easy to alias those identifierLists with a few letter names and do some calculations on them. But I'm having an error. struct A{ struct B{ int c; } B b; auto f(){ alias d = b

Re: How to efficiently resolve Associative Arrays not being sorted?

2020-06-02 Thread Ali Çehreli via Digitalmars-d-learn
On 6/2/20 12:32 AM, BoQsc wrote: > I want to read a file, put it into an array, make some search and > replace on the content and output the modified text. How large is the data? If it fits into memory, just read the whole thing, update it, sort the keys, and then output like this: import s

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 08:56:13 UTC, realhet wrote: Hello, I have a 2 level nested struct structure with nice descriptive field names. And I thought it will be easy to alias those identifierLists with a few letter names and do some calculations on them. But I'm having an error. struct A{

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:07:08 UTC, Basile B. wrote: On Tuesday, 2 June 2020 at 08:56:13 UTC, realhet wrote: [...] There's a language rule, expressions cant be aliased, however D has a bug, some expressions that look like type can be aliased, then when you use them you have an error abo

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Ali Çehreli via Digitalmars-d-learn
On 6/2/20 1:56 AM, realhet wrote: > struct A{ >struct B{ int c; } >B b; > >auto f(){ > alias d = b.c; The spec explicitly says it's not legal: "Aliases cannot be used for expressions" (Item 10): https://dlang.org/spec/declaration.html#alias I use nested functions for such

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: > struct A{ >struct B{ int c; } >B b; > >auto f(){ > alias d = b.c; The spec explicitly says it's not legal: "Aliases cannot be used for expressions" (Item 10): https://dlang.org/

Re: Postblit segfault.

2020-06-02 Thread MaoKo via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:53:47 UTC, Basile B. wrote: Ok cool. I hesitate to report an issue because the bug was too "simple". This is a proof that dmd user use the GC a lot :). Mmmmh I don't follow you, this has nothing to do with the GC. It's rather a problem with the backend (i.e the

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: On Tuesday, 2 June 2020 at 09:10:03 UTC, Ali Çehreli wrote: On 6/2/20 1:56 AM, realhet wrote: Oh and I can put that function generator mixin thing into a template as well, that way it is reusable and much nicer. There are a lot of poss

Is this a good tree?

2020-06-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
Hello. I want to create a tree which maps sequences of numbers to data. ex: - [1, 2]-> 1 - [1, 3, 1] -> 2 - [1, 3, 2] -> 3 I have no prior knowledge of what makes a good tree, and I am unsure if what I've got is good. I mean it works, but if anyone with more knowledge of trees or D-lang

Re: Is this a good tree?

2020-06-02 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 11:44:10 UTC, Vladimirs Nordholm wrote: Hello. I want to create a tree which maps sequences of numbers to data. ex: - [1, 2]-> 1 - [1, 3, 1] -> 2 - [1, 3, 2] -> 3 I have no prior knowledge of what makes a good tree, and I am unsure if what I've got is good. I m

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: static foreach(k, v; fieldMap){ mixin("@property auto $() const{ return #; }".replace("$", k).replace("#", v)); } //I know, i know -> AliasSeq :D You can use std.format.format to do it in one function call: mixin("@property auto

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Stanislav Blinov via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: I did it that way: private enum fieldMap = [ // simple names for descriptive and structured fields "hauteur" : "general.height", "rayon" : "profile.radius", "plage" : "profile.plage", "offsetv"

Re: What's the best way to find out which exceptions may be thrown ?

2020-06-02 Thread Bienlein via Digitalmars-d-learn
On Wednesday, 27 May 2020 at 11:40:00 UTC, Mike Parker wrote: On Wednesday, 27 May 2020 at 10:30:36 UTC, wjoe wrote: On Wednesday, 27 May 2020 at 10:01:33 UTC, Mike Parker wrote: Could you please elaborate why checked exceptions are more annoying? For me, it's because they require all funct

Re: I want Sublime 3 D auto import !

2020-06-02 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport Great! You should make a post about it in th

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: mixin("@property auto ", k, "() const { return ", v, "; }"); Wow, string mixin can process comma separated list, I gotta remember this, thanks!

Re: Is this a good tree?

2020-06-02 Thread Vladimirs Nordholm via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 12:34:53 UTC, Q. Schroll wrote: On Tuesday, 2 June 2020 at 11:44:10 UTC, Vladimirs Nordholm wrote: [...] You might want to check out this: https://en.wikipedia.org/wiki/Trie Possibly, that's exactly what you're looking for. Thank you! I believe this is exactly

Re: Making alias of a struct field needs "this".

2020-06-02 Thread realhet via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 13:37:25 UTC, Stanislav Blinov wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote: Try UDAs instead of a map: struct A { struct G { @("hauteur") int height; } Good idea, thx! I already using UDA's for range and measurement units. struc

Re: I want Sublime 3 D auto import !

2020-06-02 Thread welkam via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport Cool. I dont use classe but I see how this k

Re: I want Sublime 3 D auto import !

2020-06-02 Thread bauss via Digitalmars-d-learn
On Tuesday, 2 June 2020 at 06:00:10 UTC, Виталий Фадеев wrote: On Monday, 1 June 2020 at 18:55:03 UTC, Paul Backus wrote: On Monday, 1 June 2020 at 16:18:44 UTC, Виталий Фадеев wrote: I do it! https://github.com/vitalfadeev/SublimeDlangAutoImport What happens if you have the same symbol in

Re: Making alias of a struct field needs "this".

2020-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/20 10:51 AM, realhet wrote: On Tuesday, 2 June 2020 at 13:10:55 UTC, Paul Backus wrote: On Tuesday, 2 June 2020 at 09:28:01 UTC, realhet wrote:     mixin("@property auto ", k, "() const { return ", v, "; }"); Wow, string mixin can process comma separated list, I gotta remember this, th

Re: How to efficiently resolve Associative Arrays not being sorted?

2020-06-02 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/2/20 3:32 AM, BoQsc wrote: I want to read a file, put it into an array, make some search and replace on the content and output the modified text. However Associative Arrays seem to be unsorted by default. Should I drop the Associative Arrays and use something else? What are the ways to res