Re: Actual lifetime of static array slices?

2022-11-16 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 15 November 2022 at 14:05:42 UTC, Siarhei Siamashka wrote: On Tuesday, 15 November 2022 at 13:16:18 UTC, Paul Backus wrote: D's safety model is the same. In `@safe` code, D will reject anything that the compiler cannot say for sure is memory safe. However, unlike in Rust, `@safe`

Can we ease WASM in D ?

2022-11-16 Thread bioinfornatics via Digitalmars-d-learn
Dear community, I look some day ago to the D wasm page: -> https://wiki.dlang.org/Generating_WebAssembly_with_LDC And since then I ask myself can we at compile time convert a D code to an extern C code for wasm ? Indeed, if a library/framework would wrap this to let end user write his

Re: Can we ease WASM in D ?

2022-11-16 Thread max haughton via Digitalmars-d-learn
On Wednesday, 16 November 2022 at 23:00:40 UTC, Adam D Ruppe wrote: On Wednesday, 16 November 2022 at 22:51:31 UTC, bioinfornatics wrote: [...] It would be pretty cool if you could just mark `@wasm` on a function and have it magically convert... the dcompute thing i *think* does something

Re: Can we ease WASM in D ?

2022-11-16 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 16, 2022 at 10:51:31PM +, bioinfornatics via Digitalmars-d-learn wrote: > Dear community, > > I look some day ago to the D wasm page: > -> https://wiki.dlang.org/Generating_WebAssembly_with_LDC > > And since then I ask myself can we at compile time convert a D code > to an

Re: Can we ease WASM in D ?

2022-11-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 16 November 2022 at 23:16:26 UTC, H. S. Teoh wrote: You mean with Phobos and everything included? I think there may be issues with that... Yes, this is a problem, but I think I have a solution: defer GC runs until javascript is running. There's also some llvm features that

Re: Can we ease WASM in D ?

2022-11-16 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 16 November 2022 at 22:51:31 UTC, bioinfornatics wrote: And since then I ask myself can we at compile time convert a D code to an extern C code for wasm ? It would be pretty cool if you could just mark `@wasm` on a function and have it magically convert... the dcompute thing i

Re: Can we ease WASM in D ?

2022-11-16 Thread bioinfornatics via Digitalmars-d-learn
Thanks Adam, H. S., max for your point of view On Wednesday, 16 November 2022 at 23:23:48 UTC, Adam D Ruppe wrote: On Wednesday, 16 November 2022 at 23:16:26 UTC, H. S. Teoh wrote: You mean with Phobos and everything included? I think there may be issues with that... Yes that would be

How do you return a subclass instance from a base class method?

2022-11-16 Thread Daniel via Digitalmars-d-learn
I have SubclassOf derived from PosetRelation. For any poset relation, the transitivity law applies, however, I'd like to return the correct type: ``` PosetRelation transitivity(PosetRelation R, PosetRelation S) { if (R.op == S.op) { if (R.right is S.left)

Re: How do you return a subclass instance from a base class method?

2022-11-16 Thread Daniel via Digitalmars-d-learn
``` PosetRelation transitivity(PosetRelation R, PosetRelation S) { // These if conditions are typically ordered from easiest to // most involved-to-check. if (R.op == S.op && is(typeof(R) == typeof(S)) && R.right == S.left) { return new typeof(R)( R.left,

Is defining get/set methods for every field overkill?

2022-11-16 Thread thebluepandabear via Digitalmars-d-learn
I am creating a TUI library and I have a class with the following constant fields: ``` class Label : Renderable { const string text; const TextAlignment textAlignment; const Color color; this(Dimensions dimensions, string text, TextAlignment textAlignment, Color color) {

Re: How do you return a subclass instance from a base class method?

2022-11-16 Thread MorteFeuille123 via Digitalmars-d-learn
On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: I have SubclassOf derived from PosetRelation. For any poset relation, the transitivity law applies, however, I'd like to return the correct type: How does one accomplish this in D? Because PosetRelation doesn't

Re: How do you return a subclass instance from a base class method?

2022-11-16 Thread zjh via Digitalmars-d-learn
On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: ... `crtp`, will it work?

Re: Is defining get/set methods for every field overkill?

2022-11-16 Thread rikki cattermole via Digitalmars-d-learn
I wouldn't bother. They are const, they can't change. Nothing to protect, nothing to synchronize.

Re: How do you return a subclass instance from a base class method?

2022-11-16 Thread Daniel via Digitalmars-d-learn
On Thursday, 17 November 2022 at 05:21:05 UTC, MorteFeuille123 wrote: On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: [...] You can use TypeInfoClass: [...] I don't get it - you never made use of b1 or b2...

Re: How do you return a subclass instance from a base class method?

2022-11-16 Thread Daniel via Digitalmars-d-learn
On Thursday, 17 November 2022 at 05:34:49 UTC, zjh wrote: On Thursday, 17 November 2022 at 04:25:13 UTC, Daniel Donnelly, Jr. wrote: ... `crtp`, will it work? Can't use CRTP, because once you choose a derived class to pass into the template system, how do you pass in subclasses of that

Re: Is defining get/set methods for every field overkill?

2022-11-16 Thread Ali Çehreli via Digitalmars-d-learn
On 11/16/22 20:39, thebluepandabear wrote: > I am debating whether or not I should add getter methods to these > properties. If you are debating, then the answer is easy: you should not. :) Less code written means less bugs, more cohesion, easier refactoring, cleaner code, all good stuff...