Re: D equivalent to Rust or Scala's Optional and Result and best practice ?

2021-10-18 Thread dangbinghoo via Digitalmars-d-learn
On Tuesday, 19 October 2021 at 00:01:47 UTC, James Blachly wrote: On 10/18/21 12:03 PM, dangbinghoo wrote: [...] Not quite the same as tagged algebraic union ("sum type" == Rust enum) are not (yet?) a language feature. That being said, I recently integrated mir's Algebraic and Nullable int

Re: D equivalent to Rust or Scala's Optional and Result and best practice ?

2021-10-18 Thread Soulsbane via Digitalmars-d-learn
On Monday, 18 October 2021 at 16:03:53 UTC, dangbinghoo wrote: hi, It seems that now we have `Optional` and `Result` packages in Dub, are these enough or fully equal to Rust or Scala's error-handling and pattern-matching? if these are enough for real-code, any best practice advice? thanks!

Re: D equivalent to Rust or Scala's Optional and Result and best practice ?

2021-10-18 Thread James Blachly via Digitalmars-d-learn
On 10/18/21 12:03 PM, dangbinghoo wrote: hi, It seems that now we have `Optional` and `Result` packages in Dub, are these enough or fully equal to Rust or Scala's error-handling and pattern-matching? if these are enough for real-code, any best practice advice? thanks! Not quite the same

Re: Question re specific implicit type coercion

2021-10-18 Thread Don Allen via Digitalmars-d-learn
On Monday, 18 October 2021 at 15:58:35 UTC, Don Allen wrote: On Monday, 18 October 2021 at 15:34:45 UTC, Paul Backus wrote: On Monday, 18 October 2021 at 15:04:11 UTC, Don Allen wrote: Section 12.17 of the Language Reference does not indicate any circumstance in which a dynamic array, which the

D equivalent to Rust or Scala's Optional and Result and best practice ?

2021-10-18 Thread dangbinghoo via Digitalmars-d-learn
hi, It seems that now we have `Optional` and `Result` packages in Dub, are these enough or fully equal to Rust or Scala's error-handling and pattern-matching? if these are enough for real-code, any best practice advice? thanks!

Re: Question re specific implicit type coercion

2021-10-18 Thread Don Allen via Digitalmars-d-learn
On Monday, 18 October 2021 at 15:34:45 UTC, Paul Backus wrote: On Monday, 18 October 2021 at 15:04:11 UTC, Don Allen wrote: Section 12.17 of the Language Reference does not indicate any circumstance in which a dynamic array, which the literal is, is implicitly coerced to a pointer. This is a

Re: Question re specific implicit type coercion

2021-10-18 Thread Paul Backus via Digitalmars-d-learn
On Monday, 18 October 2021 at 15:04:11 UTC, Don Allen wrote: Section 12.17 of the Language Reference does not indicate any circumstance in which a dynamic array, which the literal is, is implicitly coerced to a pointer. This is a special case for string literals, covered in [section 10.23.7][

Question re specific implicit type coercion

2021-10-18 Thread Don Allen via Digitalmars-d-learn
I am calling a C function, described in D as extern (C) GtkWidget* gtk_menu_item_new_with_label (immutable(char)*); I call it like this accounts_menu_item = gtk_menu_item_new_with_label("New account (Ctrl-n)"); The type of the string literal in the call is immutable(char)[]. The type of t

Re: Why is opIndexAssign replaced by opSlice here?

2021-10-18 Thread Elmar via Digitalmars-d-learn
On Monday, 18 October 2021 at 03:42:35 UTC, Paul Backus wrote: What happens here is, the compiler first tries the D2-style rewrite: ```d s.opIndexAssign(arr[1..4], s.opSlice!0(0, 3)) ``` However, that rewrite fails to compile, because your `opSlice` does not take a template argument specifyin

Re: How can we allow using phobos with asserts/contracts?

2021-10-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/18/21 8:35 AM, user1234 wrote: On Sunday, 17 October 2021 at 21:00:19 UTC, Steven Schveighoffer wrote: On 10/16/21 6:47 PM, solidstate1991 wrote: When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access violation error. The debugger out is di

Re: How can we allow using phobos with asserts/contracts?

2021-10-18 Thread user1234 via Digitalmars-d-learn
On Sunday, 17 October 2021 at 21:00:19 UTC, Steven Schveighoffer wrote: On 10/16/21 6:47 PM, solidstate1991 wrote: When I make this call ``` format(" %3.3f"w, avgFPS); ``` my program immediately crashes with an access violation error. The debugger out is different between x86 and x86-64. I've