Re: AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: Success! So i summarize, either work with a pointer, or drop the const... Of course casting the const away was the first thing I did but I think this is not very clean :D

Re: AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 06:38:03 UTC, Tejas wrote: On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: [...] const/immutable members are to be set/assigned instantiation. Most likely the problem is a bug and sou

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:38:03 UTC, Era Scarecrow wrote: Well to add functionality with say ANSI you entered an escape code and then stuff like offset, color, effect, etc. UTF-8 automatically has escape codes being anything 128 or over, so as long as the terminal understand it, it sho

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:47:51 UTC, Kagamin wrote: https://utf8everywhere.org/ - this is an advise from a windows programmer, I use it too. Windows allocates a per thread buffer and when you call, say, WriteConsoleA, it first transcodes the string to UTF-16 in the buffer and calls Writ

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:30:55 UTC, Adam D Ruppe wrote: Most unix things do utf-8 more often than not, but technically you are supposed to check the locale and change the terminal settings to do it right. Cool! I mean, I don't plan on supporting legacy systems so I think we're fine i

Re: How to print unicode characters (no library)?

2021-12-27 Thread ag0aep6g via Digitalmars-d-learn
On 27.12.21 15:23, Adam D Ruppe wrote: Let's look at: "Hello 😂\n"; [...] Finally, there's "string", which is utf-8, meaning each element is 8 bits, but again, there is a buffer you need to build up to get the code points you feed into that VM. [...] H, e, l, l, o, , MORE elements>, , , fina

Re: AA and struct with const member

2021-12-27 Thread Tejas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 01:45:42 UTC, Era Scarecrow wrote: On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: [...] const/immutable members are to be set/assigned instantiation. Most likely the problem is a bug and sounds like [...] The workaround is okay, but I think we sh

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:23:37 UTC, Adam D Ruppe wrote: [...] After reading the whole things, I said it and I'll say it again! You guys must get paid for your support I also helped a guy in another forum yesterday writing a very big reply and tbh it felt great :P (or of course

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:57:27 UTC, Paul Backus wrote: ```d enum instantiate(string type, string expr) = type ~ "(" ~ expr ~ ")"; pragma(msg, instantiate!("RVector!(SEXPTYPE.REALSXP)", "x")); ``` One possibility is to generate a collection of compile time strings that denote the

Re: AA and struct with const member

