Re: rotate left an array

2022-10-03 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Oct 03, 2022 at 05:38:25PM -0700, Ali Çehreli via Digitalmars-d-learn wrote: [...] > Good catch but I think what we want is a copy of the front element, at > least for InputRanges (.save does not work for File.byLine :/). One of the things we need to settle in Phobos v2 is what to do

Re: rotate left an array

2022-10-03 Thread Paul Backus via Digitalmars-d-learn
On Tuesday, 4 October 2022 at 00:38:25 UTC, Ali Çehreli wrote: Good catch but I think what we want is a copy of the front element, at least for InputRanges (.save does not work for File.byLine :/). What is the generic way of copying an element? I wonder whether we have to use isSomeString to

Re: rotate left an array

2022-10-03 Thread rassoc via Digitalmars-d-learn
On 10/3/22 23:06, Ali Çehreli via Digitalmars-d-learn wrote: auto rotatedView(R)(R range) Or even more generic by chaining two slices in case the range permits it: auto rotatedView(R)(R range, long n = 1) if (...) { if (n == 0) return range; ... n %= range.length;

Re: rotate left an array

2022-10-03 Thread Ali Çehreli via Digitalmars-d-learn
On 10/3/22 17:00, Paul Backus wrote: > On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote: >> On 10/3/22 13:48, Andrey Zherikov wrote: >>> a "rotated view". >> >> Without indexes: >> >> import std.range : empty; >> >> auto rotatedView(R)(R range) >> in (!range.empty) >> { >> import

Re: rotate left an array

2022-10-03 Thread Paul Backus via Digitalmars-d-learn
On Monday, 3 October 2022 at 21:06:36 UTC, Ali Çehreli wrote: On 10/3/22 13:48, Andrey Zherikov wrote: a "rotated view". Without indexes: import std.range : empty; auto rotatedView(R)(R range) in (!range.empty) { import std.range : chain, front, only, popFront; const fr =

Re: rotate left an array

2022-10-03 Thread Ali Çehreli via Digitalmars-d-learn
On 10/3/22 13:48, Andrey Zherikov wrote: a "rotated view". Without indexes: import std.range : empty; auto rotatedView(R)(R range) in (!range.empty) { import std.range : chain, front, only, popFront; const fr = range.front; range.popFront(); return chain(range, only(fr)); }

Re: rotate left an array

2022-10-03 Thread Andrey Zherikov via Digitalmars-d-learn
On Monday, 3 October 2022 at 18:09:05 UTC, Fausto wrote: Hello all, I am trying to rotate left an array. I found a very basic way, and I am not sure if there is something clever than this :) maybe using slices... the external for represents how many times you are rotating (in this case 2).

Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-03 Thread mw via Digitalmars-d-learn
On Monday, 3 October 2022 at 18:02:51 UTC, Salih Dincer wrote: On Sunday, 2 October 2022 at 19:48:52 UTC, mw wrote: ``` text.csvReader!Layout(["b","c","a"]); // Read only these column ``` The intention is very clear: only read the selected columns from the csv, and for any other

Re: rotate left an array

2022-10-03 Thread Nick Treleaven via Digitalmars-d-learn
On Monday, 3 October 2022 at 18:09:05 UTC, Fausto wrote: Hello all, I am trying to rotate left an array. I found a very basic way, and I am not sure if there is something clever than this :) maybe using slices... Here we can't use slice assignment instead of the inner loop because that

rotate left an array

2022-10-03 Thread Fausto via Digitalmars-d-learn
Hello all, I am trying to rotate left an array. I found a very basic way, and I am not sure if there is something clever than this :) maybe using slices... the external for represents how many times you are rotating (in this case 2). ```d void main() { import std.range; import

Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-03 Thread Salih Dincer via Digitalmars-d-learn
On Sunday, 2 October 2022 at 19:48:52 UTC, mw wrote: ``` text.csvReader!Layout(["b","c","a"]); // Read only these column ``` The intention is very clear: only read the selected columns from the csv, and for any other fields of class Layout, just ignore (with the default D .init

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread Paul Backus via Digitalmars-d-learn
On Monday, 3 October 2022 at 14:37:35 UTC, kdevel wrote: On Sunday, 2 October 2022 at 23:37:26 UTC, ryuukk_ wrote: I got the answer thanks to IRC chat: https://dlang.org/spec/declaration.html#void_init Quote: Implementation Defined: If a void initialized variable's value is used

Re: Way to pass params to a function passed to a fiber?

