Re: Code Review

2017-12-09 Thread Venkat via Digitalmars-d-learn
On Sunday, 10 December 2017 at 07:03:30 UTC, Venkat wrote: Can anybody take a look at this checkin ? The import files are a noise, please ignore them and take a look at the *.d files. Changes I made. - Tried to remove __va_argsave as it doesn't compile with it. - Tried to replace no arg opCall(

Code Review

2017-12-09 Thread Venkat via Digitalmars-d-learn
Can anybody take a look at this checkin ? The import files are a noise, please ignore them and take a look at the *.d files. Changes I made. - Tried to remove __va_argsave as it doesn't compile with it. - Tried to replace no arg opCall() with a factory function. https://bitbucket.org/vra5107/dj

Re: Seed Value for reduce function

2017-12-09 Thread Ali Çehreli via Digitalmars-d-learn
On 12/09/2017 06:19 PM, Vino wrote:  Tried with fold even then it is failing same as reduce with the same error when there is empty folder auto SdFiles = Array!ulong(dirEntries(d, SpanMode.depth).map!(a => a.size).fold!((a,b) => a + b))[].filter!(a => a  > Size); When no seed value is spec

Re: Seed Value for reduce function

2017-12-09 Thread Vino via Digitalmars-d-learn
On Sunday, 10 December 2017 at 01:42:46 UTC, Jonathan M Davis wrote: On Sunday, December 10, 2017 00:39:07 Vino via Digitalmars-d-learn wrote: [...] So, basically, you're trying to use reduce with UFCS, and that doesn't work in the case where you want to provide an explicit seed value? In th

Re: Seed Value for reduce function

