Re: Idiomatic way of writing nested loops?

2017-07-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 17 July 2017 at 11:07:35 UTC, Anton Fediushin wrote: Hello! What is the best way of rewriting this code in idiomatic D manner? -- foreach(a; ["foo", "bar"]) { foreach(b; ["baz", "foz", "bof"]) { foreach(c; ["FOO", "BAR"]) { // Some operations on a, b and c } } }

Re: D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText()

2017-07-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 02:21:59 UTC, Enjoys Math wrote: DMD32 D Compiler v2.074.1 import std.file; void main() { string bigInput = readText("input.txt"); } The file is 7 MB of ascii text, don't know if that matters... Should I upgrade versions? I wonder if it thinks there is a BOM

D doesn't read the first character of a file (reads everything but the first chararacter) with either read() or readText()

2017-07-17 Thread Enjoys Math via Digitalmars-d-learn
DMD32 D Compiler v2.074.1 import std.file; void main() { string bigInput = readText("input.txt"); } The file is 7 MB of ascii text, don't know if that matters... Should I upgrade versions?

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 10:32:14PM +, Nordlöw via Digitalmars-d-learn wrote: > On Monday, 17 July 2017 at 20:01:41 UTC, H. S. Teoh wrote: [...] > > result[offset .. offset + a.length] = a[]; > > This slice assignment doesn't support conversion between different >

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 20:28:12 UTC, Nordlöw wrote: Made some adjustments with working unittest and put it up on https://github.com/nordlow/phobos-next/blob/master/src/algorithm_ex.d#L2467 Moved here https://github.com/nordlow/phobos-next/blob/master/src/array_ex.d#L2765

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 20:01:41 UTC, H. S. Teoh wrote: OK, here's an actual, compilable, runnable version: import std.algorithm : sum; import std.meta : allSatisfy, staticMap; import std.range : only; import std.traits : CommonType, isStaticArray;

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 20:53:36 UTC, H. S. Teoh wrote: See the working implementation in my latest post on this thread. That version supports CommonType, and works correctly with empty tuples as well. T Thanks.

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 08:28:12PM +, Nordlöw via Digitalmars-d-learn wrote: [...] > I had to special-case foreach body for `i == 0` since `sumOfLengths` > couldn't instantiate with empty tuple `()`. > > Further, should `concat` support `CommonType`? That is, should > > int[2] x = [1,

Profiling Windows App and DLL

2017-07-17 Thread Igor via Digitalmars-d-learn
Is there a known limitation in profiling these or am I doing something wrong? When I try to run my application from VisualD (x64 build) with -profile switch I just get Access Violation reported on WinMain function (actual declaration, it doesn't enter its body). If I build it with dub build

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 20:10:31 UTC, H. S. Teoh wrote: On Mon, Jul 17, 2017 at 08:11:03PM +, Nordlöw via Digitalmars-d-learn wrote: [...] Does this have a place in Phobos? Never know till you try. :-D If so, - under what name: append, concat or cat? I'd vote for concat. -

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 08:11:03PM +, Nordlöw via Digitalmars-d-learn wrote: [...] > Does this have a place in Phobos? Never know till you try. :-D > If so, > > - under what name: append, concat or cat? I'd vote for concat. > - where: std.algorithm or std.array? std.array, IMO, since

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 19:11:26 UTC, H. S. Teoh wrote: Hmm, since we already have sumOfLengths available at compile-time, what about: T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays arrays) if (allSatisfy!(isStaticArray, StaticArrays)) {

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
OK, here's an actual, compilable, runnable version: import std.algorithm : sum; import std.meta : allSatisfy, staticMap; import std.range : only; import std.traits : CommonType, isStaticArray; alias Elem(A : E[n], E, size_t n) = E; enum Length(A) =

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 18:54:31 UTC, Stefan Koch wrote: we have special code in the compiler to optimize a ~ b ~ c. Interesting, can you elaborate on what you mean with "optimize". In that case, is there a reason why int x[2]; int y[2]; int z[x.length + y.length] = x ~ y;

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 18:54:31 UTC, Stefan Koch wrote: So all you need to do make it so auto cat(T[]...)(T args) { T[] result; mixin(() { string mix = `result = `; foreach(i;args.length) { mix ~= `args[` ~ itos(i) ~ `] ~`; } mix[$-1] = ';';

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > template sumOfLengths(A...) > if (A.length > 0) > { > static if (A.length == 1) > enum sumOfLengths = A[0].length; > else >

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 12:01:48PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: [...] > T[sumOfLengths!StaticArrays] append(StaticArrays...)(StaticArrays > arrays) > if (/* insert static array constraints here */) > { > typeof(return) result = void; >

Re: Appending static arrays

2017-07-17 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Jul 17, 2017 at 05:38:23PM +, Nordlöw via Digitalmars-d-learn wrote: > I'm want to define a specialization of `append()` that takes only > static arrays as inputs and returns a static array being the sum of > the lengths of the inputs. > > Have anybody already implemented this? > >

Re: Appending static arrays

2017-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 07/17/2017 08:35 PM, Nordlöw wrote: Thanks, but I'm talking about the variadic case where the number of input arguments are unknown (>= 2) where the function header looks something like import std.traits : allSatisfy, isStaticArray; auto append(R, Args...)(auto ref Args args) if

Re: Appending static arrays

2017-07-17 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 17 July 2017 at 18:38:16 UTC, Nordlöw wrote: On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote: int[n + m] result = a ~ b; Further, the expression `a ~ b` here will allocate and create a copy on the GC-heap before writing `result`. Maybe LDC optimizes away this now or

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 17:38:23 UTC, Nordlöw wrote: I'm want to define a specialization of `append()` that takes only static arrays as inputs and returns a static array being the sum of the lengths of the inputs. Have anybody already implemented this? If not, I'm specifically interested

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote: int[n + m] result = a ~ b; Further, the expression `a ~ b` here will allocate and create a copy on the GC-heap before writing `result`. Maybe LDC optimizes away this now or in the future but DMD cannot. Yeah I know, kind of dumb

Re: Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
On Monday, 17 July 2017 at 17:46:42 UTC, ag0aep6g wrote: Like so? int[n + m] append(size_t n, size_t m)(int[n] a, int[m] b) { int[n + m] result = a ~ b; return result; } Thanks, but I'm talking about the variadic case where the number of input arguments are unknown (>= 2) where the

Re: Yesterday Visual D worked, today it does not!

2017-07-17 Thread Enjoys Math via Digitalmars-d-learn
On Monday, 17 July 2017 at 17:57:14 UTC, Enjoys Math wrote: I made a console app the other day and there were build options present. In the build options I had to specify the dmd2 executable directly. Then it worked (but that's another error). Today there are no build options! I tried

Yesterday Visual D worked, today it does not!

2017-07-17 Thread Enjoys Math via Digitalmars-d-learn
I made a console app the other day and there were build options present. In the build options I had to specify the dmd2 executable directly. Then it worked (but that's another error). Today there are no build options! I tried creating a regular console app and a GDC/DMD console app.

Re: Appending static arrays

2017-07-17 Thread ag0aep6g via Digitalmars-d-learn
On 07/17/2017 07:38 PM, Nordlöw wrote: I'm want to define a specialization of `append()` that takes only static arrays as inputs and returns a static array being the sum of the lengths of the inputs. Have anybody already implemented this? If not, I'm specifically interested in how to most

Appending static arrays

2017-07-17 Thread Nordlöw via Digitalmars-d-learn
I'm want to define a specialization of `append()` that takes only static arrays as inputs and returns a static array being the sum of the lengths of the inputs. Have anybody already implemented this? If not, I'm specifically interested in how to most conveniently infer the length (as an

Re: (char* str) is not callable using argument types (string)

2017-07-17 Thread rikki cattermole via Digitalmars-d-learn
On 17/07/2017 2:47 PM, Zaheer Ahmed wrote: I am Developing an Operating System in D Language and when want to Develop my writeln("Zaheer"); function, I pass String "Zaheer" and when receive, it says Error Error: function kernel.dwriteln (char* str) is not callable using argument types (string)

(char* str) is not callable using argument types (string)

2017-07-17 Thread Zaheer Ahmed via Digitalmars-d-learn
I am Developing an Operating System in D Language and when want to Develop my writeln("Zaheer"); function, I pass String "Zaheer" and when receive, it says Error Error: function kernel.dwriteln (char* str) is not callable using argument types (string) I Tried to cast but still stuck. In C and

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread kerdemdemir via Digitalmars-d-learn
As for the problem itself, it can be solved without finding connected components. I won't post the solution right away because it is potentially a spoiler. See http://codeforces.com/blog/entry/53268 for problem analysis (828B) and http://codeforces.com/contest/828/submission/28637184 for an

Re: Idiomatic way of writing nested loops?

2017-07-17 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Monday, 17 July 2017 at 11:55:47 UTC, Anton Fediushin wrote: Thank you! I knew it is in the library! So, `parallel` will work just fine with this function, isn't it? Yes

Re: Idiomatic way of writing nested loops?

2017-07-17 Thread Anton Fediushin via Digitalmars-d-learn
On Monday, 17 July 2017 at 11:32:45 UTC, Sebastiaan Koppe wrote: On Monday, 17 July 2017 at 11:07:35 UTC, Anton Fediushin wrote: Hello! What is the best way of rewriting this code in idiomatic D manner? https://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct Thank you! I knew

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Ivan Kazmenko via Digitalmars-d-learn
On Monday, 17 July 2017 at 07:14:26 UTC, Andrea Fontana wrote: Probably using ndslice library could help you! Unfortunately, that's not possible on most online contest platforms like Codeforces. For each programming language and compiler available, only the most basic package is usually

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Ivan Kazmenko via Digitalmars-d-learn
On Sunday, 16 July 2017 at 21:50:19 UTC, kerdemdemir wrote: Process(row-1,column-1, maxrow, maxcolumn); Process(row,column-1, maxrow, maxcolumn); Process(row+1,column-1, maxrow, maxcolumn);

Re: Idiomatic way of writing nested loops?

2017-07-17 Thread Sebastiaan Koppe via Digitalmars-d-learn
On Monday, 17 July 2017 at 11:07:35 UTC, Anton Fediushin wrote: Hello! What is the best way of rewriting this code in idiomatic D manner? https://dlang.org/phobos/std_algorithm_setops.html#.cartesianProduct

Idiomatic way of writing nested loops?

2017-07-17 Thread Anton Fediushin via Digitalmars-d-learn
Hello! What is the best way of rewriting this code in idiomatic D manner? -- foreach(a; ["foo", "bar"]) { foreach(b; ["baz", "foz", "bof"]) { foreach(c; ["FOO", "BAR"]) { // Some operations on a, b and c } } } -- Every array has at least 1 element, and adding/removing

How to debug in vscode with mago-mi?

2017-07-17 Thread Domain via Digitalmars-d-learn
Could anyone show me how to debug in vscode with mago-mi? I have installed vscode with Native Debug, SDLang. I have tried dlang-vscode and code-d. My tasks.json: { "version": "2.0.0", "command": "dub", "type": "shell", "presentation": { "echo": true, "reveal":

Re: Avoid if statements for checking neighboring indexes in a 2D array

2017-07-17 Thread Andrea Fontana via Digitalmars-d-learn
On Sunday, 16 July 2017 at 10:37:39 UTC, kerdemdemir wrote: My goal is to find connected components in a 2D array for example finding connected '*' chars below. You can also use a queue to avoid recursion that should improve performances and readibility. Probably using ndslice library

Re: How to initialize the Variant variable with the default value using TypeInfo?

2017-07-17 Thread Ali Çehreli via Digitalmars-d-learn
On 07/15/2017 09:27 AM, RedCAT wrote: > I have only TypeInfo taken dynamically from an arbitrary type, and I > need to initialize the Variant variable to the default value for this > type. I'm afraid there is no way of setting the value of Variant dynamically because it wants to do