Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/21 9:17 PM, jfondren wrote: On Friday, 15 October 2021 at 03:54:17 UTC, Ali Çehreli wrote: On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: Very nice,

Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread jfondren via Digitalmars-d-learn
On Friday, 15 October 2021 at 03:54:17 UTC, Ali Çehreli wrote: On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: Very nice, replacing Thread.sleep with receiveTimeout and

Re: Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/14/21 8:35 PM, jfondren wrote: The book, "The Go Programming Language" has this simple goroutine example: Here is one that uses receiveTimeout and OwnerTerminated: import std.stdio; import std.concurrency; import core.thread; void main() { spawnLinked(, 100.msecs); enum n = 45;

Threading challenge: calculate fib(45) while spinning

2021-10-14 Thread jfondren via Digitalmars-d-learn
The book, "The Go Programming Language" has this simple goroutine example: ```go func main() { go spinner(100 * time.Millisecond) const n = 45 fibN := fib(n) // slow fmt.Printf("\rFibonacci(%d) = %d\n", n, fibN) } func spinner(delay time.Duration) { for { for _, r

Re: Structured binding declaration (like in C++)

2021-10-14 Thread Vindex via Digitalmars-d-learn
On Thursday, 14 October 2021 at 15:29:13 UTC, MoonlightSentinel wrote: On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote: Is there a decomposition for tuples and other data structures? No, but you can emulate it, e.g. by using AliasSeq: ```d import std.meta : AliasSeq; import

Re: Parameter forwarding

2021-10-14 Thread Tejas via Digitalmars-d-learn
On Thursday, 14 October 2021 at 17:37:21 UTC, Paul Backus wrote: On Thursday, 14 October 2021 at 16:53:17 UTC, Kostiantyn Tokar wrote: [...] Poor test coverage. If you go through Phobos and test everything with a non-copyable struct (`@disable this(this)`), you will find that most templates

Re: Parameter forwarding

2021-10-14 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 14 October 2021 at 16:53:17 UTC, Kostiantyn Tokar wrote: Take a look at `Tuple` [constructor](https://github.com/dlang/phobos/blob/4130a1176cdb6111b0c26c7c53702e10011ff067/std/typecons.d#L672). ```d this(Types values) { field[] = values[]; } ``` Actual fields are constructed

Parameter forwarding

2021-10-14 Thread Kostiantyn Tokar via Digitalmars-d-learn
Hello. I'm concerned about D's move semantics and how Phobos supports it. For example, `std.typecons.Tuple`. ```d struct A { int i; this(this) { writeln("Expensive copy"); } } void main() { auto t = Tuple!(A)(A(42)); } ``` This code produces 1 unnecessary copy. Argument is an

Re: Structured binding declaration (like in C++)

2021-10-14 Thread MoonlightSentinel via Digitalmars-d-learn
On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote: Is there a decomposition for tuples and other data structures? No, but you can emulate it, e.g. by using AliasSeq: ```d import std.meta : AliasSeq; import std.typecons : tuple; import std.stdio : writeln; void main() { int a;

Re: How to check if value is null, today?

2021-10-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/14/21 7:58 AM, tastyminerals wrote: The new `DMD v2.097.2` deprecated implicit null conversions `std.typecons.Nullable!double.Nullable.get_`. The deprecation warning tell you to `Please use .get explicitly.`. Here is an example code that doesn't work with the new compiler anymore: ```

Re: Structured binding declaration (like in C++)

2021-10-14 Thread Ali Çehreli via Digitalmars-d-learn
On 10/13/21 1:02 PM, Vindex wrote: Is there a decomposition for tuples and other data structures? For example, ``` auto t = tuple(1, "2"); auto (x, y) = t; // or auto (x, y) = t.expand; ``` No, D does not have this (yet?). I thought there was a special case for tuples with foreach but I

Re: How to check if value is null, today?

2021-10-14 Thread jfondren via Digitalmars-d-learn
On Thursday, 14 October 2021 at 11:58:29 UTC, tastyminerals wrote: Here is an example code that doesn't work with the new compiler anymore: ``` if (someValue.isNull) ``` Attempting to run the above throws: ``` Error: incompatible types for `(0) : (someValue)`: `int` and `Nullable!int` ```

How to check if value is null, today?

2021-10-14 Thread tastyminerals via Digitalmars-d-learn
The new `DMD v2.097.2` deprecated implicit null conversions `std.typecons.Nullable!double.Nullable.get_`. The deprecation warning tell you to `Please use .get explicitly.`. Here is an example code that doesn't work with the new compiler anymore: ``` if (someValue.isNull) ``` Attempting to

Re: __traits(compiles) is true with warnings as errors

2021-10-14 Thread bauss via Digitalmars-d-learn
On Thursday, 14 October 2021 at 05:41:01 UTC, Tejas wrote: On Wednesday, 13 October 2021 at 17:58:23 UTC, Jonathan Levi wrote: When dmd is passed the "-w" tag, it "treats warnings as errors" but not with the "__traits(compiles)" expression. Is this the intended action? This code should