2017-12-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, December 10, 2017 00:39:07 Vino via Digitalmars-d-learn wrote: > Hi All, > >Request you help on how to add the seed value for the reduce > function, below is the scnerio > > Program 1 : Works > > import std.algorithm; > void main () { > int[] ara = [1,2 ,3]; > auto sum1 = ara.reduce!

Re: Question for compiler gurus about compile-time strings

2017-12-09 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, December 09, 2017 23:38:46 Stefan Koch via Digitalmars-d-learn wrote: > On Saturday, 9 December 2017 at 18:45:18 UTC, Steven > > Schveighoffer wrote: > > I was thinking that all strings generated at compile-time have > > a null-terminator added. But then I thought, wait, maybe that's

Re: Seed Value for reduce function

2017-12-09 Thread Vino via Digitalmars-d-learn
On Sunday, 10 December 2017 at 00:39:07 UTC, Vino wrote: Hi All, Request you help on how to add the seed value for the reduce function, below is the scnerio Program 1 : Works import std.algorithm; void main () { int[] ara = [1,2 ,3]; auto sum1 = ara.reduce!((a,b) => a + b); writeln(sum1);

Seed Value for reduce function

2017-12-09 Thread Vino via Digitalmars-d-learn
Hi All, Request you help on how to add the seed value for the reduce function, below is the scnerio Program 1 : Works import std.algorithm; void main () { int[] ara = [1,2 ,3]; auto sum1 = ara.reduce!((a,b) => a + b); writeln(sum1); } Program 2: Works void main () { int[] arrb = []; auto s

Re: Question for compiler gurus about compile-time strings

2017-12-09 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 9 December 2017 at 18:45:18 UTC, Steven Schveighoffer wrote: I was thinking that all strings generated at compile-time have a null-terminator added. But then I thought, wait, maybe that's only specifically for string literals. What is the true answer? If you generate a string, let

Re: Get pointer or reference of an element in Array(struct)

2017-12-09 Thread Azi Hassan via Digitalmars-d-learn
On Saturday, 9 December 2017 at 06:46:27 UTC, Arun Chandrasekaran wrote: On Saturday, 9 December 2017 at 06:38:46 UTC, anonymous wrote: On Saturday, 9 December 2017 at 06:15:16 UTC, Arun Chandrasekaran wrote: Is there a way to get the pointer or reference of an element in Array(T)? [...]

Re: Directory Size

2017-12-09 Thread Vino via Digitalmars-d-learn
On Friday, 8 December 2017 at 19:10:09 UTC, vino wrote: On Thursday, 7 December 2017 at 12:19:00 UTC, Vino wrote: On Thursday, 7 December 2017 at 09:04:19 UTC, Vino wrote: [...] Hi Andrea, Was able to find a solution to the above issue by adding the replace function as below, the the code

Re: Get pointer or reference of an element in Array(struct)

2017-12-09 Thread David Nadlinger via Digitalmars-d-learn
On Saturday, 9 December 2017 at 06:46:27 UTC, Arun Chandrasekaran wrote: Thanks. Just curious why reference can't be obtained here. Saves nasty null checks in most places. D simply doesn't have a (C++-style) concept of references as part of the type. Arguments can be passed by reference - henc

Question for compiler gurus about compile-time strings

2017-12-09 Thread Steven Schveighoffer via Digitalmars-d-learn
I was thinking that all strings generated at compile-time have a null-terminator added. But then I thought, wait, maybe that's only specifically for string literals. What is the true answer? If you generate a string, let's say via a CTFE call, does it have a null terminator? -Steve

Re: Check whether a file is empty.

2017-12-09 Thread FreeSlave via Digitalmars-d-learn
On Friday, 8 December 2017 at 19:13:20 UTC, vino wrote: Hi, The code is same just copy pasted the code form Windows 7 into Windows 2003 and executed, in Windows 7 the log file is of size 0 where as in windows 2003 the log file is of size 2 byte where the log file in both the server is empty

Re: Sort in return statement

2017-12-09 Thread codephantom via Digitalmars-d-learn
On Saturday, 9 December 2017 at 14:49:28 UTC, Seb wrote: randomSample doesn't sort its returned range Not by design, however, because it samples in the order that the elements appear, *if* those elements are already sorted (whether by design or explicately sorted), then the results of the r

Re: Sort in return statement

2017-12-09 Thread Seb via Digitalmars-d-learn
On Saturday, 9 December 2017 at 14:42:44 UTC, codephantom wrote: After lots of reading, and testing, I managed to get a simple, one liner ;-) (doesn't seem like .release is needed though.) FYI .release is only possible on a SortedRange and then yields the underlying range. randomSample doesn'

Re: Sort in return statement

2017-12-09 Thread codephantom via Digitalmars-d-learn
On Saturday, 9 December 2017 at 14:18:00 UTC, Seb wrote: Yeah, you are very welcome. It's a bit hidden in the docs: Yes. Thanks for that. After lots of reading, and testing, I managed to get a simple, one liner ;-) (doesn't seem like .release is needed though.) // --- auto draw8Nu

Re: Sort in return statement

2017-12-09 Thread Seb via Digitalmars-d-learn
On Saturday, 9 December 2017 at 14:05:36 UTC, rjframe wrote: On Sat, 09 Dec 2017 07:32:42 +, Seb wrote: Use .release to obtain the underlying array. No need to do another allocation! ``` numbers.take(8).sort.release; ``` I did not realize that was there; thanks. Yeah, you are very w

Re: Sort in return statement

2017-12-09 Thread rjframe via Digitalmars-d-learn
On Sat, 09 Dec 2017 07:32:42 +, Seb wrote: > > Use .release to obtain the underlying array. No need to do another > allocation! > > ``` > numbers.take(8).sort.release; > ``` I did not realize that was there; thanks.

Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Venkat via Digitalmars-d-learn
Thank you, core.runtime.Runtime.initialize() fixed the issue. I am now able to use to!string as well. I found your posts and Ali Çehreli's posts on this subject. I think I have some understanding now.

Re: Implicit nothrow with -betterC

2017-12-09 Thread Manuel Maier via Digitalmars-d-learn
Thanks Adam, that cleared it up for me.

Re: std.conv.to!string refuses to convert a char* to string.

2017-12-09 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 9 December 2017 at 06:14:36 UTC, Venkat wrote: Thanks for the quick response. std.string.fromStringz did the trick. I am not sure what was the deal with to!string. Be careful with fromStringz. It doesn't allocate a new string, so the returned string can easily become corrupted if