[OT] Re: howto count lines - fast

2017-06-01 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2017-05-31 at 16:37 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > […] > > An even more down-to-earth counterargument is that if CPU vendors had > been content with understandable, simple CPU implementations, and > eschewed "heroic", hard-to-understand things like instruction > pipelin

Re: howto count lines - fast

2017-06-01 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, May 31, 2017 22:50:19 H. S. Teoh via Digitalmars-d-learn wrote: > Perhaps the right approach is to check if the array length is less than > some arbitrary threshold, and just use a naïve loop below that, and only > switch to the complicated hackish stuff where you're sure it will > a

Re: howto count lines - fast

2017-06-01 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2017-05-31 at 16:37 -0700, H. S. Teoh via Digitalmars-d-learn wrote: > […] > With D, we can have the cake and eat it too.  The understandable / > naïve > implementation can be available as a fallback (and reference > implementation), with OS-specific optimized implementations guarded > und

Re: Rosetta Commatizing numbers

2017-06-01 Thread Solomon E via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 15:44:51 UTC, Ivan Kazmenko wrote: So, two custom calls, two minor changes, no sweat. Is everything right now? Even if not: that was fast, we can do another iteration. When we have a short readable solution with no special cases, the first few changes are

Re: Mixin in Inline Assembly

2017-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 23 May 2017 at 03:33:38 UTC, Era Scarecrow wrote: From what I'm seeing, it should be 8, 0ch, 10h, then 14h, all positive. I'm really scratching my head why I'm having this issue... What am i missing here? More experiments and i think it comes down to static arrays. The following

"Lazy" initialization of structs

