Re: Question about calling D method from C/C++

2013-06-03 Thread Jacob Carlborg
On 2013-06-03 06:32, Eric wrote: If I use new inside a D method that is called from a c++ program it causes a segmentation fault. For example: C++ code: #include dcode.h int main(int argc, char *argv[]) { hello(); return(0); } D code: class X { private int x; this() { x

Re: Exception isn't thrown as expected

2013-06-03 Thread Alexandr Druzhinin
03.06.2013 12:26, Ali Çehreli пишет: On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote: I found that after calling std.concurrency.spawn() template - exceptions stop throwing, but if I add little delay in beginning of spawned thread about 100 ms - it'd works again and exceptions would be

Re: Exception isn't thrown as expected

2013-06-03 Thread Jonathan M Davis
On Monday, June 03, 2013 14:30:48 Alexandr Druzhinin wrote: 03.06.2013 12:26, Ali Çehreli пишет: On 06/02/2013 08:23 PM, Alexandr Druzhinin wrote: I found that after calling std.concurrency.spawn() template - exceptions stop throwing, but if I add little delay in beginning of

randomShuffle

2013-06-03 Thread Yann
Hey, I am trying to generate an array of 10 unique (!) random numbers from 1 to 1000 each (for example). The best I could come up with is: auto arr = iota(1, 1000).array; randomShuffle(arr); return arr.take(10).array.sort; This leaves me quite unhappy, because I would like the code a) to be

Re: and/or/not/xor operators

2013-06-03 Thread Regan Heath
On Fri, 31 May 2013 21:26:56 +0100, ixid nuacco...@gmail.com wrote: We really don't want D to become a TMTOWTDI language. Ideally there should be 1 right way and no alternatives. That way, anyone who knows D will have a greater chance of knowing what any given code sample does, and not

Re: randomShuffle

2013-06-03 Thread maarten van damme
How about using std.random.randomSample? 2013/6/3 Yann skratc...@gmx.de Hey, I am trying to generate an array of 10 unique (!) random numbers from 1 to 1000 each (for example). The best I could come up with is: auto arr = iota(1, 1000).array; randomShuffle(arr); return

Re: how to use shared keyword in 2.063 version?

2013-06-03 Thread Andrey
On Saturday, 1 June 2013 at 16:00:58 UTC, Jonathan M Davis wrote: On Saturday, June 01, 2013 10:03:28 Andrey wrote: On Saturday, 1 June 2013 at 00:58:00 UTC, Jonathan M Davis wrote: On Friday, May 31, 2013 23:26:19 Anthony Goins wrote: To create a shared object you need shared this ctor.

Re: Structs should not contain pointers to internal data

