Does Visual D actually work?
I downloaded it after experiencing debugging issues with CodeBlocks (it wouldn't attach the provided debugger). I downloaded Visual D and after some fiddling with Visual Studio 2019 not supporting third party templates in my version (had to update it), I haven't been able to get Visual D to compile anything. It looks like it doesn't know where phobos lives? I'm getting this: std.file.FileException@std\file.d(872) project directory>: The system cannot find the path specified. I've tried configuring both 'Additional Import Paths' and/or 'String Import Paths' under Compiler in properties and 'Library Search Path' in Linker (not sure why I would need this...but I was desperate). I keep getting a popup that says: 'The operation could not be completed. The parameter is incorrect'. It would help if there was a setup guide for this instead of assuming it all works. What IDE should I be using on Windows, because so far the ones I've tried are not even close to working out of the box (my bare minimum for 'working out of the box' would be to at least build and be able to reference the standard library). When dmd installed i put itself on my C:\ drive in a folder called 'D'. I've done zero custom here. I just let all of the installers do their thing. Advice?
Re: Does Visual D actually work?
A machine reboot seems to have fixed the problem...
Dynamic Arrays as Stack and/or Queue
I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this.
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. Also, these may be of interest: https://dlang.org/phobos/std_array.html https://dlang.org/phobos/std_range.html
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. if the top of the stack is the last element, --stack.length works as a simple pop.
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. Does slicing do what you need? x[1..$]
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:18:03 UTC, bachmeier wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. Does slicing do what you need? x[1..$] I have no clue. My problem is I need a stack and queue and I'm a little unsure the 'd' way to do it.
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. Built-in D arrays rely on garbage collector, and you don't need an explicit delete. For nogc arrays, there are 3rd party libs and std.container.array. take a look at https://dlang.org/phobos/std_container_array.html
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:24:19 UTC, Ferhat Kurtulmuş wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: I need a stack and a queue and I noticed that the standard library doesn't appear to have one. Which is ok. I just need something that can logically behave as a stack and queue, which I think the dynamic array should be able to do (if I understand correctly this is effectively the equivalent of vector in C++ or List in C#). However, I'm having a hard time figuring out the best way to push, pop, enqueue and dequeue using D. I'm not seeing here: https://dlang.org/spec/arrays.html, anyway to remove from the array. What's the correct syntax/method call for this? I see you can easily concatenate with '~', but I see no corresponding delete. Sorry for the newbie question, but I'm just unsure where to look for this. Built-in D arrays rely on garbage collector, and you don't need an explicit delete. For nogc arrays, there are 3rd party libs and std.container.array. take a look at https://dlang.org/phobos/std_container_array.html I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC.
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:28:11 UTC, Just Dave wrote: On Monday, 7 October 2019 at 17:24:19 UTC, Ferhat Kurtulmuş wrote: On Monday, 7 October 2019 at 17:11:08 UTC, Just Dave wrote: [...] Built-in D arrays rely on garbage collector, and you don't need an explicit delete. For nogc arrays, there are 3rd party libs and std.container.array. take a look at https://dlang.org/phobos/std_container_array.html I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC. I'm sorry. Writing on my mobile phone. Maybe this is what you are looking for https://dlang.org/phobos/std_container_dlist.html
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC. I'm sorry. Writing on my mobile phone. Maybe this is what you are looking for https://dlang.org/phobos/std_container_dlist.html I think what he is looking for are the general pop_front, push_front, pop_back and push_back that you would find in virtually any C++ STL container algorithms like list, vector or map. I think this is a good question as I don't really see any good example in the documentation of the dynamic arrays about this. This is very common use case for arrays. Is there any D equivalent?
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC. I'm sorry. Writing on my mobile phone. Maybe this is what you are looking for https://dlang.org/phobos/std_container_dlist.html I think what he is looking for are the general pop_front, push_front, pop_back and push_back that you would find in virtually any C++ STL container algorithms like list, vector or map. I think this is a good question as I don't really see any good example in the documentation of the dynamic arrays about this. This is very common use case for arrays. Is there any D equivalent? With the performance that you'd expect, I believe: #! /usr/bin/env rdmd import std.stdio; import std.algorithm : moveAll; void push_front(T)(ref T[] xs, T x) { ++xs.length; moveAll(xs[0 .. $-1], xs[1..$]); x[0] = x; } T pop_front(T)(ref T[] xs) { T x = xs[0]; moveAll(xs[1 .. $], xs[0 .. $-1]); --xs.length; return x; } void push_back(T)(ref T[] xs, T x) { xs ~= x; } T pop_back(T)(ref T[] xs) { T x = xs[$ - 1]; --xs.length; return x; } void main() { int[] xs; foreach (i; 0 .. 10) xs.push_back(i); writeln(xs.pop_back()); // output: 9 writeln(xs.pop_front()); // output: 0 writeln(xs.pop_front()); // output: 1 writeln(xs); // output: [2, 3, 4, 5, 6, 7, 8] }
Re: Dynamic Arrays as Stack and/or Queue
On Monday, 7 October 2019 at 19:38:50 UTC, mipri wrote: On Monday, 7 October 2019 at 19:16:31 UTC, IGotD- wrote: On Monday, 7 October 2019 at 17:36:09 UTC, Ferhat Kurtulmuş wrote: I'm not talking about memory deletion. I'm talking about push, pop, enqueue, and dequeue behavior. I'd assume in a garbage collected language letting the reference float off should be picked up by the GC. I'm sorry. Writing on my mobile phone. Maybe this is what you are looking for https://dlang.org/phobos/std_container_dlist.html I think what he is looking for are the general pop_front, push_front, pop_back and push_back that you would find in virtually any C++ STL container algorithms like list, vector or map. I think this is a good question as I don't really see any good example in the documentation of the dynamic arrays about this. This is very common use case for arrays. Is there any D equivalent? With the performance that you'd expect, I believe: #! /usr/bin/env rdmd [...] I assume this is a little bit more complicated: while popFront and popBack are ubiquitous in ranges in D, the push functions can't be unified in terms of memory management. For example, you cannot guarantee any performance, while using GC. This opposed to complexity, which is, of course, known. Maybe, this is the reason, why such containers are omitted in Phobos (?) But: There is a priority queue, named binaryheap: https://dlang.org/phobos/std_container_binaryheap.html and there are hints, that for a stack you have to rely e.g., on an array or a list implementation http://www.cplusplus.com/reference/stack/stack/ both exist in phobos: https://dlang.org/phobos/std_container_array.html https://dlang.org/phobos/std_container_dlist.html This gives rise to user implementations like https://code.dlang.org/packages/queue https://code.dlang.org/packages/mergearray etc. Maybe, there will be more soon? ;)
Re: Dynamic Arrays as Stack and/or Queue
On 10/07/2019 10:11 AM, Just Dave wrote: I need a stack and a queue There is a DoubleEndedQueue example under "Indexing Operators" here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.opIndexOpAssign It does not have the pop varieties but it should be trivial to add those because it internally uses two slices and the "head" of the whole container is the actual "end" of one of those slices. (The elementAt() member function takes care of reversed indexing for half of the elements.) I stole the idea of that example from Chuck Allison after one of his DConf presentations. Ali
Re: Does Visual D actually work?
On Monday, 7 October 2019 at 15:02:36 UTC, Just Dave wrote: I downloaded it after experiencing debugging issues with CodeBlocks (it wouldn't attach the provided debugger). I downloaded Visual D and after some fiddling with Visual Studio 2019 not supporting third party templates in my version (had to update it), I haven't been able to get Visual D to compile anything. It looks like it doesn't know where phobos lives? I'm getting this: std.file.FileException@std\file.d(872) project directory>: The system cannot find the path specified. I've tried configuring both 'Additional Import Paths' and/or 'String Import Paths' under Compiler in properties and 'Library Search Path' in Linker (not sure why I would need this...but I was desperate). I keep getting a popup that says: 'The operation could not be completed. The parameter is incorrect'. It would help if there was a setup guide for this instead of assuming it all works. What IDE should I be using on Windows, because so far the ones I've tried are not even close to working out of the box (my bare minimum for 'working out of the box' would be to at least build and be able to reference the standard library). When dmd installed i put itself on my C:\ drive in a folder called 'D'. I've done zero custom here. I just let all of the installers do their thing. Advice? Yes it works... You can have visual D install the compilers from the options(tools). So if it' snot finding anything it will(or should) using that method.