2021-12-27 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 27 December 2021 at 19:38:38 UTC, frame wrote: I feel stupid right now: One cannot assign a struct that contains const member to AA? Error: cannot modify struct instance ... of type ... because it contains `const` or `immutable` members This is considered a modification? ```d stru

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:42:18 UTC, data pulverizer wrote: On Tuesday, 28 December 2021 at 00:32:03 UTC, Paul Backus wrote: In this case, the simplest solution is to have your code generator accept a string as its input, rather than a type. For example: ```d enum instantiate(string

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:32:03 UTC, Paul Backus wrote: The result of `.stringof` is completely implementation-defined, may change arbitrarily between compiler releases, and is not even guaranteed to be valid D code in the first place. Wow, I didn't know this. In this case, the simpl

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Adam Ruppe via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:13:13 UTC, data pulverizer wrote: There are various requirements, sometimes I have to cast or type convert, so I **need** the type to paste correctly and explicitly. You almost never actually need types as strings. I'm almost certain there's a better way for

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 00:13:13 UTC, data pulverizer wrote: The types I'm generating are a template type I've constructed for R's SEXP, so that my wrapped numeric vector (struct) type is denoted `RVector!(REALSXP)`. But `alias REALSXP = SEXPTYPE.REALSXP` where `SEXPTYPE` is an `enum`.

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 December 2021 at 23:04:40 UTC, Adam Ruppe wrote: On Monday, 27 December 2021 at 21:21:30 UTC, data pulverizer wrote: alias T = MyType!(INTEGER); What is MyType? enum code = "writeln(\"instance: \", adder(" ~ T.stringof ~ "(), " ~ U.stringof ~ "()" ~ "));"; A

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Adam Ruppe via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:21:30 UTC, data pulverizer wrote: alias T = MyType!(INTEGER); What is MyType? enum code = "writeln(\"instance: \", adder(" ~ T.stringof ~ "(), " ~ U.stringof ~ "()" ~ "));"; And why is this a string mixin instead of a plain simple function

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 December 2021 at 22:52:58 UTC, data pulverizer wrote: I think the only thing to do for now is probably for me to construct a template that creates a proper string for this type. It would look something like this: ``` enum safe_stringof(T) = T.stringof; template safe_stringof(T: M

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:31:03 UTC, Adam Ruppe wrote: if you can paste teh code where you generate this I can prolly show you a much easier way to do it. stringof sucks really hard. I think the only thing to do for now is probably for me to construct a template that creates a proper s

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:31:03 UTC, Adam Ruppe wrote: if you can paste teh code where you generate this I can prolly show you a much easier way to do it. stringof sucks really hard. Will the above `mixin` example suffice? It expands to the code that I described.

Re: How to print unicode characters (no library)?

2021-12-27 Thread Era Scarecrow via Digitalmars-d-learn
On Monday, 27 December 2021 at 07:12:24 UTC, rempas wrote: On Sunday, 26 December 2021 at 21:22:42 UTC, Adam Ruppe wrote: write just transfers a sequence of bytes. It doesn't know nor care what they represent - that's for the receiving end to figure out. Oh, so it was as I expected :P Wel

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread Adam Ruppe via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:05:51 UTC, data pulverizer wrote: adder(MyType!MyEnum.INTEGER(), MyType!MyEnum.STRING()); The rule for !(args) is of you leave the parenthesis off, it only uses the next single token as the argument. So it will never include a dot; it is like you wrote `MyTyp

Re: Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:05:51 UTC, data pulverizer wrote: Hello, ... ... an equivalent mixin error would be ``` //... alias DOUBLE = MyEnum.DOUBLE; alias STRING = MyEnum.STRING; alias INTEGER = MyEnum.INTEGER; void main() { alias T = MyType!(INTEGER); alias U = MyType!(STRING)

Ambiguity issue with expanding and evaluating single template type parameter enums

2021-12-27 Thread data pulverizer via Digitalmars-d-learn
Hello, I'm generating code using mixins and one of my mixins expands to something like this: ``` adder(MyType!MyEnum.INTEGER(), MyType!MyEnum.STRING()); ``` `MyType!MyEnum.STRING` is generated with `T.stringof `. I get the error: ``` Error: template instance `MyType!(MyEnum)` does not matc

AA and struct with const member

2021-12-27 Thread frame via Digitalmars-d-learn
I feel stupid right now: One cannot assign a struct that contains const member to AA? Error: cannot modify struct instance ... of type ... because it contains `const` or `immutable` members This is considered a modification? ```d struct S { const(int) a; } S[string] test; test["a"] = S(1);

Re: How to print unicode characters (no library)?

2021-12-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 27, 2021 at 04:40:19PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Monday, 27 December 2021 at 15:26:16 UTC, H. S. Teoh wrote: > > A lot of modern Linux applications don't even work properly under > > anything non-UTF-8 > > yeah, you're supposed to check the locale but sin

Re: How to print unicode characters (no library)?

2021-12-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 27 December 2021 at 15:26:16 UTC, H. S. Teoh wrote: A lot of modern Linux applications don't even work properly under anything non-UTF-8 yeah, you're supposed to check the locale but since so many people just assume that's becoming the new de facto reality just like how people bli

Re: How to print unicode characters (no library)?

2021-12-27 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Dec 27, 2021 at 02:30:55PM +, Adam D Ruppe via Digitalmars-d-learn wrote: > On Monday, 27 December 2021 at 11:21:54 UTC, rempas wrote: > > So should I just use UTF-8 only for Linux? > > Most unix things do utf-8 more often than not, but technically you are > supposed to check the loca

Re: How to print unicode characters (no library)?

2021-12-27 Thread Kagamin via Digitalmars-d-learn
On Monday, 27 December 2021 at 11:21:54 UTC, rempas wrote: So should I just use UTF-8 only for Linux? What about other operating systems? I suppose Unix-based OSs (maybe MacOS as well if I'm lucky) work the same as well. But what about Windows? Unfortunately I have to support this OS too with m

Re: How to print unicode characters (no library)?

2021-12-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 27 December 2021 at 11:21:54 UTC, rempas wrote: So should I just use UTF-8 only for Linux? Most unix things do utf-8 more often than not, but technically you are supposed to check the locale and change the terminal settings to do it right. But what about Windows? You should AL

Re: How to print unicode characters (no library)?

2021-12-27 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 27 December 2021 at 07:12:24 UTC, rempas wrote: Oh yeah. About that, I wasn't given a demonstration of how it works so I forgot about it. I saw that in Unicode you can combine some code points to get different results but I never saw how that happens in practice. The emoji is one e

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 09:29:38 UTC, Kagamin wrote: D strings are plain arrays without any text-specific logic, the element is called code unit, which has a fixed size, and the array length specifies how many elements are in the array. This model is most adequate for memory correctness,

Re: Starting and managing threads

2021-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/21 1:33 AM, Bagomot wrote: > separate thread, without blocking the main one. I think you can use std.concurrency there. I have a chapter here: http://ddili.org/ders/d.en/concurrency.html Look for 'struct Exit' to see how the main thread signals workers to stop running. And some s

Re: How to print unicode characters (no library)?

2021-12-27 Thread Kagamin via Digitalmars-d-learn
On Monday, 27 December 2021 at 07:29:05 UTC, rempas wrote: How can you do that? I'm trying to print the codes for them but it doesn't work. Or you cannot choose to have this behavior and there are only some terminals that support this? Try it on https://en.wikipedia.org/wiki/Teletype_Model_33

Starting and managing threads

2021-12-27 Thread Bagomot via Digitalmars-d-learn
Hello everybody! My program uses the fswatch library to track changes in a directory. It runs on the main thread of the program. I need it to do its work in a separate thread, without blocking the main one. In addition, I need to be able to terminate the thread at the moment I want from the m

Re: How to print unicode characters (no library)?

2021-12-27 Thread Kagamin via Digitalmars-d-learn
D strings are plain arrays without any text-specific logic, the element is called code unit, which has a fixed size, and the array length specifies how many elements are in the array. This model is most adequate for memory correctness, i.e. it shows what takes how much memory and where it will