2022-10-03 Thread Bienlein via Digitalmars-d-learn
On Monday, 3 October 2022 at 10:13:09 UTC, Rene Zwanenburg wrote: On Monday, 3 October 2022 at 08:10:43 UTC, Bienlein wrote: My question is whether someone has an idea for a better solution. You can pass a lambda to the fiber constructor. For example: ``` void fiberFunc(int i) {

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread kdevel via Digitalmars-d-learn
On Sunday, 2 October 2022 at 23:37:26 UTC, ryuukk_ wrote: I got the answer thanks to IRC chat: https://dlang.org/spec/declaration.html#void_init Quote: Implementation Defined: If a void initialized variable's value is used before it is set, its value is implementation defined.

Re: csvReader: how to read only selected columns while the class Layout has extra field?

2022-10-03 Thread jmh530 via Digitalmars-d-learn
On Sunday, 2 October 2022 at 21:18:43 UTC, mw wrote: [snipping] A CSV library should consider all the use cases, and allow users to ignore certain fields. In R, you have to force `NULL` for `colClasses` for the other columns. In other words, the user has to know the number of columns of

Re: Way to pass params to a function passed to a fiber?

2022-10-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Monday, 3 October 2022 at 08:10:43 UTC, Bienlein wrote: Hello, I'm looking for a way to pass parameters to a function called by a fiber. Starting a fiber works like this: You can also make a subclass of fiber that stores them with the object.

Re: Stop writeln from calling object destructor

2022-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/2/22 12:21 PM, data pulverizer wrote: I've noticed that `writeln` calls the destructor of a struct multiple times and would like to know how to stop this from happening. It has become a very serious problem when working with objects that have memory management external to D. I know you

Re: Way to pass params to a function passed to a fiber?

2022-10-03 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 3 October 2022 at 08:10:43 UTC, Bienlein wrote: In the code above there is no way to add parameters to myFunc. The construcor of class Fiber does not allow for a function to be passed that has parameters (unlike for the spawn function when starting a thread). You try

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread drug007 via Digitalmars-d-learn
On 10/3/22 09:35, tsbockman wrote: On Sunday, 2 October 2022 at 23:45:45 UTC, drug007 wrote: It works but not as someone could expect. In case of ```D Foo[2] arr = void; ``` `arr` value is not defined, it is not an initialized array of uninitialized elements like you want, it is just

Re: Way to pass params to a function passed to a fiber?

2022-10-03 Thread Rene Zwanenburg via Digitalmars-d-learn
On Monday, 3 October 2022 at 08:10:43 UTC, Bienlein wrote: My question is whether someone has an idea for a better solution. You can pass a lambda to the fiber constructor. For example: ``` void fiberFunc(int i) { writeln(i); } void main() { auto fiber = new Fiber(() =>

Way to pass params to a function passed to a fiber?

2022-10-03 Thread Bienlein via Digitalmars-d-learn
Hello, I'm looking for a way to pass parameters to a function called by a fiber. Starting a fiber works like this: int main() { auto fiber = new Fiber(); fiber.call(); fiber.call(); return 0; } void myFunc() { writeln("Fiber called"); Fiber.yield(); writeln("Fiber

Re: Visual D doesn't work, now Visual Studio Code / D doesn't work!!!! ....

2022-10-03 Thread Rainer Schuetze via Digitalmars-d-learn
On 02/10/2022 13:00, Daniel Donnell wrote: Visual D doesn't work - it just ate my app.obj file and can't find it anymore no matter if I clean or re-order the executable paths in settings. Can you be more specific what you are doing and what is going wrong? On 02/10/2022 23:28, rikki

Re: Convert array of simple structs, to C array of values

2022-10-03 Thread Dennis via Digitalmars-d-learn
On Monday, 3 October 2022 at 07:45:47 UTC, Chris Katko wrote: I know there's gotta be some simple one liner function in D, but I can't think of it. I don't know if you're looking for type safety, but you can just do `cast(float*) values.ptr;` or `cast(float[]) values[]`.

Convert array of simple structs, to C array of values

2022-10-03 Thread Chris Katko via Digitalmars-d-learn
```D struct pair { float x; float y; } pair[10] values; import std.conv; auto valuesInCStyle = to!(const float*)(values); ``` Now that's not going to work because (I would imagine) to! doesn't understand x, and y, can be placed in order to give an array of: valuesInCStyle =

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread tsbockman via Digitalmars-d-learn
On Sunday, 2 October 2022 at 23:30:16 UTC, ryuukk_ wrote: ```D MyStruct test = void; ``` Does this guarantee that the compiler will not initialize it? It's more of a request, than a guarantee. For example, `= void` may be ignored for the fields of `struct`s and `class`es: ```D struct ABC {

Re: Is `void` the correct way to say "do not initialize this variable"?

2022-10-03 Thread tsbockman via Digitalmars-d-learn
On Sunday, 2 October 2022 at 23:45:45 UTC, drug007 wrote: It works but not as someone could expect. In case of ```D Foo[2] arr = void; ``` `arr` value is not defined, it is not an initialized array of uninitialized elements like you want, it is just uninitialized array. This is incorrect. It