Re: C-like static array size inference - how?

2022-06-07 Thread forkit via Digitalmars-d-learn
On Wednesday, 8 June 2022 at 01:32:42 UTC, Steven Schveighoffer wrote: I like `$`. It's got a well-defined meaning, and already is somewhat magic. -Steve I agree it's magic. warray[5..$] - this is one of the best uses of syntax magic in D! I think it's what first attracted me to the lang

Re: C-like static array size inference - how?

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 9:17 PM, forkit wrote: On Wednesday, 8 June 2022 at 01:11:45 UTC, Mike Parker wrote: ...The author withdrew the DIP .. That's a shame. Seems like a useful language feature. I'd be using it already if it existed. I agree, it's a pain to dig out an import and the verbose name

Re: C-like static array size inference - how?

2022-06-07 Thread forkit via Digitalmars-d-learn
On Wednesday, 8 June 2022 at 01:11:45 UTC, Mike Parker wrote: ...The author withdrew the DIP .. That's a shame. Seems like a useful language feature. I'd be using it already if it existed. I'd have gone for: int[..] arr = [1,2,3];

Re: Comparing Exceptions and Errors

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 3:58 PM, frame wrote: On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` This is hard to encap

Re: C-like static array size inference - how?

2022-06-07 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 8 June 2022 at 00:43:24 UTC, Ali Çehreli wrote: Do I remember correctly that there were syntax proposals that used $ or _? int[$] arr = [ 1, 2 ]; int[_] arr = [ 1, 2 ]; But I can't find past discussions about that. https://github.com/dlang/DIPs/blob/master/DIPs/other/DIP

Re: C-like static array size inference - how?

2022-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 6/7/22 16:38, arandomonlooker wrote: There is any chance size inference is going to be implemented into D as a feature? Do I remember correctly that there were syntax proposals that used $ or _? int[$] arr = [ 1, 2 ]; int[_] arr = [ 1, 2 ]; But I can't find past discussions about that

Re: C-like static array size inference - how?

2022-06-07 Thread arandomonlooker via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 00:20:31 UTC, Ali Çehreli wrote: On 6/6/22 17:04, arandomonlooker wrote: > [...] syntax causes > [...] As you already know, the correct syntax is 'int[]' :) but it won't work because -betterC cannot support dynamic array. [...] There is any chance size inference

Re: Comparing Exceptions and Errors

2022-06-07 Thread Ali Çehreli via Digitalmars-d-learn
On 6/7/22 12:58, frame wrote: > ```d > bool fun() { > scope(failure) { > // do something > return false; > } > > badCode(); > return true; > } > ``` > > I know this is bad as I'm capturing a possible error here - but this is > what an unexperienced code

Re: Comparing Exceptions and Errors

2022-06-07 Thread frame via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` This is hard to encapsulate into a type, as dtors onl

Re: Comparing Exceptions and Errors

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/7/22 12:28 PM, frame wrote: On Friday, 3 June 2022 at 23:40:50 UTC, Steven Schveighoffer wrote: During the last beerconf, I wrote a short blog post about how `Error` and `Exception` are different, and why you should never continue after catching `Error`s. I know the thematics but I still

Re: Comparing Exceptions and Errors

2022-06-07 Thread frame via Digitalmars-d-learn
On Friday, 3 June 2022 at 23:40:50 UTC, Steven Schveighoffer wrote: During the last beerconf, I wrote a short blog post about how `Error` and `Exception` are different, and why you should never continue after catching `Error`s. I know the thematics but I still wonder why we only have `scope(f

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread mw via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 13:56:23 UTC, Steven Schveighoffer wrote: So you are safe, it will see the pointer inside the array reference, and see that it doesn't point at GC memory, so nothing further will be done. Thanks for the detailed explanation, and everyone who has replied.

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/6/22 6:18 PM, mw wrote: Hi, Suppose I have this code: ``` class GCAllocated {   float[] data;   this() {     // non-gc-allocated field     this.data = cast(float[])(core.stdc.stdlib.malloc(nBytes)[0 .. nBytes]);   } } void foo() {   auto obj = new GCAllocated();  // gc-allocated

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread max haughton via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 09:12:25 UTC, ag0aep6g wrote: On 07.06.22 11:00, max haughton wrote: On Tuesday, 7 June 2022 at 08:56:29 UTC, ag0aep6g wrote: [...] That wasn't mw's question. I also answered this in my original one IIRC. You didn't. Ok I must have assumed it was obvious it wou

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.06.22 11:00, max haughton wrote: On Tuesday, 7 June 2022 at 08:56:29 UTC, ag0aep6g wrote: [...] That wasn't mw's question. I also answered this in my original one IIRC. You didn't.

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread max haughton via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 08:56:29 UTC, ag0aep6g wrote: On 07.06.22 03:02, max haughton wrote: I'm talking about the data in the array. void[] might contain pointers, float[] does not so it won't be scanned. That wasn't mw's question. I also answered this in my original one IIRC. There's

Re: want to confirm: gc will not free a non-gc-allocated field of a gc-allocated object?

2022-06-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.06.22 03:02, max haughton wrote: I'm talking about the data in the array. void[] might contain pointers, float[] does not so it won't be scanned. That wasn't mw's question.

Re: C-like static array size inference - how?

2022-06-07 Thread Dennis via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 00:20:31 UTC, Ali Çehreli wrote: > it's complaining about TypeInfo being absent. What an unfortunate error message! Trying writeln() causes equally weird error messages. Walter just improved it! https://github.com/dlang/dmd/pull/14181 Perhaps try a [nightly build]