2013-06-03 Thread Saurabh Das
Thank you @Ali and @Jonothan! So essentially since I will be storing a pointer, Telemetry!(T) is NOT safe to use only with structs in general. If I have something like: struct UsefulStruct2 { this(this) @disable; this(UsefulStruct2) @disable; this(ref const(UsefulStruct2)) @disable;

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 10:48 AM, Yann wrote: I am trying to generate an array of 10 unique (!) random numbers from 1 to 1000 each (for example). The best I could come up with is: You mean you want a random sample of the numbers 1, 2, ..., 1000? That is, you want to pick 10 unique numbers from 1, ...,

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 01:29 PM, Diggory wrote: For small samples from very large ranges an efficient algorithm would be: int[] randomGen(int N, int M) { if (N == 0) return []; int[] result = randomGen(N-1, M-1); int num = rand(M); foreach (ref int i; result)

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 02:30 PM, Joseph Rushton Wakeling wrote: On 06/03/2013 01:29 PM, Diggory wrote: For small samples from very large ranges an efficient algorithm would be: int[] randomGen(int N, int M) { if (N == 0) return []; int[] result = randomGen(N-1, M-1); int num =

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 02:30 PM, Joseph Rushton Wakeling wrote: On 06/03/2013 01:29 PM, Diggory wrote: For small samples from very large ranges an efficient algorithm would be: int[] randomGen(int N, int M) { if (N == 0) return []; int[] result = randomGen(N-1, M-1); int num =

Re: Using custom CCS styles with ddoc

2013-06-03 Thread Gary Willoughby
On Monday, 3 June 2013 at 14:55:03 UTC, Gary Willoughby wrote: When creating documentation using ddoc there is no CSS file specified in the head of the generated HTML file. How can i tell ddoc to generate documentation and use a custom CSS file for the styles? Just found the answer here:

Re: Question about calling D method from C/C++

2013-06-03 Thread Eric
This will crash when the line X x = new X() is executed. Is this to be expected? It seems you haven't started the runtime. Use this function: https://github.com/D-Programming-Language/druntime/blob/master/src/rt/dmain2.d#L281 Thanks. That fixed my problem. This is my first D program, so

Re: Structs should not contain pointers to internal data

2013-06-03 Thread Ali Çehreli
On 06/03/2013 05:26 AM, Saurabh Das wrote: Thank you @Ali and @Jonothan! So essentially since I will be storing a pointer, Telemetry!(T) is NOT safe to use only with structs in general. If I have something like: struct UsefulStruct2 { this(this) @disable;

Re: Writing closed source programs in D?

2013-06-03 Thread Jesse Phillips
On Friday, 31 May 2013 at 15:35:54 UTC, Jonathan M Davis wrote: The only problem with auto is that the type can't be inferred without the function body. But all of the information is there. So, all you have to do is make it so that the function doesn't return auto (or so that the variable

Re: UFCS for classes with opCall( ... )

2013-06-03 Thread ParticlePeter
UFCS is working with opCall already. The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.) What do you mean with locally import symbols, isn't that the normal import statement ? Could you

Re: Exception isn't thrown as expected

2013-06-03 Thread Ali Çehreli
On 06/03/2013 12:30 AM, Alexandr Druzhinin wrote: if child thread throws an exception, should it print some diagnostic message to clear that it crashed or no? No, the parent does not know about such a termination. These are the following options that I know of: 1) The exceptions can be

Re: randomShuffle

2013-06-03 Thread Diggory
On Monday, 3 June 2013 at 13:18:30 UTC, Joseph Rushton Wakeling wrote: On 06/03/2013 02:30 PM, Joseph Rushton Wakeling wrote: On 06/03/2013 01:29 PM, Diggory wrote: For small samples from very large ranges an efficient algorithm would be: int[] randomGen(int N, int M) { if (N == 0)

Re: Question about calling D method from C/C++

2013-06-03 Thread Jacob Carlborg
On 2013-06-03 17:42, Eric wrote: Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own... If it's not obvious, you should terminate the runtime as well when your program ends. There's a corresponding function for that. -- /Jacob Carlborg

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 07:00 PM, Diggory wrote: Thanks for testing before dismissing completely :P The way it returns results can be improved a lot by pre-allocating a range of the necessary size/using a range passed in. Surely. :-) The complexity is O(N²) where N is the number of samples out of M.

Re: randomShuffle

2013-06-03 Thread Diggory
On Monday, 3 June 2013 at 17:35:22 UTC, Joseph Rushton Wakeling wrote: On 06/03/2013 07:00 PM, Diggory wrote: Thanks for testing before dismissing completely :P The way it returns results can be improved a lot by pre-allocating a range of the necessary size/using a range passed in. Surely.

Re: Writing closed source programs in D?

2013-06-03 Thread Maxim Fomin
On Friday, 31 May 2013 at 15:35:54 UTC, Jonathan M Davis wrote: The situation with templates is basically the same as it is with C++. They have to go in the interface/header file and always will. There's no way around that, because the code importing the header/interface file actually needs

Re: UFCS for classes with opCall( ... )

2013-06-03 Thread Timon Gehr
On 06/03/2013 06:25 PM, ParticlePeter wrote: UFCS is working with opCall already. The reason your code does not work is that UFCS only works with module-level symbols (and with the latest release also for locally imported symbols IIRC.) What do you mean with locally import symbols, isn't

Re: Question about calling D method from C/C++

2013-06-03 Thread Eric
On Monday, 3 June 2013 at 17:20:22 UTC, Jacob Carlborg wrote: On 2013-06-03 17:42, Eric wrote: Thanks. That fixed my problem. This is my first D program, so I wouldn't have figured it out on my own... If it's not obvious, you should terminate the runtime as well when your program ends.

Re: randomShuffle

2013-06-03 Thread Joseph Rushton Wakeling
On 06/03/2013 08:28 PM, Diggory wrote: I'd guess that the heavy use of floating point arithmetic to calculate the step sizes means that algorithm has a fairly large constant overhead even though the complexity is smaller. Yes, I agree. There might be some optimizations that could be done

Nested class defined in another file

2013-06-03 Thread Bruno Deligny
Hi, I want to separate nested classes in multiple files to increase readability but i need to keep the access to parent members. Is it possible? Thx

Re: Nested class defined in another file

2013-06-03 Thread bearophile
Bruno Deligny: I want to separate nested classes in multiple files to increase readability but i need to keep the access to parent members. Is it possible? This is a solution, but it's not nice: mixin(import(filename1)); mixin(import(filename2)); ... Why do you need so much/so many nested

version(noboundscheck) + friends

2013-06-03 Thread Timothee Cour
A) How to query for compiler flags, eg whether or not noboundscheck was set? B) Why aren't we using version=noboundscheck (+ friends) instead of -noboundscheck? C) similar to version(assert) which IIRC was introduced later, could we introduce version(noboundscheck) (+ friends) ?

Re: version(noboundscheck) + friends

2013-06-03 Thread Ali Çehreli
On 06/03/2013 03:11 PM, Timothee Cour wrote: A) How to query for compiler flags, eg whether or not noboundscheck was set? version D_NoBoundsChecks: http://dlang.org/version.html B) Why aren't we using version=noboundscheck (+ friends) instead of -noboundscheck? Because the runtime

Re: Nested class defined in another file

2013-06-03 Thread Bruno Deligny
On Monday, 3 June 2013 at 22:07:15 UTC, bearophile wrote: Bruno Deligny: I want to separate nested classes in multiple files to increase readability but i need to keep the access to parent members. Is it possible? This is a solution, but it's not nice: mixin(import(filename1));

Re: Nested class defined in another file

2013-06-03 Thread Ali Çehreli
On 06/03/2013 03:20 PM, Bruno Deligny wrote: I began to separate them by hand by passing a parent reference but it's ugly because i need to make the parent members accessible in public to have acces. Is there any friend like in C++ to keep them private to others? Have you considered the

Re: Nested class defined in another file

2013-06-03 Thread bearophile
Bruno Deligny: Is there any friend like in C++ to keep them private to others? In D there is no C++ friend nor classes split as in C#. D Classes are supposed to be written in a single file. I have shown you a rough solution with import. Maybe others will give you more suggestions. Bye,

Re: version(noboundscheck) + friends

2013-06-03 Thread Timothee Cour
Thanks, D_NoBoundsChecks indeed works. On Mon, Jun 3, 2013 at 3:19 PM, Ali Çehreli acehr...@yahoo.com wrote: On 06/03/2013 03:11 PM, Timothee Cour wrote: A) How to query for compiler flags, eg whether or not noboundscheck was set? version D_NoBoundsChecks:

Re: version(noboundscheck) + friends

2013-06-03 Thread Jonathan M Davis
On Monday, June 03, 2013 15:19:22 Ali Çehreli wrote: B) Why aren't we using version=noboundscheck (+ friends) instead of -noboundscheck? Because the runtime is not written in D. :) However, it should be easy to translate version=noboundscheck to -noboundscheck. The runtime _is_

Re: version(noboundscheck) + friends

2013-06-03 Thread Timothee Cour
Again, this seems like an unimportant technicality. For user code, whether the logic is handled in the compiler or druntime shouldn't make a difference, so why not have version(D_NoBoundsChecks) instead of version(noboundscheck). It makes it more discoverable, and more consistent with the rest

Re: version(noboundscheck) + friends

2013-06-03 Thread Timothee Cour
I meant 'why not have version(noboundscheck) instead of version(D_NoBoundsChecks)' of course. On Mon, Jun 3, 2013 at 4:48 PM, Timothee Cour thelastmamm...@gmail.comwrote: Again, this seems like an unimportant technicality. For user code, whether the logic is handled in the compiler or druntime

Re: version(noboundscheck) + friends

2013-06-03 Thread Jonathan M Davis
On Monday, June 03, 2013 16:49:29 Timothee Cour wrote: I meant 'why not have version(noboundscheck) instead of version(D_NoBoundsChecks)' of course. So, you're complaining about the name of the version identifier? I thought that you were complaining that we were using a flag instead a version

Re: version(noboundscheck) + friends

2013-06-03 Thread Timothee Cour
A) whether the logic is done in compiler or druntime shouldn't matter to user, so it'd be nice to use as uniform syntax as possible, ie: dmd -version=noboundscheck should be supported (in addition to existing -noboundscheck) Implementation can then use that version flag to set compiler flag

Re: version(noboundscheck) + friends

2013-06-03 Thread Jonathan M Davis
On Monday, June 03, 2013 18:57:07 Timothee Cour wrote: A) whether the logic is done in compiler or druntime shouldn't matter to user, so it'd be nice to use as uniform syntax as possible, ie: dmd -version=noboundscheck should be supported (in addition to existing -noboundscheck)

Re: version(noboundscheck) + friends

2013-06-03 Thread Ivan Kazmenko
By the way, what is the naming convention of predefined versions? I am having a hard time trying to figure it out by myself from the docs (http://dlang.org/version.html#PredefinedVersions). To me, it would make sense if all predefined versions started with D_ or something similar to avoid

Re: version(noboundscheck) + friends

2013-06-03 Thread Jonathan M Davis
On Tuesday, June 04, 2013 05:17:08 Ivan Kazmenko wrote: By the way, what is the naming convention of predefined versions? I am having a hard time trying to figure it out by myself from the docs (http://dlang.org/version.html#PredefinedVersions). To me, it would make sense if all predefined