2017-06-01 Thread Daniel Tan Fook Hao via Digitalmars-d-learn
Somehow this code works for me: ```D auto error (int status, string description){ struct Error { int status; string description; } Error err = { status, description }; return err.serializeToJson; } ``` which is supposed to be the same as ```D

Re: "Lazy" initialization of structs

2017-06-01 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: If I'm reading this right, in the former, the struct is created when the function is called in run-time, and the type is then inferred after that? I don't really understand the behavior behind this. The only difference betw

Re: "Lazy" initialization of structs

2017-06-01 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: Somehow this code works for me: ```D auto error (int status, string description){ struct Error { int status; string description; } Error err = { status, description }; return

Re: Rosetta Commatizing numbers

2017-06-01 Thread Ivan Kazmenko via Digitalmars-d-learn
On Thursday, 1 June 2017 at 08:45:23 UTC, Solomon E wrote: On Wednesday, 31 May 2017 at 15:44:51 UTC, Ivan Kazmenko wrote: So, two custom calls, two minor changes, no sweat. Is everything right now? Even if not: that was fast, we can do another iteration. When we have a short readable

Re: "Lazy" initialization of structs

2017-06-01 Thread Stanislav Blinov via Digitalmars-d-learn
On Thursday, 1 June 2017 at 12:04:05 UTC, Daniel Tan Fook Hao wrote: Somehow this code works for me: ```D auto error (int status, string description){ struct Error { int status; string description; } Error err = { status, description }; return

Re: Question on @nothrow

2017-06-01 Thread Vasileios Anagnostopoulos via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 17:20:08 UTC, Ali Çehreli wrote: On 05/31/2017 02:10 AM, Vasileios Anagnostopoulos wrote: > compiler enforced @throws For that to be possible, the compiler would have to see all definitions, which is not possible with separate compilation. Besides, I think the on

Re: Finding the index of the maximum value in an associative array

2017-06-01 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 30 May 2017 at 18:05:07 UTC, H. S. Teoh wrote: On Tue, May 30, 2017 at 05:57:04PM +, Lyle via Digitalmars-d-learn wrote: Hi, I have an associative array of type int[ulong] and I'm trying to get the index of the maximum value, like this: int[ulong] aa = [1UL: 2000,

Re: Question on @nothrow

2017-06-01 Thread Ali Çehreli via Digitalmars-d-learn
On 06/01/2017 06:26 AM, Vasileios Anagnostopoulos wrote: > how do I know that a function "may throw" an > exception in order to use a try/catch/finally block? This is my biggest > problem (sorry, coming from a java/C background). I come from a C++ background so the advices may be different from

Re: Question on @nothrow

2017-06-01 Thread Vasileios Anagnostopoulos via Digitalmars-d-learn
On Thursday, 1 June 2017 at 15:17:32 UTC, Ali Çehreli wrote: On 06/01/2017 06:26 AM, Vasileios Anagnostopoulos wrote: > how do I know that a function "may throw" an > exception in order to use a try/catch/finally block? This is my biggest > problem (sorry, coming from a java/C background). I co

Re: Question on @nothrow

2017-06-01 Thread Ali Çehreli via Digitalmars-d-learn
On 06/01/2017 08:41 AM, Vasileios Anagnostopoulos wrote: //If I do not know void haveToCommunicateWithAli() { sendEmailToAli(); } //can blow-up after code has shipped //and have no chance to recover What shall I do in this case? Thank you in advance. Vasileios (Sorry if I go to too basic

Re: Changing Template Static Ifs to Recursion

2017-06-01 Thread jmh530 via Digitalmars-d-learn
On Wednesday, 31 May 2017 at 21:02:07 UTC, jmh530 wrote: On Wednesday, 31 May 2017 at 19:22:18 UTC, Stefan Koch wrote: You could also use string mixins. Which will be more efficient then recursion. I try to avoid string mixins unless I can't help it. Nevertheless, I made an effort to try to

Re: howto count lines - fast

2017-06-01 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, May 31, 2017 at 12:13:04PM -0700, H. S. Teoh via Digitalmars-d-learn wrote: > On Tue, May 30, 2017 at 05:13:46PM -0700, Ali Çehreli via Digitalmars-d-learn > wrote: > [...] > > I could not make the D program come close to wc's performance when the > > data was piped from stdin. > [...] >

Creating and loading D plugins in D app

2017-06-01 Thread aberba via Digitalmars-d-learn
Want to create and load plugins written in D into a D app at run-time, the kind that can make api calls or extended main app with other functionality. I'm currently interested in it for a vibe.d app. How does these stuff work?

Re: Creating and loading D plugins in D app

2017-06-01 Thread Stefan Koch via Digitalmars-d-learn
On Thursday, 1 June 2017 at 23:24:13 UTC, aberba wrote: Want to create and load plugins written in D into a D app at run-time, the kind that can make api calls or extended main app with other functionality. I'm currently interested in it for a vibe.d app. How does these stuff work? It works

D scripting in D

2017-06-01 Thread Mike B Johnson via Digitalmars-d-learn
I wonder if it is possible to somehow turn D in to a scripting language that can be run inside D? The point? To have the same uniform syntax for quickly developing scripts that can then be easily transferred, if desired, in to a complete binary. e.g., suppose I am working in some type of ana

Re: D scripting in D

2017-06-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:06:27 UTC, Mike B Johnson wrote: I wonder if it is possible to somehow turn D in to a scripting language that can be run inside D? Why not just use regular compiled D?

Re: D scripting in D

2017-06-01 Thread Mike B Johnson via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:15:27 UTC, Adam D. Ruppe wrote: On Friday, 2 June 2017 at 02:06:27 UTC, Mike B Johnson wrote: I wonder if it is possible to somehow turn D in to a scripting language that can be run inside D? Why not just use regular compiled D? Because it requires one to recomp

Re: D scripting in D

2017-06-01 Thread Stefan Koch via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:32:43 UTC, Mike B Johnson wrote: 1. change test12.wav to test123.wav 2. save file 3. recompile. 4. run 5. Get back to same test point(could be a lot or a little amount of work). If that is all you want; then compile your code into a dll/so and load the new version

Re: D scripting in D

2017-06-01 Thread Mike B Johnson via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:39:47 UTC, Stefan Koch wrote: On Friday, 2 June 2017 at 02:32:43 UTC, Mike B Johnson wrote: 1. change test12.wav to test123.wav 2. save file 3. recompile. 4. run 5. Get back to same test point(could be a lot or a little amount of work). If that is all you want; th

Re: D scripting in D

2017-06-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 2 June 2017 at 02:32:43 UTC, Mike B Johnson wrote: But it would be nice if a D had a scripting language that used the same D syntax as this would make porting a piece of cake. So my script.d has kinda similar syntax, but fairly different semantics than good D code (though my jsvar.

Re: D scripting in D

2017-06-01 Thread Mike B Johnson via Digitalmars-d-learn
On Friday, 2 June 2017 at 03:33:37 UTC, Adam D. Ruppe wrote: On Friday, 2 June 2017 at 02:32:43 UTC, Mike B Johnson wrote: But it would be nice if a D had a scripting language that used the same D syntax as this would make porting a piece of cake. So my script.d has kinda similar syntax, but