Re: About the in expression, Why can't use with array.

2019-10-25 Thread lili via Digitalmars-d-learn
On Friday, 25 October 2019 at 21:06:53 UTC, IGotD- wrote: On Friday, 25 October 2019 at 20:44:18 UTC, Dennis wrote: On Friday, 25 October 2019 at 19:49:05 UTC, Ali Çehreli wrote: I'm still not completely sold on the whole idea though because it's not a clear win. Do others see other

Re: File I/O performance pitfalls

2019-10-25 Thread 9898287 via Digitalmars-d-learn
On Saturday, 26 October 2019 at 02:42:04 UTC, rikki cattermole wrote: On 26/10/2019 2:27 PM, 9898287 wrote: [...] You probably want -O3 not -O5. [...] I assume what you intended is: writeln("Hello, ", i); Also for format functions in D you should prefer the templated variation as it

Re: File I/O performance pitfalls

2019-10-25 Thread rikki cattermole via Digitalmars-d-learn
On 26/10/2019 2:27 PM, 9898287 wrote: Hi I want to find out what's causing my file writes to be so slow. I'm setting up buffer and locking the file and writing them to the file. $ cat d.d && ldc2 -O5  d.d && time ./d >> /dev/null You probably want -O3 not -O5. void main() {     import

File I/O performance pitfalls

2019-10-25 Thread 9898287 via Digitalmars-d-learn
Hi I want to find out what's causing my file writes to be so slow. I'm setting up buffer and locking the file and writing them to the file. $ cat d.d && ldc2 -O5 d.d && time ./d >> /dev/null void main() { import std.stdio; stdout.setvbuf(4096); stdout.lock(); foreach(i; 0 ..

Re: About the in expression, Why can't use with array.

2019-10-25 Thread IGotD- via Digitalmars-d-learn
On Friday, 25 October 2019 at 20:44:18 UTC, Dennis wrote: On Friday, 25 October 2019 at 19:49:05 UTC, Ali Çehreli wrote: I'm still not completely sold on the whole idea though because it's not a clear win. Do others see other advantages in other places like templates? For example, could

Re: Good way let low-skill people edit CSV files with predefined row names?

2019-10-25 Thread Laeeth Isharc via Digitalmars-d-learn
On Thursday, 24 October 2019 at 17:41:21 UTC, Dukc wrote: On Thursday, 24 October 2019 at 16:50:17 UTC, Dukc wrote: Hmm, I need to check whether I can do that on LibreOffice Calc. Unfortunately, no. If there's a way to do that, it's not obvious. I should be able to make an easy-to-use

Re: Eliding of slice range checking

2019-10-25 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 25 October 2019 at 15:22:12 UTC, Ali Çehreli wrote: On 10/25/2019 05:37 AM, Stefan Koch wrote: just replace x = a[i] with x = a.ptr[i]; That's a neat trick! Ali But it requires the function to be qualified as @trusted which might hide a @system == operator. How common is it

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Dennis via Digitalmars-d-learn
On Friday, 25 October 2019 at 19:49:05 UTC, Ali Çehreli wrote: I'm still not completely sold on the whole idea though because it's not a clear win. Do others see other advantages in other places like templates? For example, could templates really be written generically for arrays and

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 02:25 AM, Dennis wrote: > On Friday, 25 October 2019 at 05:17:35 UTC, Ali Çehreli wrote: >> - Big O is different > > No it isn't. Agreed and I've just realized a benefit of the 'in' operator for arrays, which I haven't heard before. (I don't follow all discussions in detail.)

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 October 2019 at 16:01:57 UTC, mipri wrote: On Friday, 25 October 2019 at 15:52:50 UTC, Paul Backus wrote: On Friday, 25 October 2019 at 09:25:21 UTC, Dennis wrote: I can overload the 'in' operator on my types to something that takes exponential time if I want, just like "+" can

Re: Printing floating point numbers

2019-10-25 Thread berni44 via Digitalmars-d-learn
On Friday, 25 October 2019 at 14:51:33 UTC, Yui Hosaka wrote: The outputs for your program are as follows: [...] Thanks for the output. I added it to the bug report. The internal representation of the value is correct in all versions. While the result of the direct call of snprintf always

Re: About the in expression, Why can't use with array.

2019-10-25 Thread IGotD- via Digitalmars-d-learn
On Thursday, 24 October 2019 at 12:58:11 UTC, lili wrote: Hi: In Dlang where is strange design. The in expression can only use to associative array, why array can not use in expression. I don't see much of a problem why this couldn't be implemented as long as the user understands the

Re: About the in expression, Why can't use with array.

2019-10-25 Thread mipri via Digitalmars-d-learn
On Friday, 25 October 2019 at 15:52:50 UTC, Paul Backus wrote: On Friday, 25 October 2019 at 09:25:21 UTC, Dennis wrote: I can overload the 'in' operator on my types to something that takes exponential time if I want, just like "+" can also be overloaded to a linear time operation on e.g.

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Paul Backus via Digitalmars-d-learn
On Friday, 25 October 2019 at 09:25:21 UTC, Dennis wrote: I can overload the 'in' operator on my types to something that takes exponential time if I want, just like "+" can also be overloaded to a linear time operation on e.g. BigInt. Worth noting that `opIn` is a D1 operator overload, and

Re: Eliding of slice range checking

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 05:37 AM, Stefan Koch wrote: just replace x = a[i] with x = a.ptr[i]; That's a neat trick! Ali

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/2019 07:34 AM, Robert M. Münch wrote: > If the compiler is a 1-pass one I see the problem, otherwise one could > first get a "total overview" and create the necessary vtbl entries after > everything is known. Maybe this is not "how a compiler is implemented" > but the problem sounds

Re: Printing floating point numbers

2019-10-25 Thread Yui Hosaka via Digitalmars-d-learn
On Friday, 25 October 2019 at 06:53:38 UTC, berni44 wrote: On Thursday, 24 October 2019 at 20:48:02 UTC, Yui Hosaka wrote: Do you have any idea for this issue? I added a bug report: https://issues.dlang.org/show_bug.cgi?id=20320 Internally the conversation from the binary representation of

Re: ... use of ... is hidden by ...; use alias ... to introduce base class overload set ??

2019-10-25 Thread Robert M. Münch via Digitalmars-d-learn
On 2019-10-24 19:45:42 +, Ali ‡ehreli said: One practical reason is, the number of their instances cannot be known when the interface (or base class) is compiled. ... Ali, first, thanks a lot for your answers. If the compiler is a 1-pass one I see the problem, otherwise one could

Re: Eliding of slice range checking

2019-10-25 Thread welkam via Digitalmars-d-learn
On Thursday, 24 October 2019 at 21:02:03 UTC, Per Nordlöw wrote: On Thursday, 24 October 2019 at 18:37:05 UTC, welkam wrote: I remember in some video Chandler Carruth said that value range propagation across function boundary was implemented in llvm but later removed because it produced no

Re: Eliding of slice range checking

2019-10-25 Thread Stefan Koch via Digitalmars-d-learn
On Wednesday, 23 October 2019 at 12:01:47 UTC, Per Nordlöw wrote: On Wednesday, 23 October 2019 at 11:33:56 UTC, kinke wrote: For your example, the template is inferred to be @safe, and `-release` only elides bounds checks in @system functions (corresponding to `-boundscheck=safeonly`). Use

Re: Can not understand this code.

2019-10-25 Thread kinke via Digitalmars-d-learn
On Friday, 25 October 2019 at 06:40:19 UTC, lili wrote: why need defined a alias Min in Min template? https://dlang.org/spec/template.html#implicit_template_properties

Blog Post #82: Notebook, Part VI - Add and Remove Tabs

2019-10-25 Thread Ron Tarrant via Digitalmars-d-learn
More fun with Notebooks, adding and removing tabs willy-nilly: https://gtkdcoding.com/2019/10/25/0082-notebook-vi-add-remove-tabs.html

Re: About the in expression, Why can't use with array.

2019-10-25 Thread Dennis via Digitalmars-d-learn
On Friday, 25 October 2019 at 05:17:35 UTC, Ali Çehreli wrote: - Big O is different No it isn't. Worst case lookup of an associative array lookup is O(n) too. It can easily be 'achieved' by having a key type with: ``` size_t toHash() const scope pure { return 0; } ``` The fact that

Re: Can not understand this code.

2019-10-25 Thread berni44 via Digitalmars-d-learn
On Friday, 25 October 2019 at 06:40:19 UTC, lili wrote: Hi: What is the alias Min = xxx mean? why need defined a alias Min in Min template? ``` template Min(alias pred, Args...) if (Args.length > 0 && __traits(isTemplate, pred)) { static if (Args.length == 1) { alias Min =

Re: Array-only version of startsWith and skipOver

2019-10-25 Thread Per Nordlöw via Digitalmars-d-learn
On Friday, 25 October 2019 at 06:59:07 UTC, Per Nordlöw wrote: /** Array-overload for `skipOver` with no explicit predicate predicate. */ bool skipOver(T)(scope ref const(T)[] haystack, scope const(T)[] needle) Found it. The parameter `haystack` must be qualified with inout

Array-only version of startsWith and skipOver

2019-10-25 Thread Per Nordlöw via Digitalmars-d-learn
Why does /** Array-overload for `startsWith` with no explicit predicate predicate. */ bool startsWith(T)(scope const(T)[] haystack, scope const(T)[] needle) { if (haystack.length >= needle.length) { return haystack[0 .. needle.length] == needle; // range

Re: Printing floating point numbers

2019-10-25 Thread berni44 via Digitalmars-d-learn
On Thursday, 24 October 2019 at 20:48:02 UTC, Yui Hosaka wrote: Do you have any idea for this issue? I added a bug report: https://issues.dlang.org/show_bug.cgi?id=20320 Internally the conversation from the binary representation of the value to the printed one is done by a call to a C

Can not understand this code.

2019-10-25 Thread lili via Digitalmars-d-learn
Hi: What is the alias Min = xxx mean? why need defined a alias Min in Min template? ``` template Min(alias pred, Args...) if (Args.length > 0 && __traits(isTemplate, pred)) { static if (Args.length == 1) { alias Min = Alias!(Args[0]); } else static if (isLess!(pred,