Re: Is there a formula for overflow?

2022-11-29 Thread Salih Dincer via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:07:44 UTC, thebluepandabear wrote: I am curious as to what formula the D compiler uses for calculating 'overflowed' values, if such thing exists? :) Regards, thebluepandabear **Source:**

Re: Is there a formula for overflow?

2022-11-29 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:19:49 UTC, Basile B. wrote: writeln((30LU + 30LU) % uint.max); It's actually writeln((30LU + 30LU) % (uint.max.to!ulong + 1)); or writeln((30LU + 30LU) & uint.max);

Re: Is there a formula for overflow?

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:19:49 UTC, Basile B. wrote: [...] It's always a wraparound (think modulo) but your examples with negative number can be explained because there are hidden unsigned to signed implicit convertions. That the only special things D does. forgot to say, you

Re: Is there a formula for overflow?

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:07:44 UTC, thebluepandabear wrote: I am reading through Ali's book about D, and he gives the following examples for an overflow: ```D import std.stdio; void main() { // 3 billion each uint number_1 = 30; uint number_2 = 30; }

Is there a formula for overflow?

2022-11-29 Thread thebluepandabear via Digitalmars-d-learn
I am reading through Ali's book about D, and he gives the following examples for an overflow: ```D import std.stdio; void main() { // 3 billion each uint number_1 = 30; uint number_2 = 30; } writeln("maximum value of uint: ", uint.max); writeln(" number_1: ", number_1);

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to

Re: How do I _really_ implement opApply?

2022-11-29 Thread zjh via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 01:17:14 UTC, zjh wrote: Should there be an `intermediate layer` to simplify such function calls? There should be a `placeholder` similar to `inout` that can absorb all `attributes` of the parameter.

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 01:53:10 UTC, Siarhei Siamashka wrote: Rust also appears to be picky about the order of operations: ```Rust fn main() { let mut a = [1, 2, 3, 4, 5]; let c = a; let b = a; b[1] = 99; println!("{:?}", b); // [1, 99, 3, 4, 5]

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 00:40:57 UTC, Vladimir Panteleev wrote: On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array,

Re: How do I _really_ implement opApply?

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 01:30:03 UTC, Steven Schveighoffer wrote: On 11/29/22 7:50 PM, WebFreak001 wrote: (note: I don't want to use a template, this way of writing it has the advantage that the compiler checks all different code paths for errors, so the errors aren't delayed until

Re: How do I _really_ implement opApply?

2022-11-29 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/29/22 7:50 PM, WebFreak001 wrote: (note: I don't want to use a template, this way of writing it has the advantage that the compiler checks all different code paths for errors, so the errors aren't delayed until someone actually tries to iterate over my data structure) 1. use the

Re: How do I _really_ implement opApply?

2022-11-29 Thread zjh via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 00:50:46 UTC, WebFreak001 wrote: ... Should there be an `intermediate layer` to simplify such function calls?

Re: dirEntries removes entire branches of empty directories

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Thursday, 10 November 2022 at 21:27:28 UTC, Ali Çehreli wrote: However, ftw performs about twice as fast as dirEntries Yes, `dirEntries` isn't as fast as it could be. Here is a directory iterator which tries to strictly not do more work than what it must:

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Siarhei Siamashka via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 23:25:46 UTC, DLearner wrote: Many languages also have variable length arrays, I suggest D's 'dynamic array' _does not_ operate as expected. I'm not suggesting that the result contradicts D's definition of 'dynamic array', nor it's implementation, just that

Re: How do I _really_ implement opApply?

2022-11-29 Thread WebFreak001 via Digitalmars-d-learn
note: all of these functions are prefixed with `scope:`

How do I _really_ implement opApply?

2022-11-29 Thread WebFreak001 via Digitalmars-d-learn
it seems now when trying to cover scope semantics, @safe/@system and pure it already becomes quite unmanagable to implement opApply properly. Right now this is my solution: ```d private static enum opApplyImpl = q{ int result; foreach (string key, ref value; this.table) { result =

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 00:40:57 UTC, Vladimir Panteleev wrote: On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array,

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Vladimir Panteleev via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: Suggestion: it would be clearer if the two concepts were separated: 1. Convert 'int[] VarArr;' so it produces a straightforward _value-type_ variable array, called 'VarArr'; 2. Implement a new concept 'int slice Window;' to produce

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread matheus via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 23:25:46 UTC, DLearner wrote: On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ... I think this was discussed before a few weeks ago here (But I don't remember the thread), and this is a design

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread DLearner via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 19:06:20 UTC, rikki cattermole wrote: [...] Please see the following example: ``` void main() { import std.stdio; int[] VarArr1, VarArr2; VarArr1.length = 6; VarArr1[5] = 10; VarArr1[4] = 9; VarArr1[3] = 8; VarArr1[2] = 7; VarArr1[1] =

Re: __traits isCopyable vs isPOD

2022-11-29 Thread Per Nordlöw via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 00:50:54 UTC, Paul Backus wrote: If your goal is to avoid calling the copy constructor (and, I assume, to avoid unnecessary instantiations of `move`), then yeah, `isPOD` is the one you want. Thanks.

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread rikki cattermole via Digitalmars-d-learn
Okay you have misunderstand a lot here. We have two types of arrays: - Static, fixed sized stored on stack. - Dynamic, variable sized, stored on the heap. However dynamic arrays are not actually a distinct type in the type system, its a language extension to use runtime hooks using the GC.

Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread DLearner via Digitalmars-d-learn
To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to an array, through which that array can be manipulated. And

Re: Running GtkD programs on macOS

2022-11-29 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 07:17:09 UTC, Joel wrote: On Saturday, 30 November 2019 at 00:17:51 UTC, Mike Wey wrote: On 29-11-2019 04:40, Joel wrote: Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright?

Re: Running GtkD programs on macOS

2022-11-29 Thread Joel via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 07:17:09 UTC, Joel wrote: On Saturday, 30 November 2019 at 00:17:51 UTC, Mike Wey wrote: On 29-11-2019 04:40, Joel wrote: Oh, I used 'brew install gtk+3', and the test program worked, but (see below) I don't know about all that installing - is that alright?