Re: How come a count of a range becomes 0 before a foreach?
On 4/10/23 6:43 PM, ikelaiah wrote: On Monday, 10 April 2023 at 01:01:59 UTC, Steven Schveighoffer wrote: On 4/9/23 9:16 AM, Ali Çehreli wrote: auto entries = dirEntries(/* ... */).array; I'd be cautious of that. I don't know what the underlying code uses, it may reuse buffers for e.g. filenames to avoid allocation. If you are confident the directory contents won't change in that split-second, then I think iterating twice is fine. Steve, The Rmd files are not on a network drive, but saved locally. So, I'm confident, the files won't change in a split-second. That is not what I meant. What I mean is that `array` is going to copy whatever values the range gives it, which might be later *overwritten* depending on how `dirEntries` is implemented. e.g. the following code is broken: ```d auto lines = File("foo.txt").byLine.array; ``` But the following is correct: ``` auto lines = File("foo.txt").byLineCopy.array; ``` Why? Because `byLine` reuses the line buffer eventually to save on allocations. The array of lines might contain garbage in the earlier elements as they got overwritten. I'm not saying it's wrong for `dirEntries`, I haven't looked. But you may want to be cautious about just using `array` to get you out of trouble, especially for lazy input ranges. -Steve
Re: How come a count of a range becomes 0 before a foreach?
On Monday, 10 April 2023 at 01:01:59 UTC, Steven Schveighoffer wrote: On 4/9/23 9:16 AM, Ali Çehreli wrote: On 4/8/23 21:38, ikelaiah wrote: > I will modify the code to construct it twice. Multiple iterations of dirEntries can produce different results, which may or may not be what your program will be happy with. Sticking an .array at the end will iterate a single time and maintain the list forever because .array returns an array. :) auto entries = dirEntries(/* ... */).array; I'd be cautious of that. I don't know what the underlying code uses, it may reuse buffers for e.g. filenames to avoid allocation. If you are confident the directory contents won't change in that split-second, then I think iterating twice is fine. -Steve Steve, The Rmd files are not on a network drive, but saved locally. So, I'm confident, the files won't change in a split-second. -ikelaiah.
Re: How come a count of a range becomes 0 before a foreach?
On Sunday, 9 April 2023 at 13:16:51 UTC, Ali Çehreli wrote: On 4/8/23 21:38, ikelaiah wrote: > I will modify the code to construct it twice. Multiple iterations of dirEntries can produce different results, which may or may not be what your program will be happy with. Sticking an .array at the end will iterate a single time and maintain the list forever because .array returns an array. :) auto entries = dirEntries(/* ... */).array; Ali Ali, I didn't think about returning `dirEntries` as `array`. Thanks for the Gems (and your online book too). Regards, ikelaiah
Re: mutable pointers as associative array keys
On 4/10/23 4:25 PM, Steven Schveighoffer wrote: It's also completely useless. Having const keys does nothing to guarantee unchanging keys. Another half-assed attempt to be encode correct semantics but fails completely in its goal. In case you wonder how old this is: https://issues.dlang.org/show_bug.cgi?id=11477 https://issues.dlang.org/show_bug.cgi?id=12491#c2 -Steve
Re: mutable pointers as associative array keys
On 4/10/23 2:14 PM, John Colvin wrote: It seems that it isn't possible, am I missing something? alias Q = int[int*]; pragma(msg, Q); // int[const(int)*] Yep, it's been that way forever. Only with pointers and arrays. It's fine with mutable classes and structs (even if they contain pointers). Also, is this documented somewhere? No. It's also completely useless. Having const keys does nothing to guarantee unchanging keys. Another half-assed attempt to be encode correct semantics but fails completely in its goal. -Steve
Re: DlangUI Layout Justification
On Friday, 7 April 2023 at 17:13:58 UTC, Adam D Ruppe wrote: On Friday, 7 April 2023 at 15:52:02 UTC, Ali Çehreli wrote: I don't know how relevant it is but there is also Hipreme Engine that supports Android: [...] One library can help with both games and guis but it is unlikely to be a complete solution for either, certainly not both. Wow, what a great comparison, Adam! I've worked on GUIs, but never on games... and often wondered about this. Maybe you can copy+paste the whole thing as a topic on your blog ...? This comparison deserves *not* to fade into oblivion as is the typical fate of most forum discussions.
Re: mutable pointers as associative array keys
On Monday, 10 April 2023 at 18:14:56 UTC, John Colvin wrote: It seems that it isn't possible, am I missing something? alias Q = int[int*]; pragma(msg, Q); // int[const(int)*] Also, is this documented somewhere? It seems to be so (which is strange) and I can't image it is by design since you can do this: ```d static struct Pointer(T) { T* val; } int[Pointer!int] f; pragma(msg,typeof(f)); int* val = new int; *val = 5; f[Pointer!int(val)] = 12; *val = 6; f[Pointer!int(val)].writeln; //12 ```
mutable pointers as associative array keys
It seems that it isn't possible, am I missing something? alias Q = int[int*]; pragma(msg, Q); // int[const(int)*] Also, is this documented somewhere?